Skip to search.

Breaking News Visit Yahoo! News for the latest.

×Close this window

taffydb · TaffyDB Support and User Group

The Yahoo! Groups Product Blog

Check it out!

Group Information

  • Members: 186
  • Category: JavaScript
  • Founded: Apr 25, 2008
  • Language: English
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Messages

Advanced
Messages Help
Messages 246 - 275 of 476   Oldest  |  < Older  |  Newer >  |  Newest
Messages: Show Message Summaries Sort by Date ^  
#246 From: "stephanfopeano" <stephan.fopeano@...>
Date: Fri Apr 16, 2010 8:25 pm
Subject: Problem with find combining has terms
stephanfopeano
Send Email Send Email
 
Hi,

I seem to be having a problem with the find method. I'm combining terms using
the has operator, and expected them to be AND'd, but they seem to be returning
OR results:

academicGradeLevel":{"is":"7"},"academic":{"has":"93"},academic:{"has":"115"}

I would expect this to find both 93 and 115 in the "academic" array, but it
returns an array with records with either 93 or 115. Am I doing something wrong?

Thanks,

Stephan

#247 From: "tacoman_cool" <ian@...>
Date: Fri Apr 16, 2010 9:20 pm
Subject: Re: Problem with find combining has terms
tacoman_cool
Send Email Send Email
 
Stephan,

Actually you're looking at a feature of JavaScript. Since an object {} can
contain only one of any given key any duplicates are ignored.

