I have a column in my TAFFY DB that has a bunch of string date values
such as "2008-07-01", "2008-08-01", etc. Using the orderBy, those
values sort fine. The problem I see is that I also have null values
in that column, which don't seem to do any kind of sort. Preferably I
would like these sort at the top for "asc" and bottom for "desc".
Think this is possible?
Matt,
Yes, first is the preferred method for accessing one record. On paper
it will be a little slower than array[arrayIndex] since it is designed
to take an object for a search, an array of many indexes, or a single
index. But you'd need to run it many thousands of times before you
noticed. get()[arrayIndex] is going to be slower because it builds a
new array with all the record objects to return. For the most part
get() is best used when building a new TAFFY collection off of an
existing collection.
Ian
--- In taffydb@yahoogroups.com, "berg.matt" <berg.matt@...> wrote:
>
> Thanks Marty and Ian for your help. I think including the index in
> the forEach is exactly what I was looking for, but if I am looping
> through the whole collection, keeping track of the index isn't too big
> of a deal for now.
>
> Ian, I know you showed the use of myCollection.first(index). Is this
> the fastest way to retrieve a row (basically the same as
> array[arrayIndex])?
>
> Matt
>
> --- In taffydb@yahoogroups.com, "madcitymm" <marty@> wrote:
> >
> > Hi Ian,
> > Returning the index in the foreach will be a great addition. In my
> > application the foreach is always traversing a subset of the db and
> > having the index would be handy.
> > Marty
> >
>
Thanks Marty and Ian for your help. I think including the index in
the forEach is exactly what I was looking for, but if I am looping
through the whole collection, keeping track of the index isn't too big
of a deal for now.
Ian, I know you showed the use of myCollection.first(index). Is this
the fastest way to retrieve a row (basically the same as
array[arrayIndex])?
Matt
--- In taffydb@yahoogroups.com, "madcitymm" <marty@...> wrote:
>
> Hi Ian,
> Returning the index in the foreach will be a great addition. In my
> application the foreach is always traversing a subset of the db and
> having the index would be handy.
> Marty
>
Hi Ian,
Returning the index in the foreach will be a great addition. In my
application the foreach is always traversing a subset of the db and
having the index would be handy.
Marty
Hey Matt,
Marty may have already answered your question but I thought I'd throw
in my two cents. With the next version of Taffy I'm adding in some
better support for indexes. This includes a change to forEach where
two arguments will be passed in to your function: record,index. In
this way you'll be able to use forEach and easily keep track of the
index number. The next version shouldn't be too far out (working
through bugs now) but right now you have to hack it.
Assume the document contains <ul id="mylist"></ul>
Here is an option:
var x = 0;
var ml = document.getElementById("mylist");
myCollection.forEach(function(r){
var row = document.createElement("li");
row.appendChild(document.createTextNode(r.name));
row.index = x;
row.onclick = function(){
alert(myCollection.first(this.index).name)
};
ml.appendChild(row);
x++;
});
Hope that helps,
Ian
--- In taffydb@yahoogroups.com, "berg.matt" <berg.matt@...> wrote:
>
> I have been curious about what you recommend as far as using Taffy
> when it relates to Row/Index ids.
>
> Here is example of what I would like to do.
>
> Output all of my Taffy Data into row(li) elements, keeping track of
> the Taffy array index on each row. And then access each Taffy row by
> using the array index.
>
> How do I access the Taffy array index. And what is the best method of
> retrieving the Taffy row using the index?
>
> Thanks.
>
> Matt
>
Hi Matt,
I faced the same issue. With a bit of help from Ian, here's what
worked for me: I'll have my taffy driven site up in the next couple
of days and will post the link so others can see it in action. My
driving force was to make a cascaded vehicle search work without
going back to the server.
function js_Test()
{ var trows = new TAFFY([
{ make:"Ford",
model:"Escort",
color:"Silver"},
{ make:"Hyundai",
model:"Sonata",
color:"Red"}
]);
var trowidx; // list of indexes of objects in trows
var qry={};
qry["make"]={notequal:""}; // retrieve all records because make is
never empty
// use find to retreive all elements
trowidx = trows.find(qry);
// list the indexes
for (var i = 0; i < trowidx.length; i++)
{ alert("trow index = " + trowidx[i]);}
// if you also need to extract other information than the index
while populating
// the li then use the foreach. The trowidx at the end of the
function is used
// when find returns a subset of trows.
var veh;
var models="";
trows.forEach
( function (Lst)
{ models += Lst.model + " ";
}
,trowidx
);
alert("all models are: " + models);
// use this to retreive a single element from the taffy object with
// the index
var indx = 1; //the index to the taffy object
veh = trows.get()[indx];
var themakeis = veh.make; //Hyundai
var thecoloris = veh.color; //Red
alert("make and color are:" + themakeis + ", " + thecoloris);
}
I have been curious about what you recommend as far as using Taffy
when it relates to Row/Index ids.
Here is example of what I would like to do.
Output all of my Taffy Data into row(li) elements, keeping track of
the Taffy array index on each row. And then access each Taffy row by
using the array index.
How do I access the Taffy array index. And what is the best method of
retrieving the Taffy row using the index?
Thanks.
Matt
I would also vote for NO on indexes. I think keeping it lightweight
is one of the real nice features of Taffy. Though you could possibly
add extensions to TaffyDb, for users who need the extra processing.
--- In taffydb@yahoogroups.com, "madcitymm" <marty@...> wrote:
>
> --- In taffydb@yahoogroups.com, "tacoman_cool" <ian@> wrote:
> >
> > Hi everyone,
> >
> > I've spent some time over the last couple of weeks trying to test and
> > add indexes into Taffy DB. ...........
>
> Hi Ian,
> I'm new to Taffy, but what attracted me to it was that is a small but
> powerful application and it is not intended to be a real SQL type
> replacement, but for use in web pages, which by definition(at least
> mine) should be keep small. So, my vote on indexes is no.
> Thanks
> Marty
>
Hey Marty,
You've got a couple of options. By passing in an array to forEach it
will call your function for each entry in that array. You can also
pass in an object which will be handled the same way find is handled.
So collection.forEach(someFunc,collection.find({name:"Ian"}));
is the same as collection.forEach(someFunc,{name:"Ian"});
But I don't think that is what you are asking. I think you may be
looking for get(). Or perhaps first.
So collection.get({name:"Ian"}) will return an array that contains
every record (object) where name is Ian. You can use this to create
another taffy or loop over how ever you want. Are you certain that
only one record will be matched? first() and last() return just the
object instead of the array.
So alert(collection.get()[0].name) is the same as
alert(collection.first());
Does that help?
Ian
--- In taffydb@yahoogroups.com, "madcitymm" <marty@...> wrote:
>
> After executing a find, I have my list of indexes. How do I use those
> indexes to extract the contents? Seems silly, but there is only one
> example, the foreach, that does this, but then I have to scan the
> entire record set looking for the indexes.
> TIA
> Marty
>
After executing a find, I have my list of indexes. How do I use those
indexes to extract the contents? Seems silly, but there is only one
example, the foreach, that does this, but then I have to scan the
entire record set looking for the indexes.
TIA
Marty
--- In taffydb@yahoogroups.com, "tacoman_cool" <ian@...> wrote:
>
> Hi everyone,
>
> I've spent some time over the last couple of weeks trying to test and
> add indexes into Taffy DB. ...........
Hi Ian,
I'm new to Taffy, but what attracted me to it was that is a small but
powerful application and it is not intended to be a real SQL type
replacement, but for use in web pages, which by definition(at least
mine) should be keep small. So, my vote on indexes is no.
Thanks
Marty
Hi everyone,
I've spent some time over the last couple of weeks trying to test and
add indexes into Taffy DB. JavaScript is not designed for this type of
optimization so it has required a lot of brute force experimentation.
The results have been mixed.
Under a normal TaffyDB database it takes about 1500 milliseconds to
load 10,000 records via JavaScript. With a unique ID column it takes
around 200 milliseconds to retrieve a single record with a known ID.
If you add an index you can find that single record in 8-20
milliseconds. That is a huge improvement.
The index works by creating blocks of records and assembling meta data
about the column you want to search on. It knows the highest and
lowest value within that block of records (256 by default) and so it
can check each block to see if the record you are searching for may be
contained within it. So instead of looking at 10,000 records Taffy DB
only has to look at 256 to find the record in question.
So what's the problem?
The problem is speed of creation and maintenance of the index over
time. Creating the index takes about a 1000 milliseconds on 10,000
records. Given the improved speed of record lookup it is easy to
recoup that speed in a faster application.
Inserts also take virtually no time to handle.
Updates? Well they aren't bad but it will double or triple the amount
of time it will take to run updates.
Removes? Horrible. Because the block records have to change it is more
or less faster to rebuild the index from scratch than update it. Which
means removing a single record could take a second.
OrderBy? Also requires a complete rebuild of the index.
So the basic question I have, is this worth the file size? If you only
have 1000 records in your database the index really what improve your
speed noticeably. If you had one or two very large collections that
you do ID style lookups on then I think we could see an improvement.
But that isn't a typically use case of Taffy DB.
Thoughts? How would you want to use indexes? I hate to roll back all
the work but after a lot of testing it becomes virtually impossible to
maintain the index on a often updated collection, at which point it is
faster to just do full table scans.
Ian
Hi kioopi,
You're write. There isn't a way to do that currently. I've been
thinking along those lines though and came up with the idea of some
kind of "has" syntax.
It would work something like this:
// See if there is a city variable
collection.find(address:{has:"city"});
// Match on the city variable
collection.find(address:{has:{"city":"paris"}});
One issue with this solution is that you can still only go one level
lower. However Taffy DB isn't really designed as a way to query object
data as it is a way to query tabular data.
Any thoughts on this?
For right now about the only way you could do this would be to use
forEach and create a custom function. I didn't test this could but it
should work:
// add custom findByCity function
people.findByCity = function (SearchCity)
{
var cityMatches = [];
// Lookup based on argument city and march cityFound column
people.forEach(function(r) {
if (r.address.city == SearchCity) {
r.cityFound = true;
} else {
r.cityFound = false;
}
return r;
});
// search on city found column
cityMatches = people.find({cityFound:true});
// reset cityFound column
people.update({cityFound:false});
// return city found
return cityMatches;
};
// do a lookup using find and new function
people.find({somedata:"10"},people.findByCity("Paris"));
Ian
--- In taffydb@yahoogroups.com, kioopi <no_reply@...> wrote:
>
> Hi All,
>
> TaffyDB is amazing, but i have a problem that seems not to be possible
> in Taffy. I would like to do "relational"-queries on subobjects. An
> example:
>
> i have Objects with subobjects encaosulating adresses like this in a
> TaffyDB:
>
> {
> somedata : '123456',
> adress : {
> city : 'paris',
> zipcode : '15'
> }
> }
>
> now i would like to get objects based on values of the adress-objects.
>
> var results = taffydb.get( {somdata:{start:'12'},
> adress:{city:'paris',zipcode:'15'}});
>
> returns the entry, but when i change the values of adress in the query,
> for example removing the city or even trying to select several zipcodes,
> like this { adress: {zipcode : [13,14,15]}} i get no results at all.
>
> I guess this is because only object-equality is checked and the
> sub-object in the query is not recursivley parsed by Taffy.
>
> Any ideas about this? Is this somehow possible with taffy?
>
> Thanks in advance for your time.
>
> Cheers
> kioopi
>
Hi All,
TaffyDB is amazing, but i have a problem that seems not to be possible
in Taffy. I would like to do "relational"-queries on subobjects. An
example:
i have Objects with subobjects encaosulating adresses like this in a
TaffyDB:
{
somedata : '123456',
adress : {
city : 'paris',
zipcode : '15'
}
}
now i would like to get objects based on values of the adress-objects.
var results = taffydb.get( {somdata:{start:'12'},
adress:{city:'paris',zipcode:'15'}});
returns the entry, but when i change the values of adress in the query,
for example removing the city or even trying to select several zipcodes,
like this { adress: {zipcode : [13,14,15]}} i get no results at all.
I guess this is because only object-equality is checked and the
sub-object in the query is not recursivley parsed by Taffy.
Any ideas about this? Is this somehow possible with taffy?
Thanks in advance for your time.
Cheers
kioopi
--- In taffydb@yahoogroups.com, "tacoman_cool" <ian@...> wrote:
>
> You can view source to see the code. It is all inline JavaScript and
> there are some comments to show how it works.
>
> The DOM API I'm using is the 16 line Hyperscript example. It makes it
> really easy to write out code to the interface inline by creating
> functions for each tag (span(),div(), etc).
>
> Hyperscript:
> http://elzr.com/posts/hyperscript
>
> Beyond that it is just event handlers and calls to the four Taffy
> Collections.
>
> --- In taffydb@yahoogroups.com, wyzewoman99 <no_reply@> wrote:
> >
> > --- In taffydb@yahoogroups.com, "tacoman_cool" <ian@> wrote:
> > >
> > > I added a new example application to show how to use TaffyDB in the
> > > real world. I hope to add more of these in the future so let me know
> > > what you are looking for.
> > >
> > > Ian
> > >
> > > http://taffydb.com/example_schedule.cfm
> > >
> >
> > This looks neat! Any chance you'd be willing to post the code so I
> can see how you've made
> > it?
> >
> > (Apologies if you've seen this message twice before... I keep
> posting it and it keeps not
> > showing up...)
> >
> > Thanks!
> >
>
Oh, thanks. I had tried view source but apparently didn't scroll down far
enough!
Kendra
You can view source to see the code. It is all inline JavaScript and
there are some comments to show how it works.
The DOM API I'm using is the 16 line Hyperscript example. It makes it
really easy to write out code to the interface inline by creating
functions for each tag (span(),div(), etc).
Hyperscript:
http://elzr.com/posts/hyperscript
Beyond that it is just event handlers and calls to the four Taffy
Collections.
--- In taffydb@yahoogroups.com, wyzewoman99 <no_reply@...> wrote:
>
> --- In taffydb@yahoogroups.com, "tacoman_cool" <ian@> wrote:
> >
> > I added a new example application to show how to use TaffyDB in the
> > real world. I hope to add more of these in the future so let me know
> > what you are looking for.
> >
> > Ian
> >
> > http://taffydb.com/example_schedule.cfm
> >
>
> This looks neat! Any chance you'd be willing to post the code so I
can see how you've made
> it?
>
> (Apologies if you've seen this message twice before... I keep
posting it and it keeps not
> showing up...)
>
> Thanks!
>
--- In taffydb@yahoogroups.com, "tacoman_cool" <ian@...> wrote:
>
> I added a new example application to show how to use TaffyDB in the
> real world. I hope to add more of these in the future so let me know
> what you are looking for.
>
> Ian
>
> http://taffydb.com/example_schedule.cfm
>
This looks neat! Any chance you'd be willing to post the code so I can see how
you've made
it?
(Apologies if you've seen this message twice before... I keep posting it and it
keeps not
showing up...)
Thanks!
Matt,
Yeah, I thought about doing that. I guess I was afraid it would add to
much complication. My theory was that if someone needed to do it they
could also change the number inline. If they wanted greater than or
equal to 5 they would need to do greaterthan:4 and the like. Not a
perfect solution but it saves code.
Ian
--- In taffydb@yahoogroups.com, "berg.matt" <berg.matt@...> wrote:
>
> Ian,
>
> Thanks for the prompt response. It works perfectly.
>
> Not to be the only one to keep requesting things, but a greater than
> or equal might be a nice addition as well. Though I suppose you could
> just use a combination of equal and greaterthan. Just a thought.
>
> Thanks,
>
> Matt
>
>
> --- In taffydb@yahoogroups.com, "tacoman_cool" <ian@> wrote:
> >
> > Hey Matt,
> >
> > I dropped another release that I think will address your issue.
> > Download the latest on taffydb.com
> >
> > There should now be a couple of ways of finding an empty array
> > depending on what you want to do.
> >
> > Using length:
> > collection.find({arrayCol:{length:0}});
> > collection.find({arrayCol:{length:{lt:10}}});
> >
> > Using isSameArray:
> > collection.find({arrayCol:{isSameArray:[]}});
> >
> > I'll be updating the getting started article with more details
> > sometime today. Let me know if you have any questions or run into any
> > bugs.
> >
> > Ian
> >
> > --- In taffydb@yahoogroups.com, "berg.matt" <berg.matt@> wrote:
> > >
> > > Ian,
> > >
> > > Adding the ability to find by length sounds like the perfect
solution,
> > > especially if it is flexible for both arrays and strings.
> > >
> > > What you have envisioned would work nicely for me.
> > >
> > > Matt
> > > http://www.vitalist.com
> > >
> > > --- In taffydb@yahoogroups.com, "tacoman_cool" <ian@> wrote:
> > > >
> > > > Hi Matt,
> > > >
> > > > You know, I don't think you can do that natively....but it may
be a
> > > > good thing to add. One thing you can do currently is create a new
> > > > column with forEach to contain the length of the array (see
> example at
> > > > end of email). Only issue is that the forEach will have to be run
> > > > anytime you update the array in order to keep it current.
> > > >
> > > > I think I could patch Taffy to support what you are trying to do
> > > > though. Here is the syntax I envision:
> > > >
> > > > collection.find({arrayColumn:{length:0}});
> > > >
> > > > or for a greater than check:
> > > >
> > > > collection.find({arrayColumn:{length:{gt:25}}})
> > > >
> > > > Thoughts of this before I try and implement it? It would work for
> > > > strings as well.
> > > >
> > > > Ian
> > > >
> > > >
> > > > // forEach to create a new column with array length
> > > >
> > > > var emptyArrayTest = new TAFFY([{orange:[],box:"first"},
> > > > {orange:["12 oranges"],box:"second"}]);
> > > >
> > > > alert(emptyArrayTest.length);
> > > >
> > > > emptyArrayTest.forEach(function(r) {
> > > > r.orangeLength = r.orange.length
> > > > return r});
> > > >
> > > > alert(emptyArrayTest.first({orangeLength:0}).box);
> > > >
> > > > --- In taffydb@yahoogroups.com, "berg.matt" <berg.matt@> wrote:
> > > > >
> > > > > I know that you have the "contains" option, but what about
finding
> > > > > records with an empty array? I have tried a few options that
> don't
> > > > > seem to work.
> > > > >
> > > > > Thanks,
> > > > >
> > > > > Matt
> > > > >
> > > >
> > >
> >
>
Ian,
Thanks for the prompt response. It works perfectly.
Not to be the only one to keep requesting things, but a greater than
or equal might be a nice addition as well. Though I suppose you could
just use a combination of equal and greaterthan. Just a thought.
Thanks,
Matt
--- In taffydb@yahoogroups.com, "tacoman_cool" <ian@...> wrote:
>
> Hey Matt,
>
> I dropped another release that I think will address your issue.
> Download the latest on taffydb.com
>
> There should now be a couple of ways of finding an empty array
> depending on what you want to do.
>
> Using length:
> collection.find({arrayCol:{length:0}});
> collection.find({arrayCol:{length:{lt:10}}});
>
> Using isSameArray:
> collection.find({arrayCol:{isSameArray:[]}});
>
> I'll be updating the getting started article with more details
> sometime today. Let me know if you have any questions or run into any
> bugs.
>
> Ian
>
> --- In taffydb@yahoogroups.com, "berg.matt" <berg.matt@> wrote:
> >
> > Ian,
> >
> > Adding the ability to find by length sounds like the perfect solution,
> > especially if it is flexible for both arrays and strings.
> >
> > What you have envisioned would work nicely for me.
> >
> > Matt
> > http://www.vitalist.com
> >
> > --- In taffydb@yahoogroups.com, "tacoman_cool" <ian@> wrote:
> > >
> > > Hi Matt,
> > >
> > > You know, I don't think you can do that natively....but it may be a
> > > good thing to add. One thing you can do currently is create a new
> > > column with forEach to contain the length of the array (see
example at
> > > end of email). Only issue is that the forEach will have to be run
> > > anytime you update the array in order to keep it current.
> > >
> > > I think I could patch Taffy to support what you are trying to do
> > > though. Here is the syntax I envision:
> > >
> > > collection.find({arrayColumn:{length:0}});
> > >
> > > or for a greater than check:
> > >
> > > collection.find({arrayColumn:{length:{gt:25}}})
> > >
> > > Thoughts of this before I try and implement it? It would work for
> > > strings as well.
> > >
> > > Ian
> > >
> > >
> > > // forEach to create a new column with array length
> > >
> > > var emptyArrayTest = new TAFFY([{orange:[],box:"first"},
> > > {orange:["12 oranges"],box:"second"}]);
> > >
> > > alert(emptyArrayTest.length);
> > >
> > > emptyArrayTest.forEach(function(r) {
> > > r.orangeLength = r.orange.length
> > > return r});
> > >
> > > alert(emptyArrayTest.first({orangeLength:0}).box);
> > >
> > > --- In taffydb@yahoogroups.com, "berg.matt" <berg.matt@> wrote:
> > > >
> > > > I know that you have the "contains" option, but what about finding
> > > > records with an empty array? I have tried a few options that
don't
> > > > seem to work.
> > > >
> > > > Thanks,
> > > >
> > > > Matt
> > > >
> > >
> >
>
That is awesome. While I didn't request this, it is a welcome addition. Thanks for your prompt attention to this deficiency.
-Don
On Wed, Apr 30, 2008 at 9:44 AM, tacoman_cool <ian@...> wrote:
Hey Matt,
I dropped another release that I think will address your issue.
Download the latest on taffydb.com
There should now be a couple of ways of finding an empty array
depending on what you want to do.
Using length:
collection.find({arrayCol:{length:0}});
collection.find({arrayCol:{length:{lt:10}}});
Using isSameArray:
collection.find({arrayCol:{isSameArray:[]}});
I'll be updating the getting started article with more details
sometime today. Let me know if you have any questions or run into any
bugs.
Ian
--- In taffydb@yahoogroups.com, "berg.matt" <berg.matt@...> wrote:
>
> Ian,
>
> Adding the ability to find by length sounds like the perfect solution,
> especially if it is flexible for both arrays and strings.
>
> What you have envisioned would work nicely for me.
>
> Matt
> http://www.vitalist.com
>
> --- In taffydb@yahoogroups.com, "tacoman_cool" <ian@> wrote:
> >
> > Hi Matt,
> >
> > You know, I don't think you can do that natively....but it may be a
> > good thing to add. One thing you can do currently is create a new
> > column with forEach to contain the length of the array (see example at
> > end of email). Only issue is that the forEach will have to be run
> > anytime you update the array in order to keep it current.
> >
> > I think I could patch Taffy to support what you are trying to do
> > though. Here is the syntax I envision:
> >
> > collection.find({arrayColumn:{length:0}});
> >
> > or for a greater than check:
> >
> > collection.find({arrayColumn:{length:{gt:25}}})
> >
> > Thoughts of this before I try and implement it? It would work for
> > strings as well.
> >
> > Ian
> >
> >
> > // forEach to create a new column with array length
> >
> > var emptyArrayTest = new TAFFY([{orange:[],box:"first"},
> > {orange:["12 oranges"],box:"second"}]);
> >
> > alert(emptyArrayTest.length);
> >
> > emptyArrayTest.forEach(function(r) {
> > r.orangeLength = r.orange.length
> > return r});
> >
> > alert(emptyArrayTest.first({orangeLength:0}).box);
> >
> > --- In taffydb@yahoogroups.com, "berg.matt" <berg.matt@> wrote:
> > >
> > > I know that you have the "contains" option, but what about finding
> > > records with an empty array? I have tried a few options that don't
> > > seem to work.
> > >
> > > Thanks,
> > >
> > > Matt
> > >
> >
>
Hey Matt,
I dropped another release that I think will address your issue.
Download the latest on taffydb.com
There should now be a couple of ways of finding an empty array
depending on what you want to do.
Using length:
collection.find({arrayCol:{length:0}});
collection.find({arrayCol:{length:{lt:10}}});
Using isSameArray:
collection.find({arrayCol:{isSameArray:[]}});
I'll be updating the getting started article with more details
sometime today. Let me know if you have any questions or run into any
bugs.
Ian
--- In taffydb@yahoogroups.com, "berg.matt" <berg.matt@...> wrote:
>
> Ian,
>
> Adding the ability to find by length sounds like the perfect solution,
> especially if it is flexible for both arrays and strings.
>
> What you have envisioned would work nicely for me.
>
> Matt
> http://www.vitalist.com
>
> --- In taffydb@yahoogroups.com, "tacoman_cool" <ian@> wrote:
> >
> > Hi Matt,
> >
> > You know, I don't think you can do that natively....but it may be a
> > good thing to add. One thing you can do currently is create a new
> > column with forEach to contain the length of the array (see example at
> > end of email). Only issue is that the forEach will have to be run
> > anytime you update the array in order to keep it current.
> >
> > I think I could patch Taffy to support what you are trying to do
> > though. Here is the syntax I envision:
> >
> > collection.find({arrayColumn:{length:0}});
> >
> > or for a greater than check:
> >
> > collection.find({arrayColumn:{length:{gt:25}}})
> >
> > Thoughts of this before I try and implement it? It would work for
> > strings as well.
> >
> > Ian
> >
> >
> > // forEach to create a new column with array length
> >
> > var emptyArrayTest = new TAFFY([{orange:[],box:"first"},
> > {orange:["12 oranges"],box:"second"}]);
> >
> > alert(emptyArrayTest.length);
> >
> > emptyArrayTest.forEach(function(r) {
> > r.orangeLength = r.orange.length
> > return r});
> >
> > alert(emptyArrayTest.first({orangeLength:0}).box);
> >
> > --- In taffydb@yahoogroups.com, "berg.matt" <berg.matt@> wrote:
> > >
> > > I know that you have the "contains" option, but what about finding
> > > records with an empty array? I have tried a few options that don't
> > > seem to work.
> > >
> > > Thanks,
> > >
> > > Matt
> > >
> >
>
Ian,
Adding the ability to find by length sounds like the perfect solution,
especially if it is flexible for both arrays and strings.
What you have envisioned would work nicely for me.
Matt
http://www.vitalist.com
--- In taffydb@yahoogroups.com, "tacoman_cool" <ian@...> wrote:
>
> Hi Matt,
>
> You know, I don't think you can do that natively....but it may be a
> good thing to add. One thing you can do currently is create a new
> column with forEach to contain the length of the array (see example at
> end of email). Only issue is that the forEach will have to be run
> anytime you update the array in order to keep it current.
>
> I think I could patch Taffy to support what you are trying to do
> though. Here is the syntax I envision:
>
> collection.find({arrayColumn:{length:0}});
>
> or for a greater than check:
>
> collection.find({arrayColumn:{length:{gt:25}}})
>
> Thoughts of this before I try and implement it? It would work for
> strings as well.
>
> Ian
>
>
> // forEach to create a new column with array length
>
> var emptyArrayTest = new TAFFY([{orange:[],box:"first"},
> {orange:["12 oranges"],box:"second"}]);
>
> alert(emptyArrayTest.length);
>
> emptyArrayTest.forEach(function(r) {
> r.orangeLength = r.orange.length
> return r});
>
> alert(emptyArrayTest.first({orangeLength:0}).box);
>
> --- In taffydb@yahoogroups.com, "berg.matt" <berg.matt@> wrote:
> >
> > I know that you have the "contains" option, but what about finding
> > records with an empty array? I have tried a few options that don't
> > seem to work.
> >
> > Thanks,
> >
> > Matt
> >
>
Hi Matt,
You know, I don't think you can do that natively....but it may be a
good thing to add. One thing you can do currently is create a new
column with forEach to contain the length of the array (see example at
end of email). Only issue is that the forEach will have to be run
anytime you update the array in order to keep it current.
I think I could patch Taffy to support what you are trying to do
though. Here is the syntax I envision:
collection.find({arrayColumn:{length:0}});
or for a greater than check:
collection.find({arrayColumn:{length:{gt:25}}})
Thoughts of this before I try and implement it? It would work for
strings as well.
Ian
// forEach to create a new column with array length
var emptyArrayTest = new TAFFY([{orange:[],box:"first"},
{orange:["12 oranges"],box:"second"}]);
alert(emptyArrayTest.length);
emptyArrayTest.forEach(function(r) {
r.orangeLength = r.orange.length
return r});
alert(emptyArrayTest.first({orangeLength:0}).box);
--- In taffydb@yahoogroups.com, "berg.matt" <berg.matt@...> wrote:
>
> I know that you have the "contains" option, but what about finding
> records with an empty array? I have tried a few options that don't
> seem to work.
>
> Thanks,
>
> Matt
>
I know that you have the "contains" option, but what about finding
records with an empty array? I have tried a few options that don't
seem to work.
Thanks,
Matt
I added a new example application to show how to use TaffyDB in the
real world. I hope to add more of these in the future so let me know
what you are looking for.
Ian
http://taffydb.com/example_schedule.cfm
I think I understand what you are trying to do and you don't need to
use Eval for it.
This should work:
var year = 2006;
var city = "New York";
var rsltSet = data.get({year:year, city:city});
Alternatively you could also create the filter object outside of the
get call if that makes it easier:
var qry = {};
if (year > 0) {
qry["year"] = year;
}
if (city.length > 0)
{
qry["city"] = city;
}
var rsltSet = data.get(qry);
Hope that helps.
Ian
--- In taffydb@yahoogroups.com, "anodari" <anodari@...> wrote:
>
> Hi!
>
> Taffy DB is a great piece of software!
>
> I'm testing to use it in a CDRom project against a database with about
> 15k records.
>
> There are some simple method I could use optional parameters in a query?
>
> Explaining:
> Suppose I have 2 independent optional parameters to filter: Year and
> City. I want to filter only those the user has filled.
>
> It worked using eval:
> qry = "rsltSet = data.get({year:'" + year + "', city:'" + city +
"'})";
> eval(qry);
>
> But that looks ugly.
>
> Some suggestions?
>
> thank you.
>
> Antonio
>
Hi!
Taffy DB is a great piece of software!
I'm testing to use it in a CDRom project against a database with about
15k records.
There are some simple method I could use optional parameters in a query?
Explaining:
Suppose I have 2 independent optional parameters to filter: Year and
City. I want to filter only those the user has filled.
It worked using eval:
qry = "rsltSet = data.get({year:'" + year + "', city:'" + city + "'})";
eval(qry);
But that looks ugly.
Some suggestions?
thank you.
Antonio