EzDevInfo.com

taffydb

TaffyDB - an open source JavaScript Database for your browser TaffyDB - The JavaScript Database

How to dynamically create this Object for taffyDB query

I have a taffyDB filled with productdata and want to do a query to select all products with a range between >2 and <=4

   allProducts = TAFFY([
    {OrderNo:'prod1',range: 3,Status:'inactive'},
    {OrderNo:'prod2',range: 2,Status:'inactive'},
    {OrderNo:'prod3',range: 2,Status:'inactive'},
    {OrderNo:'prod4',range: 6,Status:'inactive'},
    {OrderNo:'prod5',range: 5,Status:'inactive'},

I know can easily do this with this query:

allProducts({range:{gt:2}},{range:{lte:4}}).get();

but how do I dynamically construct this query with values from two dropdownboxes? I can't think of a way to achieve it because I think I can't creat an object which has 2 properties with the same name :/


Source: (StackOverflow)

TaffyDB: Select problems

I'm new to TaffyDB and haven't done a lot of javascript programming so I'm hoping that the problem I'm having is something simple. I'm trying to update a listbox with the options stored in the TaffyDB according to the selected client. When I do my select however, it is returning all the rows.

Below is the code I am using to update the listbox, along with the selectString used to do the query, and what's in the TaffyDB.

Anyone have any ideas why I am getting back all rows when I specify clientID = 1788?

I tried the select string with and without quotes around the column identifier.

// load existing user client projects if we have any
var lbProjects = document.getElementById('lbProjects');
lbProjects.options.length = 0;
var selectString = '{clientID:"' + clientID + '"}';
alert(selectString);
userProjects(selectString).each(
function (r) {
    var option = new Option();
    option.value = r.projectID;
    option.text = r.projectName;
    lbProjects.add(option, null);
});

What's in selectString: {clientID:"1788"}

What's in the DB: [{"clientID":"1788","projectID":"19"}, {"clientID":"1789","projectID":"24"}, {"clientID":"1790","projectID":"23"}]

Thanks for any help. Aaron L. Bratcher


Source: (StackOverflow)

Advertisements

TaffyDB db().get() not returning an array of all the records

I'm just starting to learn TaffyDB and am relatively new to programming in general and I'm not sure why what I'm trying to do isn't working.

Just a simple db to mess around and play with:

var sports = TAFFY([{name:"Washington Capitals", sport:"Hockey"},
                    {name:"Washington Redskins", sport:"Football"},
                    {name: "Washington Nationals", sport:"Baseball"}
                  ]);

And then I call .get() and want to return all of the names in the db

console.log(sports().get("name"));

This just returns an array of 3 objects containing all of the info inside the db. It doesn't specifically pull the names into an array.

Am I making the call wrong?


Source: (StackOverflow)

Using an OR condition in TaffyDB with "lte" and "gte"

I have data in taffy DB that look like this. Data points can be blank:

{"first_name":"Sam", "last_name": "Andrew", "age":26 ... }
{"first_name":"Jane", "last_name": "Doe", "age": 19 ... } 
{"first_name":"John", "last_name": "Deer", "age":51 ... }
.
.
.

If i need all the rows where the first name is either "John" or "Jane", the age is between 40 and 60, the query would be:

{
    "name":["John","Jane"], 
    "age":{"lte":60,"gte":40}
}

Now if I add the condition that the age can be less than 20 as well, I am unable to write a query for that.

I have tried this but it does not work:

{
    "name":["John","Jane"], 
    "age":[{"lte":60,"gte":40},{"lte":20}]
}

Any help would be greatly appreciated.


Source: (StackOverflow)

Connecting to Taffy DB in Nodejs

I am building an application using Angular js,Node js and Taffy DB.

I am trying to store the data submitted from front-end to Taffy DB through Node js server.

var express = require('express');
var TAFFY = require('taffy');
var teamlist=TAFFY();
exports.postShareData=function(data,response){   
console.log(data);
teamlist.store();
teamlist.insert(data);
console.log(teamlist); 
}

But I get "localStorage is not defined".

What may be the problem?How to rectify it.

Please Advice


Source: (StackOverflow)

TaffyDB sort with a custom function

I'm updating my app to the latest TaffyDB, and it seems that orderBy has been removed:

allfeats = TAFFY(feats().get());
allfeats().orderBy(function(a, b) {
    return (a.prereqs == null || a.prereqs.feats == null) && (a.name < b.name) ? -1 : 1;
});

results in

Uncaught TypeError: allfeats(...).orderBy is not a function

How do I sort a TaffyDB with a comparison function?


Source: (StackOverflow)

Filter in Taffy

I want to pass column name as variable for gender, as my column in the filter will be decided at Runtime, if I am passing column name as variable then I am getting 0 rows in the result.

Please let me know the solution?

 var friends = TAFFY([
 {"id":1,"gender":"M","first":"John","last":"Smith","city":"Seattle, WA","status":"Active"},
 {"id":2,"gender":"F","first":"Kelly","last":"Ruth","city":"Dallas, TX","status":"Active"},
 {"id":3,"gender":"M","first":"Jeff","last":"Stevenson","city":"Washington, D.C.","status":"Active"},
 {"id":4,"gender":"F","first":"Jennifer","last":"Gill","city":"Seattle, WA","status":"Active"}
]);

var cities = friends({gender:"M"}).distinct("city");

Source: (StackOverflow)

TaffyDB - combine methods

I'm really new to TaffyDB and JavaScript. How can I combine methods in TaffyDB?

I'm trying to use distinct () and stringify(), which is not working

var xyz = db().distinct("mnths").stringify ();

console.log(xyz );

I get an error stating that stringify() is not supported.

Thank you.


Source: (StackOverflow)

Store an object with a TAFFY database

I have an object with TAFFY databases:

var save = {
    money: 20000,
    albumsReleased: 0,
    hour: 0,
    artistsHired: TAFFY(),
    albums: TAFFY()
}

Using JSON encoding doesn't work. How can I save the object in the localStorage?


Source: (StackOverflow)

Non-case sensitive query with TaffyDB (or other JS DB)

I'm using TaffyDB for a "DB" for the website I am working on right now. Its pretty neat, I can do 'like' searches. However, the 'like' search is still case sensitive and that if a record exist: "Banana", a query of "banana" will fail.

  • Anyone knows how to use TaffyDB for such query
  • Or, is there a JS DB that can do such function

Source: (StackOverflow)

adding json data using taffydb in durandal

I'm trying to use taffydb with durandal. I'm able to add simple json-data to a ko.observableArray() (a colleague showed me how :-) ).

Now I want to save it using taffydb.

main.js:

requirejs.config({
  paths: {
   'taffy': '../lib/db-master/taffy'
    ...
  }
});

participant.js:

define(['durandal/app', 'knockout', 'models/user', 'taffy'], function (app, ko, user, taffy) {
...
}

Whenever I add this:

var db = taffy;
db.insert({record:1, data:"test"});

I get this error:

Uncaught TypeError: Cannot call method 'insert' of undefined

Leaving it out will add test-data as expected. Am I 'holding' durandal the wrong way?

regards Claus


Source: (StackOverflow)

reading and writing to taffydb

I can't seem to get data from my taffyDB. It has to be bad syntax but I don't know where. My Javascript looks like this:

   // init db
    var procTech = TAFFY();

//..... other code in the middle

      procTech().remove(); 
      var x=0;
    $(".sxRow select[id^='KRCtech_']").each(function(){
        var techName= $(this).val();        
        x++;
        var xStr=x.toString();
        clog(xStr+" "+techName);
        procTech.insert({"count":xStr,"tech":techName });   
      });


      var ret=eval(procTech().select("count","tech"));   
        clog(ret.length);
        for(j=0;j<=ret.length-1;j++){     
            clog("read back: "+[j][0]+","+[j][1]);
      } 

// wrapper for console.log
function clog(s){
    window.console && console.log(s);
    return; 
}

console says:

 1 tonya
 2 shawn
 2
 read back: 0,undefined
 read back: 1,undefined

so I know that

  1. my initial values are good; i.e. they have value
  2. Taffy sees 2 records, which is correct

It's just when I try and retrieve them, they are garbage.

What am I doing wrong?


Source: (StackOverflow)

Is it possible to store database on local by using TAFFY()

Is it possible to store database on local by using TAFFY()?

An how to use wild card query on TAFFY()


Source: (StackOverflow)

Can race conditions exist with TaffyDB and node.js?

Can a race condition exist within TaffyDb and nodejs? For example: 100 concurrent connections with node.js using require('net') reliable data read relies on a variable Dbman(example) lock: to be 0 when not being read and 1 when being read. Could the data be read and therefor corrupted if 2 reads were called just before the lock to be set?


Source: (StackOverflow)

Using a variable name as a column name in TaffyDB

I am a novice to taffydb, faced following issue when trying to querying the db. My db has a column named TYPE. I tried to get all record where TYPE equals to "Yes".

This line give me the correct results:

var records = database({ "TYPE": { "===": "Yes" } });

But if I tried to pass these values as parameters no records found.

eg.

var column= "TYPE";
var operator = "===";
var value = "Yes" ;
var records = database({ column: { operator: value } });

Simply I need to pass these values as method parameters not in the hard-coded way. What should be the correct way to get this done?


Source: (StackOverflow)