btwael / locallydb Goto Github PK
View Code? Open in Web Editor NEWAn easy-to-use and lightweight local storage database for node.js and node-webkit
Home Page: http://boutglay.com/locallydb/
License: MIT License
An easy-to-use and lightweight local storage database for node.js and node-webkit
Home Page: http://boutglay.com/locallydb/
License: MIT License
Dear Wael Boutglay,
I've been evaluated your library and found an issue after remove() operation. Running 0.0.3 version.
// Insert/add/push a list of elements
collection.insert([
{name: "sphinx", mythology: "greek", eyes: 2, sex: "f", hobbies: ["riddles","sitting","being a wonder"]},
{name: "hydra", mythology: "greek", eyes: 18, sex: "m", hobbies: ["coiling","terrorizing","growing"]},
{name: "huldra", mythology: "norse", eyes: 2, sex: "f", hobbies: ["luring","terrorizing"]},
{name: "cyclops", mythology: "greek", eyes: 1, sex: "m", hobbies: ["staring","terrorizing"]},
{name: "fenrir", mythology: "norse", eyes: 2, sex: "m", hobbies: ["growing","god-killing"]},
{name: "medusa", mythology: "greek", eyes: 2, sex: "f", hobbies: ["coiling","staring"]}
]);
var entry = collection.where({ name : 'fenrir' })
console.log(entry[0].cid); // => Display 4
collection.update( entry[0].cid, { eyes : 7 } );
console.log( entry[0].cid);
// => { name: 'fenrir', mythology: 'norse', eyes: 7, sex: 'm', hobbies: [ 'growing', 'god-killing' ], cid: 4, '$created': '2014-09-15T19:50:22.090Z', '$updated': '2014-09-15T19:50:22.091Z' },
var one = collection.get(2);
console.log(one); // => {name: "huldra", mythology: "norse", eyes: 2, sex: "f", hobbies: ["luring","terrorizing"]}
collection.remove(2);
collection.save();
var list = collection.items;
console.log(list); // => The whole list [ ...{ hydra ...} , , { cyclops ... }, ...}] but there is a null element between hydra and cyclops
var entry = collection.where({ name : 'fenrir' })
console.log(entry[0].cid); // => Display 4
collection.update( entry[0].cid, { eyes : 7 } ); //or collection.update( 4, { eyes : 7 } );
// => .../node_modules/locallydb/lib/collection.js:107
// if (element.cid === cid) {
// ^
// TypeError: Cannot read property 'cid' of undefined
// at Collection.update (/home/sjphyun/Angular/gardplc/node_modules/locallydb/lib/collection.js:107:20)
// ...
Best regards,
Dear Wael Boutglay,
I encountered the following problem. where() returns { items : [A,B,C,D]} on Linux However, I see the different result from windows/Mac platforms. It returns a list instead. [A,B,C,D].
Thanks.
There's a little bug that makes removeCollection method fail:
removeCollection: (name) ->
collecton = @collection(name)
fs.unlinkSync(collection._cpath)
should just be
removeCollection: (name) ->
collection = @collection(name)
fs.unlinkSync(collection._cpath)
I am sending you an email with the grammar corrections.
Is there a way to use the .where
where one can find all items with an array having a specific value?
lets say for
collection.insert([
{name: "sphinx", mythology: "greek", eyes: 2, sex: "f", hobbies: ["riddles","sitting","being a wonder"]},
{name: "hydra", mythology: "greek", eyes: 18, sex: "m", hobbies: ["coiling","terrorizing","growing"]},
{name: "huldra", mythology: "norse", eyes: 2, sex: "f", hobbies: ["luring","terrorizing"]},
{name: "cyclops", mythology: "greek", eyes: 1, sex: "m", hobbies: ["staring","terrorizing"]},
{name: "fenrir", mythology: "norse", eyes: 2, sex: "m", hobbies: ["growing","god-killing"]},
{name: "medusa", mythology: "greek", eyes: 2, sex: "f", hobbies: ["coiling","staring"]}
]);
I am looking for all monsters with terrorizing
as a hobbie
One could
var a = [];
collection.items.map(function(val){
if(val.hobbies && val.hobbies.indexOf("terrorizing")>-1){
a.push(val);
}
})
them, but wondering if there is a .where
syntax for it.
Going through the source Code of collection.coffee
, I noticed something odd in the remove
method when autosave = true
. Since I don't know CS, I checked the compiled source and confirmed my suspicion:
save
is called in every loop iterationSo this should probably read like:
remove: (cid) ->
for element, i in @items
if element.cid is cid
@items.remove i
@save() if @autosave
return true
return false
Please throw exception when insert with an existing _id. This could keep the _id unique.
Is there a backup somewhere for the site data? I want to see the docs.
Current upsert method contains the following code:
if (check.length > 0) {
.. do update...
}
else {
.. do insert...
}
But 'check' variable is an object, not an array, contained 'items' property within self with length property.
May be there are cases when that statement isn't true, but currently 'upsert' is broken.
Above the large code example, it should read:
An example that explains everything.
...I thought we fixed that already.
Stupid question, but … Are the operations/methods sync or async?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.