So
collection.find({academicGradeLevel":{"is":"7"},"academic":{"has":"93"},academic\
:{"has":"115"}})

Is really something like:

So collection.find({academicGradeLevel":{"is":"7"},"academic":{"has":"93"}})

Since either the first or second academic value will be ignored.

To do what you want you'll need to use the subfilter feature of find:

So
collection.find({academicGradeLevel":{"is":"7"},"academic":{"has":"93"}},collect\
ion.find({academic:{"has":"115"}}))

Here the results of the first find attempt ({academic:{"has":"115"}}) are passed
into the second find attempt which then filters only those results. The end
result is academic must have both 115 and 93 to be returned.

Ian

--- In taffydb@yahoogroups.com, "stephanfopeano" <stephan.fopeano@...> wrote:
>
> Hi,
>
> I seem to be having a problem with the find method. I'm combining terms using
the has operator, and expected them to be AND'd, but they seem to be returning
OR results:
>
> academicGradeLevel":{"is":"7"},"academic":{"has":"93"},academic:{"has":"115"}
>
> I would expect this to find both 93 and 115 in the "academic" array, but it
returns an array with records with either 93 or 115. Am I doing something wrong?
>
> Thanks,
>
>
>

#248 From: "stephanfopeano" <stephan.fopeano@...>
Date: Fri Apr 16, 2010 9:49 pm
Subject: Re: Problem with find combining has terms
stephanfopeano
Send Email Send Email
 
Thanks, Ian. That explains it! Thanks for the great tool!

-Stephan

--- In taffydb@yahoogroups.com, "tacoman_cool" <ian@...> wrote:
>
> Stephan,
>
> Actually you're looking at a feature of JavaScript. Since an object {} can
contain only one of any given key any duplicates are ignored.
>
> So
collection.find({academicGradeLevel":{"is":"7"},"academic":{"has":"93"},academic\
:{"has":"115"}})
>
> Is really something like:
>
> So collection.find({academicGradeLevel":{"is":"7"},"academic":{"has":"93"}})
>
> Since either the first or second academic value will be ignored.
>
> To do what you want you'll need to use the subfilter feature of find:
>
> So
collection.find({academicGradeLevel":{"is":"7"},"academic":{"has":"93"}},collect\
ion.find({academic:{"has":"115"}}))
>
> Here the results of the first find attempt ({academic:{"has":"115"}}) are
passed into the second find attempt which then filters only those results. The
end result is academic must have both 115 and 93 to be returned.
>
> Ian
>
> --- In taffydb@yahoogroups.com, "stephanfopeano" <stephan.fopeano@> wrote:
> >
> > Hi,
> >
> > I seem to be having a problem with the find method. I'm combining terms
using the has operator, and expected them to be AND'd, but they seem to be
returning OR results:
> >
> >
academicGradeLevel":{"is":"7"},"academic":{"has":"93"},academic:{"has":"115"}
> >
> > I would expect this to find both 93 and 115 in the "academic" array, but it
returns an array with records with either 93 or 115. Am I doing something wrong?
> >
> > Thanks,
> >
> >
> >
>

#249 From: test_addon
Date: Fri May 7, 2010 4:28 pm
Subject: Grouping in grid
test_addon
 
Hi,

is there an example how grouping could be achieved. I would especially interested to see how it is possible to print a grid where the columns have group header. I've found an example how to print a taffyDB in a simple grid as html table but I would be interested if there are also smart ways to get the grouping done, something like.

Date1 Date2
Country1 Country2 Country1
City1 City2 City3 City1
Travel X1
Travel X2
Travel X3

Assuming the TaffyDB would look like this

[
{tripID:'Travel X1',date:'Date1',city:'City1',country:'Country1',value:400},
{tripID:'Travel X1',date:'Date2',city:'City1',country:'Country1',value:800},
{tripID:'Travel X2',date:'Date1',city:'City1',country:'Country1',value:450},
{tripID:'Travel X1',date:'Date1',city:'City2',country:'Country1',value:300}
]


The taffydb website is down, so I can't get into the tutorials.

Greetings

#250 From: "tacoman_cool" <ian@...>
Date: Mon May 10, 2010 4:41 pm
Subject: Re: Grouping in grid
tacoman_cool
Send Email Send Email
 
Thanks for the heads up on the site. The server it is on keeps crashing so I'm
planning to move to a new server this week.

As for your question, the data grid isn't officially supported. Since the data
grid is so generic I'd recommend building something to render your custom table
using your data.

For example you could loop to get your tripIDs and then for each travel ID start
adding cells with the details. When you are done you can add the correct number
of column headers. I assume you are trying to make it dynamic so any given trip
could have unlimited cities, correct?

--- In taffydb@yahoogroups.com, test_addon <no_reply@...> wrote:
>
> Hi,
>
> is there an example how grouping could be achieved. I would especially
> interested to see how it is possible to print a grid where the columns
> have group header. I've found an example how to print a taffyDB in a
> simple grid as html table but I would be interested if there are also
> smart ways to get the grouping done, something like.
>
> Date1  Date2      Country1  Country2  Country1      City1  City2  City3
> City1   Travel X1        Travel X2        Travel X3
> Assuming the TaffyDB would look like this
>
> [
> {tripID:'Travel
> X1',date:'Date1',city:'City1',country:'Country1',value:400},
> {tripID:'Travel
> X1',date:'Date2',city:'City1',country:'Country1',value:800},
> {tripID:'Travel
> X2',date:'Date1',city:'City1',country:'Country1',value:450},
> {tripID:'Travel
> X1',date:'Date1',city:'City2',country:'Country1',value:300}
> ]
>
>
> The taffydb website is down, so I can't get into the tutorials.
>
> Greetings
>

#251 From: "capitaine_minuit" <capitaine_minuit@...>
Date: Sun Nov 21, 2010 12:02 pm
Subject: is TaffyDb localStorage backed?
capitaine_mi...
Send Email Send Email
 
Can TaffyDb use HTML5 localStorage?

Btw, TaffyDb is a great tool, Thanks!

#252 From: "yevgenie" <yevgenie@...>
Date: Wed Sep 8, 2010 8:47 pm
Subject: Re: Should Indexes be added to Taffy DB?
yevgenie
Send Email Send Email
 
Ian-
Would you be open to posting the code with the indexes?  I for one would find it
very useful.
Thanks.

#253 From: test_addon
Date: Mon May 10, 2010 7:00 pm
Subject: Re: Grouping in grid
test_addon
 
Yes, that is correct, it try to build a solution where I could define for both
axis (column and rows) the columns in an collection. Then the function should
draw the table. For example: an array for x-axis where first grouped by country,
than by city ... and the y-axis by booking, date etc.. Ideal I think of a
function to call like

buildGrid (collection, rowSortedAxisArray,columnSortedAxisArray)

buildGrid
(collDB,{'country':'...','city':'...',...},{'booking':'..',date:'...',...})

I'm using taffydb in an browser addon and so far it is really great and fast. 
Hope I get this solution done.

Greetings


--- In taffydb@yahoogroups.com, "tacoman_cool" <ian@...> wrote:
>
> Thanks for the heads up on the site. The server it is on keeps crashing so I'm
planning to move to a new server this week.
>
> As for your question, the data grid isn't officially supported. Since the data
grid is so generic I'd recommend building something to render your custom table
using your data.
>
> For example you could loop to get your tripIDs and then for each travel ID
start adding cells with the details. When you are done you can add the correct
number of column headers. I assume you are trying to make it dynamic so any
given trip could have unlimited cities, correct?
>
> --- In taffydb@yahoogroups.com, test_addon <no_reply@> wrote:
> >
> > Hi,
> >
> > is there an example how grouping could be achieved. I would especially
> > interested to see how it is possible to print a grid where the columns
> > have group header. I've found an example how to print a taffyDB in a
> > simple grid as html table but I would be interested if there are also
> > smart ways to get the grouping done, something like.
> >
> > Date1  Date2      Country1  Country2  Country1      City1  City2  City3
> > City1   Travel X1        Travel X2        Travel X3
> > Assuming the TaffyDB would look like this
> >
> > [
> > {tripID:'Travel
> > X1',date:'Date1',city:'City1',country:'Country1',value:400},
> > {tripID:'Travel
> > X1',date:'Date2',city:'City1',country:'Country1',value:800},
> > {tripID:'Travel
> > X2',date:'Date1',city:'City1',country:'Country1',value:450},
> > {tripID:'Travel
> > X1',date:'Date1',city:'City2',country:'Country1',value:300}
> > ]
> >
> >
> > The taffydb website is down, so I can't get into the tutorials.
> >
> > Greetings
> >
>

#254 From: "tacoman_cool" <ian@...>
Date: Tue Nov 23, 2010 6:14 pm
Subject: Re: is TaffyDb localStorage backed?
tacoman_cool
Send Email Send Email
 
It doesn't have a built in method but it would be very easy to do. Let's say you
had a TaffyDB collection called "messages". You could save it to local storage
like so:

localStorage.setItem('messages', messages.get());

You could then get it from localStorage and turn it back into a taffy collection
like so:

messages = TAFFY(localStorage.getItem('messages'));

I haven't tested the code. You could also use the onUpdate,onRemove,onInsert
events to sync to local storage for a given collection. For a large collection
(1000+ rows) this would have a performance hit but for a small collection you
could probably do it all the time safely.

--- In taffydb@yahoogroups.com, "capitaine_minuit" <capitaine_minuit@...> wrote:
>
> Can TaffyDb use HTML5 localStorage?
>
> Btw, TaffyDb is a great tool, Thanks!
>

#255 From: "andrew_wc_brown" <omen.king@...>
Date: Fri Dec 10, 2010 12:54 am
Subject: TaffyDB - Make a new website?
andrew_wc_brown
Send Email Send Email
 
Howdy Taffiers,

I using TaffyDB but the main website needs a bit of love.
Anyway I can fix up this website so its as awesome as Taffy itself?

#256 From: "tacoman_cool" <ian@...>
Date: Fri Dec 10, 2010 4:51 pm
Subject: Re: TaffyDB - Make a new website?
tacoman_cool
Send Email Send Email
 
That would be awesome Andrew.

For everyone's information, I'm working on a 2.0 version of TaffyDB based on a
recent project. It changes the API a little bit I think will improve the
usefulness of the library (and enable things like plugin enhancements, indexes,
etc). The project using the test code should go live in January with a public
release of 2.0 sometime after. It was be great to have a better design wrapped
around the launch.

--- In taffydb@yahoogroups.com, "andrew_wc_brown" <omen.king@...> wrote:
>
> Howdy Taffiers,
>
> I using TaffyDB but the main website needs a bit of love.
> Anyway I can fix up this website so its as awesome as Taffy itself?
>

#257 From: SimLev
Date: Thu May 19, 2011 11:07 am
Subject: OR
SimLev
 
Hi there, is there a simple way to perform a search using several condition in
OR in addition to AND?

e.g. {name:{regex:/^Joh/i} OR lastname:{regex:/mith$/i}

It could be done running multiple times the find method and joining the
resulting arrays, but it should be simpler than that, right?

Thanks,
SimLev

#258 From: taffydb-owner@yahoogroups.com
Date: Thu Sep 1, 2011 11:33 pm
Subject: TaffyDB 2.0 is out!
taffydb-owner@yahoogroups.com
Send Email Send Email
 
Finally! Over the past couple of months I've been pushing to turn the idea of
TaffyDB into a full on launched app. The site is new, the API is new. In fact,
almost every line has either been replaced or improved.

http://taffydb.com/

Key change: now TaffyDB works a lot more like jQuery for data.

Example:

Each DB is a function:

var db = TAFFY();

db({column:value}) // look for records where column = value

Additionally you can chain methods together.

messages({status:"unread"}).limit(15).order("datesent
logicaldesc").each(function (r) {
    alert(r.message);
}).update({status:"read"});

I'm writing this on the train but if I got that right this expression does the
following in one line:
1. Finds messages with a status of unread.
2. Limits the number to 15.
3. Orders just the query (not the whole DB like it would in Taffy 1.X) by a
column.
4. Loops over each record and alerts the message.
5. Updates the records to a status of read

You can also "cache" queries.

So let's say you had a collection of friends.

var friends = TAFFY();

You can now build cache queries that will stay current but never rerun unless
the data changes.

men = friends({gender:"M"});
women = friends({gender:"F"});

You can now do things like call men.each() or women.update() anywhere (assuming
they are global variables) in your app.

There is a lot more to look at. Please have a look. Let me know if you spot bugs
(spelling mistakes, etc).

Thanks!

http://taffydb.com

Ian
twitter.com/mriansmith

#259 From: "onnodivider" <onnodivider@...>
Date: Fri Sep 2, 2011 3:50 pm
Subject: TaffyDB Slowness
onnodivider
Send Email Send Email
 
Hi

I've implemented a TaffyDB 1.7.3 and I'm converting it to 2.0, but it is slow on
inserting large amounts of data.

This is my setup:
- Server which sends JSON objects
- Client AJAX website with TaffyDB as a local cache

When I request a userlist from the server it returns 519 objects. Each object is
inserted into the database, but needs to get checked if it already exists. The
fields "id" and "_type" are used to check if the object already exist in the
cache:

//Check if there exists an object in the database
var obj = this.db({"id":data["id"],"_type" : type}).first();
//The return value
var success = false;
// Update or insert the object
if(obj){
	 success = this.db(obj["___id"]).update(data);
} else {
	 success = this.db.insert(data);
}

With TaffyDB 2.0 this is really slow (Firefox even wants to stop the script)
while 1.7.3 had no problem with it.

Is there an easier method the check every object that gets inserted if it
already exists? "___id" is ofcourse not set as it comes from the server

Thanks,

Onno Steenbergen

#260 From: Darren Kovalchik <kovalchik@...>
Date: Fri Sep 2, 2011 3:55 pm
Subject: Re: TaffyDB 2.0 is out!
darren_koval...
Send Email Send Email
 
Awesome work Ian, looks great! Can't wait to figure out something to use it on.

#261 From: "tacoman_cool" <ian@...>
Date: Fri Sep 2, 2011 4:18 pm
Subject: Re: TaffyDB Slowness
tacoman_cool
Send Email Send Email
 
Hi Onno,

Sorry to hear about the slowness. 2.0 makes a number of changes to how data is
looked up and inserted although this seems like a slowness on lookup rather than
insert.

Couple of questions:

1. Is the data["id"] unique? What is the value? It may be possible to build an
object to determine if the record is loaded yet outside of Taffy (not ideal).
2. Are you always returning the full dataset from the server? If so it might be
faster to replace all the data rather than check each record.
3. How often is this part of your code running? Any time you talk to the server?
Only on startup? etc...

TaffyDB 2.0 is optimized around more complex and often repeated queries that
look for the same selection of records. For a case like this where hundreds of
queries are run all at once it is may need to optimized.

Ian

--- In taffydb@yahoogroups.com, "onnodivider" <onnodivider@...> wrote:
>
> Hi
>
> I've implemented a TaffyDB 1.7.3 and I'm converting it to 2.0, but it is slow
on inserting large amounts of data.
>
> This is my setup:
> - Server which sends JSON objects
> - Client AJAX website with TaffyDB as a local cache
>
> When I request a userlist from the server it returns 519 objects. Each object
is inserted into the database, but needs to get checked if it already exists.
The fields "id" and "_type" are used to check if the object already exist in the
cache:
>
> //Check if there exists an object in the database
> var obj = this.db({"id":data["id"],"_type" : type}).first();
> //The return value
> var success = false;
> // Update or insert the object
> if(obj){
>  success = this.db(obj["___id"]).update(data);
> } else {
>  success = this.db.insert(data);
> }
>
> With TaffyDB 2.0 this is really slow (Firefox even wants to stop the script)
while 1.7.3 had no problem with it.
>
> Is there an easier method the check every object that gets inserted if it
already exists? "___id" is ofcourse not set as it comes from the server
>
> Thanks,
>
> Onno Steenbergen
>

#262 From: "tacoman_cool" <ian@...>
Date: Fri Sep 2, 2011 4:26 pm
Subject: Re: TaffyDB Slowness
tacoman_cool
Send Email Send Email
 
Actually, I have one optimization that can be made right now to be more 2.0 ish.
I don't think it is your speed problem though.

I want to remove the "first" from your lookup and use count() inside your if
statement instead. You can then use obj.update and you'll save yourself a query
anytime you do an update.

Updates:

//Check if there exists an object in the database
var obj = this.db({"id":data["id"],"_type" : type});
//The return value
var success = false;
// Update or insert the object
if(obj.count()){
success = obj.update(data);
} else {
success = this.db.insert(data);
}

--- In taffydb@yahoogroups.com, "onnodivider" <onnodivider@...> wrote:
>
> Hi
>
> I've implemented a TaffyDB 1.7.3 and I'm converting it to 2.0, but it is slow
on inserting large amounts of data.
>
> This is my setup:
> - Server which sends JSON objects
> - Client AJAX website with TaffyDB as a local cache
>
> When I request a userlist from the server it returns 519 objects. Each object
is inserted into the database, but needs to get checked if it already exists.
The fields "id" and "_type" are used to check if the object already exist in the
cache:
>
> //Check if there exists an object in the database
> var obj = this.db({"id":data["id"],"_type" : type}).first();
> //The return value
> var success = false;
> // Update or insert the object
> if(obj){
>  success = this.db(obj["___id"]).update(data);
> } else {
>  success = this.db.insert(data);
> }
>
> With TaffyDB 2.0 this is really slow (Firefox even wants to stop the script)
while 1.7.3 had no problem with it.
>
> Is there an easier method the check every object that gets inserted if it
already exists? "___id" is ofcourse not set as it comes from the server
>
> Thanks,
>
> Onno Steenbergen
>

#263 From: Don Smith <donwsmith@...>
Date: Fri Sep 2, 2011 4:40 pm
Subject: Re: TaffyDB 2.0 is out!
donwsmith@...
Send Email Send Email
 
Super awesomeness!

On Thu, Sep 1, 2011 at 4:33 PM, <taffydb-owner@yahoogroups.com> wrote:
 

Finally! Over the past couple of months I've been pushing to turn the idea of TaffyDB into a full on launched app. The site is new, the API is new. In fact, almost every line has either been replaced or improved.

http://taffydb.com/

Key change: now TaffyDB works a lot more like jQuery for data.

Example:

Each DB is a function:

var db = TAFFY();

db({column:value}) // look for records where column = value

Additionally you can chain methods together.

messages({status:"unread"}).limit(15).order("datesent logicaldesc").each(function (r) {
alert(r.message);
}).update({status:"read"});

I'm writing this on the train but if I got that right this expression does the following in one line:
1. Finds messages with a status of unread.
2. Limits the number to 15.
3. Orders just the query (not the whole DB like it would in Taffy 1.X) by a column.
4. Loops over each record and alerts the message.
5. Updates the records to a status of read

You can also "cache" queries.

So let's say you had a collection of friends.

var friends = TAFFY();

You can now build cache queries that will stay current but never rerun unless the data changes.

men = friends({gender:"M"});
women = friends({gender:"F"});

You can now do things like call men.each() or women.update() anywhere (assuming they are global variables) in your app.

There is a lot more to look at. Please have a look. Let me know if you spot bugs (spelling mistakes, etc).

Thanks!

http://taffydb.com

Ian
twitter.com/mriansmith



#264 From: "tacoman_cool" <ian@...>
Date: Fri Sep 2, 2011 5:02 pm
Subject: Re: TaffyDB Slowness
tacoman_cool
Send Email Send Email
 
Ok, so I may have a fix you can try out. It may take a small amount of code
rework. We are basiclly going to bypass the default look up by creating an
extension to do the work for you. We are going to create a single "upsert"
extension to take a key, look for dups, and do an insert or update directly on
the DB instead of using the external methods.

Here is the extension. Drop this at the top of your script so it only runs once:

TAFFY.extend("upsert",function (primarykeys,records) {
			  // get context
			  var that = this;
			  // run query as needed
              that.context({
                    results: that.getDBI().query(that.context())
              });
              var foundRecords = {};
             TAFFY.each(this.context().results,function (r) {
            	 var k = "";
            	 TAFFY.each(primarykeys,function (key) {
            		 k = k +"_" + r[key];
            	 })
            	 foundRecords[k] = r.___id;
             });

             TAFFY.each(records,function (r) {
            	 var k = "";
            	 TAFFY.each(primarykeys,function (key) {
            		 k = k +"_" + r[key];
            	 })
            	 if (foundRecords[k]) {
            		  that.getDBI().update(foundRecords[k], r);
            	 } else {
            		 that.getDBI().insert(r);
            	 }
             });
             // since data may have changed, clear chache
             if (this.context().results.length) {
                 this.context({
                     run: null
                 });
             }
             return this;
})

And here is my test with 500 records and 500 updates. FireFox has no issues with
it:

		 var speed = TAFFY();

		 for(var x = 0;x<500;x++) {
			 speed.insert({id:"abc"+x,type:"a"});
		 }
		 var records = [];
		 for(var x = 0;x<500;x++) {
			 records.push({id:"abc"+x,type:"a"});
		 }

		 speed().upsert(["id","type"],records);


So your code would look something like this on the upsert:

this.db().upsert(["id","_type"],recordsArrayFromServer);

The first arg are the primary key columns and the second would be all the
records from the server in an array. The script should then figure out what
already exists and call the insert or update as needed.


--- In taffydb@yahoogroups.com, "onnodivider" <onnodivider@...> wrote:
>
> Hi
>
> I've implemented a TaffyDB 1.7.3 and I'm converting it to 2.0, but it is slow
on inserting large amounts of data.
>
> This is my setup:
> - Server which sends JSON objects
> - Client AJAX website with TaffyDB as a local cache
>
> When I request a userlist from the server it returns 519 objects. Each object
is inserted into the database, but needs to get checked if it already exists.
The fields "id" and "_type" are used to check if the object already exist in the
cache:
>
> //Check if there exists an object in the database
> var obj = this.db({"id":data["id"],"_type" : type}).first();
> //The return value
> var success = false;
> // Update or insert the object
> if(obj){
>  success = this.db(obj["___id"]).update(data);
> } else {
>  success = this.db.insert(data);
> }
>
> With TaffyDB 2.0 this is really slow (Firefox even wants to stop the script)
while 1.7.3 had no problem with it.
>
> Is there an easier method the check every object that gets inserted if it
already exists? "___id" is ofcourse not set as it comes from the server
>
> Thanks,
>
> Onno Steenbergen
>

#265 From: "Givius" <givius24@...>
Date: Thu Sep 8, 2011 4:20 pm
Subject: v2.0 OrberBy() and Get() are missing
givius24
Send Email Send Email
 
Hello,

I just got the update from 1.7  to 2.0, and now my code is complaining about
this two functions:
"taffyObj.orderBy is not a function"
"taffyObj.get is not a function"

can you please advice how can I handle this two missing/changed functions.

thanks

-Charly

#266 From: "tacoman_cool" <ian@...>
Date: Thu Sep 8, 2011 4:50 pm
Subject: Re: v2.0 OrberBy() and Get() are missing
tacoman_cool
Send Email Send Email
 
Hi Charly,

There are a couple of key API differences between the 1.X stack and 2.0. The
main one is that your DB is now a function and you use that function to filter
for records. It returns a collection of methods to then work with your filtered
data.

So...

var mystuff = TAFFY();

// get records with status = 1
var myrecords = mystuff({status:1}).get();

Additionally the root DB function has a couple of methods:

mystuff.insert(newrecord);
mystuff.sort("status desc");

Sort changes the order of the data in the database but it isn't the only way can
order data. You can also do it when you query for data and using the order()
method only changes the order of the data you are working with, not the whole
DB.

var myOrderedRecords = mystuff({status:1}).order("name").get();

There are a variety of reasons for the change but one key advantage is chaining
of methods and reuse of queries.

Example chain:

mystuff().limit(15).order("name").each(func).update();

Example reuse:

var activeRecords = mystuff({status:1});

activeRecords.get();
activeRecords.each();
activeRecords.update();

So you'll have to make a few minor updates to your code. The docs on TaffyDB.com
have been updated to reflect the changes.

Ian

--- In taffydb@yahoogroups.com, "Givius" <givius24@...> wrote:
>
> Hello,
>
> I just got the update from 1.7  to 2.0, and now my code is complaining about
this two functions:
> "taffyObj.orderBy is not a function"
> "taffyObj.get is not a function"
>
> can you please advice how can I handle this two missing/changed functions.
>
> thanks
>
> -Charly
>

#267 From: "onnodivider" <onnodivider@...>
Date: Fri Sep 9, 2011 7:31 am
Subject: Re: TaffyDB Slowness
onnodivider
Send Email Send Email
 
Thanks, works like a charm! Maybe include this into Taffy by default!?

Onno

--- In taffydb@yahoogroups.com, "tacoman_cool" <ian@...> wrote:
>
> Ok, so I may have a fix you can try out. It may take a small amount of code
rework. We are basiclly going to bypass the default look up by creating an
extension to do the work for you. We are going to create a single "upsert"
extension to take a key, look for dups, and do an insert or update directly on
the DB instead of using the external methods.
>
> Here is the extension. Drop this at the top of your script so it only runs
once:
>
> TAFFY.extend("upsert",function (primarykeys,records) {
> 			 // get context
> 			 var that = this;
> 			 // run query as needed
>              that.context({
>                    results: that.getDBI().query(that.context())
>              });
>              var foundRecords = {};
>             TAFFY.each(this.context().results,function (r) {
>              var k = "";
>              TAFFY.each(primarykeys,function (key) {
>             	 k = k +"_" + r[key];
>              })
>              foundRecords[k] = r.___id;
>             });
>
>             TAFFY.each(records,function (r) {
>              var k = "";
>              TAFFY.each(primarykeys,function (key) {
>             	 k = k +"_" + r[key];
>              })
>              if (foundRecords[k]) {
>             		 that.getDBI().update(foundRecords[k], r);
>              } else {
>             	 that.getDBI().insert(r);
>              }
>             });
>             // since data may have changed, clear chache
>             if (this.context().results.length) {
>                 this.context({
>                     run: null
>                 });
>             }
>             return this;
> })
>
> And here is my test with 500 records and 500 updates. FireFox has no issues
with it:
>
> 	 var speed = TAFFY();
>
> 	 for(var x = 0;x<500;x++) {
> 		 speed.insert({id:"abc"+x,type:"a"});
> 	 }
> 	 var records = [];
> 	 for(var x = 0;x<500;x++) {
> 		 records.push({id:"abc"+x,type:"a"});
> 	 }
>
> 	 speed().upsert(["id","type"],records);
>
>
> So your code would look something like this on the upsert:
>
> this.db().upsert(["id","_type"],recordsArrayFromServer);
>
> The first arg are the primary key columns and the second would be all the
records from the server in an array. The script should then figure out what
already exists and call the insert or update as needed.
>
>
> --- In taffydb@yahoogroups.com, "onnodivider" <onnodivider@> wrote:
> >
> > Hi
> >
> > I've implemented a TaffyDB 1.7.3 and I'm converting it to 2.0, but it is
slow on inserting large amounts of data.
> >
> > This is my setup:
> > - Server which sends JSON objects
> > - Client AJAX website with TaffyDB as a local cache
> >
> > When I request a userlist from the server it returns 519 objects. Each
object is inserted into the database, but needs to get checked if it already
exists. The fields "id" and "_type" are used to check if the object already
exist in the cache:
> >
> > //Check if there exists an object in the database
> > var obj = this.db({"id":data["id"],"_type" : type}).first();
> > //The return value
> > var success = false;
> > // Update or insert the object
> > if(obj){
> >  success = this.db(obj["___id"]).update(data);
> > } else {
> >  success = this.db.insert(data);
> > }
> >
> > With TaffyDB 2.0 this is really slow (Firefox even wants to stop the script)
while 1.7.3 had no problem with it.
> >
> > Is there an easier method the check every object that gets inserted if it
already exists? "___id" is ofcourse not set as it comes from the server
> >
> > Thanks,
> >
> > Onno Steenbergen
> >
>

#268 From: "Givius" <givius24@...>
Date: Wed Sep 14, 2011 8:57 pm
Subject: Re: v2.0 OrberBy() and Get() are missing
givius24
Send Email Send Email
 
Thanks a lot for the advice I did the changes in my code and all seems to be
working fine.

--Charles

--- In taffydb@yahoogroups.com, "tacoman_cool" <ian@...> wrote:
>
> Hi Charly,
>
> There are a couple of key API differences between the 1.X stack and 2.0. The
main one is that your DB is now a function and you use that function to filter
for records. It returns a collection of methods to then work with your filtered
data.
>
> So...
>
> var mystuff = TAFFY();
>
> // get records with status = 1
> var myrecords = mystuff({status:1}).get();
>
> Additionally the root DB function has a couple of methods:
>
> mystuff.insert(newrecord);
> mystuff.sort("status desc");
>
> Sort changes the order of the data in the database but it isn't the only way
can order data. You can also do it when you query for data and using the order()
method only changes the order of the data you are working with, not the whole
DB.
>
> var myOrderedRecords = mystuff({status:1}).order("name").get();
>
> There are a variety of reasons for the change but one key advantage is
chaining of methods and reuse of queries.
>
> Example chain:
>
> mystuff().limit(15).order("name").each(func).update();
>
> Example reuse:
>
> var activeRecords = mystuff({status:1});
>
> activeRecords.get();
> activeRecords.each();
> activeRecords.update();
>
> So you'll have to make a few minor updates to your code. The docs on
TaffyDB.com have been updated to reflect the changes.
>
> Ian
>
> --- In taffydb@yahoogroups.com, "Givius" <givius24@> wrote:
> >
> > Hello,
> >
> > I just got the update from 1.7  to 2.0, and now my code is complaining about
this two functions:
> > "taffyObj.orderBy is not a function"
> > "taffyObj.get is not a function"
> >
> > can you please advice how can I handle this two missing/changed functions.
> >
> > thanks
> >
> > -Charly
> >
>

#269 From: "wklau2046" <wklau2006@...>
Date: Mon Sep 19, 2011 5:46 am
Subject: Some bugs(?) and some requests
wklau2046
Send Email Send Email
 
1. The "!" is not working properly, it seems that the following line is wrong:

// get the match results based on the s/match type
                                     var r = ((s === "regex") ?
(mtest.test(mvalue)) :
                                             (s === "lt") ? (mvalue < mtest) :
                                             (s === "gt") ? (mvalue > mtest) :
                                             (s === "lte") ? (mvalue <= mtest) :
                                             (s === "gte") ? (mvalue >= mtest) :
                                             (s === "left") ?
(mvalue.indexOf(mtest) === 0)  :
                                             (s === "leftnocase") ?
(mvalue.toLowerCase().indexOf(mtest.toLowerCase()) === 0) :
                                             (s === "right") ?
(mvalue.substring((mvalue.length - mtest.length)) === mtest) :
                                             (s === "rightnocase") ?
(mvalue.toLowerCase().substring((mvalue.length - mtest.length)) ===
mtest.toLowerCase()) :
                                             (s === "like") ?
(mvalue.indexOf(mtest) >= 0) :
                                             (s === "likenocase") ?
(mvalue.toLowerCase().indexOf(mtest.toLowerCase()) >= 0) :
                                             (s === "is") ? (mvalue === mtest) :
                                             (s === "isnocase") ?
(mvalue.toLowerCase() === mtest.toLowerCase()) :
                                             (s === "has") ? (T.has(mvalue,
mtest)) :
                                             (s === "hasall") ? (T.hasAll(mvalue,
mtest)) :
                                             (!TAFFY.isUndefined(mvalue[s]) &&
!TAFFY.isObject(mtest) && !TAFFY.isArray(mtest)) ? (mtest === mvalue[s]) :
                                             (T[s] && T.isFunction(T[s])) ?
T[s](mvalue, mtest) :
																						 (su === f)) ? su : f; //(su === f) ? su : f) //*** TAFFY
bug

2. The has() is not working properly, it seems that the function should return
re.

3. Now by default forcePropertyCase: "lower", so all data will be converted to
lowercase. I have to change it to null. Maybe the constructor should allow a
second argument for passing the default settings.

4. Suggestion:

Expose JSON:

TAFFY.JSON = JSON;

so we can use JSON also.

#270 From: taffydb-owner@yahoogroups.com
Date: Tue Sep 20, 2011 2:22 am
Subject: Re: Some bugs(?) and some requests
tacoman_cool
Send Email Send Email
 
Patched in 2.2 to address these issues.

1. I found the issue with "!" and fixed it.

2. I couldn't find any issues with has. Do you have some example code of
something that isn't working?

3. I've changed the default from "Lower" to NULL for forcePropertyCase. It is
more consistent with JavaScript's view of the world and increases performance.

4. I expose JSON globally now. Hadn't realized that I wasn't.

Additionally I removed several unneeded loops which has added a dramatic speed
improvement.  TaffyDB is essentially running on poor with authoring the for()
loops yourself and features dramatic improvements for repeated queries thanks to
query caching from the last release.



--- In taffydb@yahoogroups.com, "wklau2046" <wklau2006@...> wrote:
>
> 1. The "!" is not working properly, it seems that the following line is wrong:
>
> // get the match results based on the s/match type
>                                     var r = ((s === "regex") ?
(mtest.test(mvalue)) :
>                                             (s === "lt") ? (mvalue < mtest) :
>                                             (s === "gt") ? (mvalue > mtest) :
>                                             (s === "lte") ? (mvalue <= mtest)
:
>                                             (s === "gte") ? (mvalue >= mtest)
:
>                                             (s === "left") ?
(mvalue.indexOf(mtest) === 0)  :
>                                             (s === "leftnocase") ?
(mvalue.toLowerCase().indexOf(mtest.toLowerCase()) === 0) :
>                                             (s === "right") ?
(mvalue.substring((mvalue.length - mtest.length)) === mtest) :
>                                             (s === "rightnocase") ?
(mvalue.toLowerCase().substring((mvalue.length - mtest.length)) ===
mtest.toLowerCase()) :
>                                             (s === "like") ?
(mvalue.indexOf(mtest) >= 0) :
>                                             (s === "likenocase") ?
(mvalue.toLowerCase().indexOf(mtest.toLowerCase()) >= 0) :
>                                             (s === "is") ? (mvalue === mtest)
:
>                                             (s === "isnocase") ?
(mvalue.toLowerCase() === mtest.toLowerCase()) :
>                                             (s === "has") ? (T.has(mvalue,
mtest)) :
>                                             (s === "hasall") ?
(T.hasAll(mvalue, mtest)) :
>                                             (!TAFFY.isUndefined(mvalue[s]) &&
!TAFFY.isObject(mtest) && !TAFFY.isArray(mtest)) ? (mtest === mvalue[s]) :
>                                             (T[s] && T.isFunction(T[s])) ?
T[s](mvalue, mtest) :
> 																					 (su === f)) ? su : f; //(su === f) ? su : f) //*** TAFFY
bug
>
> 2. The has() is not working properly, it seems that the function should return
re.
>
> 3. Now by default forcePropertyCase: "lower", so all data will be converted to
lowercase. I have to change it to null. Maybe the constructor should allow a
second argument for passing the default settings.
>
> 4. Suggestion:
>
> Expose JSON:
>
> TAFFY.JSON = JSON;
>
> so we can use JSON also.
>

#271 From: "wklau2046" <wklau2006@...>
Date: Tue Sep 20, 2011 2:33 am
Subject: Re: Some bugs(?) and some requests
wklau2046
Send Email Send Email
 
2. The problem is in the line:

                     } else if (T.isArray(var2)) {
                         each(var2, function (v, n) {
                             re = T.has(var1, var2[n]);
                             if (re === true) {
                                 return TAFFY.EXIT;
                             }
                         });
                                                 return re; //*** missing this

Looking forward to v2.2.

Regards.


--- In taffydb@yahoogroups.com, taffydb-owner@yahoogroups.com wrote:
>
> Patched in 2.2 to address these issues.
>
> 1. I found the issue with "!" and fixed it.
>
> 2. I couldn't find any issues with has. Do you have some example code of
something that isn't working?
>
> 3. I've changed the default from "Lower" to NULL for forcePropertyCase. It is
more consistent with JavaScript's view of the world and increases performance.
>
> 4. I expose JSON globally now. Hadn't realized that I wasn't.
>
> Additionally I removed several unneeded loops which has added a dramatic speed
improvement.  TaffyDB is essentially running on poor with authoring the for()
loops yourself and features dramatic improvements for repeated queries thanks to
query caching from the last release.
>
>
>
> --- In taffydb@yahoogroups.com, "wklau2046" <wklau2006@> wrote:
> >
> > 1. The "!" is not working properly, it seems that the following line is
wrong:
> >
> > // get the match results based on the s/match type
> >                                     var r = ((s === "regex") ?
(mtest.test(mvalue)) :
> >                                             (s === "lt") ? (mvalue < mtest)
:
> >                                             (s === "gt") ? (mvalue > mtest)
:
> >                                             (s === "lte") ? (mvalue <=
mtest) :
> >                                             (s === "gte") ? (mvalue >=
mtest) :
> >                                             (s === "left") ?
(mvalue.indexOf(mtest) === 0)  :
> >                                             (s === "leftnocase") ?
(mvalue.toLowerCase().indexOf(mtest.toLowerCase()) === 0) :
> >                                             (s === "right") ?
(mvalue.substring((mvalue.length - mtest.length)) === mtest) :
> >                                             (s === "rightnocase") ?
(mvalue.toLowerCase().substring((mvalue.length - mtest.length)) ===
mtest.toLowerCase()) :
> >                                             (s === "like") ?
(mvalue.indexOf(mtest) >= 0) :
> >                                             (s === "likenocase") ?
(mvalue.toLowerCase().indexOf(mtest.toLowerCase()) >= 0) :
> >                                             (s === "is") ? (mvalue ===
mtest) :
> >                                             (s === "isnocase") ?
(mvalue.toLowerCase() === mtest.toLowerCase()) :
> >                                             (s === "has") ? (T.has(mvalue,
mtest)) :
> >                                             (s === "hasall") ?
(T.hasAll(mvalue, mtest)) :
> >                                             (!TAFFY.isUndefined(mvalue[s])
&& !TAFFY.isObject(mtest) && !TAFFY.isArray(mtest)) ? (mtest === mvalue[s]) :
> >                                             (T[s] && T.isFunction(T[s])) ?
T[s](mvalue, mtest) :
> > 																					 (su === f)) ? su : f; //(su === f) ? su : f) //***
TAFFY bug
> >
> > 2. The has() is not working properly, it seems that the function should
return re.
> >
> > 3. Now by default forcePropertyCase: "lower", so all data will be converted
to lowercase. I have to change it to null. Maybe the constructor should allow a
second argument for passing the default settings.
> >
> > 4. Suggestion:
> >
> > Expose JSON:
> >
> > TAFFY.JSON = JSON;
> >
> > so we can use JSON also.
> >
>

#272 From: "tacoman_cool" <ian@...>
Date: Tue Sep 20, 2011 2:42 am
Subject: Re: Some bugs(?) and some requests
tacoman_cool
Send Email Send Email
 
Ahh, thanks. I believe it is fixed in just deployed 2.2.1.

#273 From: "wklau2046" <wklau2006@...>
Date: Tue Sep 20, 2011 4:15 am
Subject: Re: Some bugs(?) and some requests
wklau2046
Send Email Send Email
 
Thank you for quick response.

Regarding the JSON issue, the new code is:

         JSON; // *** error line
         if (!JSON) {
             JSON = {};
         }

While this will work in newer browsers, it will raise "'JSON' is undefined"
error in older browsers such as IE7.



--- In taffydb@yahoogroups.com, "tacoman_cool" <ian@...> wrote:
>
> Ahh, thanks. I believe it is fixed in just deployed 2.2.1.
>

#274 From: "wklau2046" <wklau2006@...>
Date: Tue Sep 20, 2011 5:03 am
Subject: Re: Some bugs(?) and some requests
wklau2046
Send Email Send Email
 
In 2.2.1, now we have:

case "object":
                     if (T.isObject(var2)) {
                         eachin(var2, function (v, n) {
                             if (re === true && !T.isUndefined(var1[n]) &&
var1.hasOwnProperty(n)) {
                                 re = T.has(var1[n], var2[n]);
                             } else {
                                 re = false;
                                 return TAFFY.EXIT;
                             }
                         })
                     } else if (T.isArray(var2)) {
                         each(var2, function (v, n) {
                             re = T.has(var1, var2[n]);
                             if (re) {
                                 return TAFFY.EXIT;
                             }
                         });
                     } else if (T.isString(var2) &&
!TAFFY.isUndefined(var1[var2])) {
                         return true;
                     }
                     return re;
                     break;

But in the 3rd case (T.isString(var2) && !TAFFY.isUndefined(var1[var2])), it
will return re (=true) if the 3rd case is false.




--- In taffydb@yahoogroups.com, "tacoman_cool" <ian@...> wrote:
>
> Ahh, thanks. I believe it is fixed in just deployed 2.2.1.
>

#275 From: "tacoman_cool" <ian@...>
Date: Tue Sep 20, 2011 6:17 am
Subject: Re: Some bugs(?) and some requests
tacoman_cool
Send Email Send Email
 
That for the help debugging. I think both the JSON and has issues are fixed in
2.2.2.

--- In taffydb@yahoogroups.com, "wklau2046" <wklau2006@...> wrote:
>
> In 2.2.1, now we have:
>
> case "object":
>                     if (T.isObject(var2)) {
>                         eachin(var2, function (v, n) {
>                             if (re === true && !T.isUndefined(var1[n]) &&
var1.hasOwnProperty(n)) {
>                                 re = T.has(var1[n], var2[n]);
>                             } else {
>                                 re = false;
>                                 return TAFFY.EXIT;
>                             }
>                         })
>                     } else if (T.isArray(var2)) {
>                         each(var2, function (v, n) {
>                             re = T.has(var1, var2[n]);
>                             if (re) {
>                                 return TAFFY.EXIT;
>                             }
>                         });
>                     } else if (T.isString(var2) &&
!TAFFY.isUndefined(var1[var2])) {
>                         return true;
>                     }
>                     return re;
>                     break;
>
> But in the 3rd case (T.isString(var2) && !TAFFY.isUndefined(var1[var2])), it
will return re (=true) if the 3rd case is false.
>
>
>
>
> --- In taffydb@yahoogroups.com, "tacoman_cool" <ian@> wrote:
> >
> > Ahh, thanks. I believe it is fixed in just deployed 2.2.1.
> >
>

Messages 246 - 275 of 476   Oldest  |  < Older  |  Newer >  |  Newest
Add to My Yahoo!      XML What's This?

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines NEW - Help