Giter Club home page Giter Club logo

lokijs's Introduction

LokiJS

The super fast in-memory javascript document oriented database.

Enable offline-syncing to your SQL/NoSQL database servers with SyncProxy !! Code-free real time syncing, ideal for mobile, electron and web apps.

Join the chat at https://gitter.im/techfort/LokiJS alt CI-badge npm version alt packagequality

Overview

LokiJS is a document oriented database written in javascript, published under MIT License. Its purpose is to store javascript objects as documents in a nosql fashion and retrieve them with a similar mechanism. Runs in node (including cordova/phonegap and node-webkit), nativescript and the browser. LokiJS is ideal for the following scenarios:

  1. client-side in-memory db is ideal (e.g., a session store)
  2. performance critical applications
  3. cordova/phonegap mobile apps where you can leverage the power of javascript and avoid interacting with native databases
  4. data sets loaded into a browser page and synchronised at the end of the work session
  5. node-webkit desktop apps
  6. nativescript mobile apps that mix the power and ubiquity of javascript with native performance and ui

LokiJS supports indexing and views and achieves high-performance through maintaining unique and binary indexes (indices) for data.

Demo

The following demos are available:

  • Sandbox / Playground
  • a node-webkit small demo in the folder demos/desktop_app. You can launch it by running /path/to/nw demos/desktop_app/

Wiki

Example usage can be found on the wiki

Main Features

  1. Fast performance NoSQL in-memory database, collections with unique index (1.1M ops/s) and binary-index (500k ops/s)
  2. Runs in multiple environments (browser, node, nativescript)
  3. Dynamic Views for fast access of data subsets
  4. Built-in persistence adapters, and the ability to support user-defined ones
  5. Changes API
  6. Joins

Current state

LokiJS is at version 1.3 [Eostre].

As LokiJS is written in JavaScript it can be run on any environment supporting JavaScript such as browsers, node.js/node-webkit, nativescript mobile framework and hybrid mobile apps (such as phonegap/cordova).

Made by @techfort, with the precious help of Dave Easterday.

Leave a tip or give us a star if you find LokiJS useful!

Installation

For browser environments you simply need the lokijs.js file contained in src/

You can use bower to install lokijs with bower install lokijs

For node and nativescript environments you can install through npm install lokijs.

Roadmap

  • exactIndex
  • key-value datastore
  • MRU cache
  • MongoDB API compatibility
  • server standalone (tcp and http servers and clients)
  • replication and horizontal scaling

Contact

For help / enquiries contact [email protected]

Commercial Support

For commercial support contact [email protected]

License

Copyright (c) 2015 TechFort [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

lokijs's People

Contributors

alex-werner avatar alexandernst avatar alinanova21 avatar areksredzki avatar assafweinberg avatar bnadim avatar christophertaplogic avatar cortys avatar goatslacker avatar guewen avatar ichursin avatar johnmunsch avatar jonathanz avatar kavaro avatar kberryman avatar lagden avatar moocar avatar moshewe avatar mromanbcn avatar obeliskos avatar plepe avatar radex avatar redsandro avatar stefalda avatar stefanprobst avatar techfort avatar thrilleratplay avatar viatorus avatar vladimirtechman avatar xbenjii avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lokijs's Issues

Init erro by node-webkit context

use node-webkit.

var db = new loki();

will throw error

Uncaught node.js Error 

ReferenceError: document is not defined
    at Loki.getENV (D:\workspace\radium\canvas\node_modules\lokijs\src\lokijs.js:228:15)
    at LokiEventEmitter.Loki (D:\workspace\radium\canvas\node_modules\lokijs\src\lokijs.js:237:18)

change source code in file lokijs.js:224 like this will be ok

   if (typeof exports === 'object' || typeof window === 'undefined') {

getCollection return value

Right now, the behavior for getCollection is to throw an error if the collection requested isn't present. I think it might be more convenient to return null if the collection isn't found. Then a user can test the value and initialize the collection if necessary. e.g.

var col = db.getCollection('test');
if(!col)
  col = db.addCollection('test')

Right now, there's no great way to know if a collection already exists before trying to get it.

Collection.prototype.get('1') fails

If one accidentally tries to get using string id it does not throw but fails to find the document. This is due to isNaN returning false for string id so it is not cast to number, but later strict equality === causes id not to be found.

update() increments the collection count when fetching on an index

I found this particular strange bug. If you're using an index, when you update an item that already exists in the collection it appends a new item to the collection. This bug only occurs though if you're fetching on the index itself.

Here's a very basic minimal example:

ฮป node
> var loki = require('lokijs')
undefined
> var db = new loki('db.json')
undefined
>
undefined
> test = db.addCollection('test', ['index'])
{ name: 'test',
  data: [],
  idIndex: [],
  binaryIndices: { index: { name: 'index', dirty: false, values: [] } },
  objType: 'test',
  transactional: false,
  cachedIndex: null,
  cachedBinaryIndex: null,
  cachedData: null,
  maxId: 0,
  DynamicViews: [],
  events:
    { insert: [ [Function] ],
      update: [ [Function] ],
      close: [],
      flushbuffer: [],
      error: [],
      delete: [] } }
> item = test.insert({ index: 'key', a: 1 })
{ index: 'key',
  a: 1,
  objType: 'test',
  meta: { version: 0 },
  id: 1 }
 > test.find({ index: 'key' }).length
1
> item.a = 2
2
> test.update(item)
undefined
> test.find({ index: 'key' }).length
2

I'm expecting the length to be 1. If you inspect the collection returned it'll contain an item where a = 1 and another item where a = 2

Can't load empty JSON file.

I'm using the following code in node-webkit/angular:

app.service('Database', [
    function() {
        return function(dbName) {

            var self = this;

            this.initialized = false;
            this.db = new loki(dbName + '.json', {
                env: 'NODEJS',
                autoload: true
            });
            this.models = {};

            this.init = function(collections, callback) {
                if (fs.existsSync(dbName + '.json')) {
                    this.db.loadDatabase({}, function() {
                        initDb();
                    });
                } else {
                    initDb();
                }

                function initDb() {
                    collections.forEach(function(collection) {
                        self.db.addCollection(collection);
                        self.models[collection] = self.db.getCollection(collection);
                    });
                    self.initialized = true;
                    callback();
                }
            };

            this.save = function(callback) {
                self.db.saveDatabase(callback);
            };

            return this;
        };
    }
]);

This worked in 1.0, bar the API changes I've made for 1.1. It would load an empty database which would then allow it to save if it hadn't been created, now it just throws an error because it's trying to parse JSON that doesn't exist.

SyntaxError: Unexpected end of input
    at Object.parse (native)
    at LokiEventEmitter.Loki.loadJSON (C:\njs\arch\node_modules\lokijs\src\lokijs.js:396:22)
    at readFileCallback (C:\njs\arch\node_modules\lokijs\src\lokijs.js:677:16)
    at fs.js:289:14
    at Object.oncomplete (fs.js:97:15)

Edit: Your desktop_app demo throws the same error. Also if there's no file present, it throws an ENOENT error. Instead, it should probably create the file and initialize a database.

For-looping collection.remove(obj) weird behavior

Whenever I use a for-loop to remove objects from a collection, loki skips every other reference and ends up deleting only half of the objects in the result array.

Although when I reverse the loop, it works as expected.
Using Node-webkit and lokijs 1.1.14

        var loki = require("lokijs")
        var db = new loki("test3");

        var folders = db.addCollection("folders");

        folders.insert({name : "data", type: "system"});
        folders.insert({name : "images", type: "user"});
        folders.insert({name : "datacache", type: "system"});
        folders.insert({name : "imagecache", type: "system"});
        folders.insert({name : "sample", type: "user"});
        folders.insert({name : "documents", type: "user"});
        folders.insert({name : "feeds", type: "user"});
        folders.insert({name : "site", type: "user"});

        db.saveDatabase();
        console.log(folders);


        // Load the database

        db2 = new loki("test3");
        db2.loadDatabase({}, function(){

            var folders = db2.getCollection("folders");
            console.log(folders);
            var list = folders.find();

            for(var i = 0; i < list.length; i++) {
                console.log(i);
                console.log(list[i]);

                folders.remove(list[i]);
            }


            // Reverse loop works fine though

            /*for(var z = list.length -1; z >= 0; z--) {
                console.log(z);
                console.log(list[z]);

                folders.remove(list[z]);
            }*/


        });

Unnecessary dependencies?

Gordian, Istanbul and Mocha are already listed in devDependencies, so they could be removed from ordinary dependencies? Now those dependencies bring in 10MB extra to ordinary install...

Implement key-value store

Already developed in experimental branch, remains to be decided how key-value stores will relate to the db as opposed to collections.

Error calculating collection maxId when adding to empty collection

This code from Collection.add:

if (isNaN(this.maxId)) {
    this.maxId = (this.data[this.data.length - 1].id + 1);
}

Does not work if the collection is empty and leads to this error: Cannot read property 'id' of undefined

How to reproduce:

  • Load a database with a non-empty collection. The collections maxId is initialized with undefined: copyColl.maxId = (coll.data.length === 0) ? 0 : coll.data.maxId; (from loadJSON)
  • Remove all entries from the collection
  • Add an entry to the collection

I'm guessing the error is in the loadJSON method line above, since coll.data.maxId is never set. Plus the code in Collection.add basically assumes that some other code did set the maxId to 0 if the collection is empty.

Emit events on DynamicViews on changes

It would be great if DynamicViews would also emit change events, but only if changes to the underlying collection are actually affecting the DynamicView.

Suppose I have a DynamicView whose data I'm feeding to an HTML template. It would be good if I could re-render my HTML template only if the DynamicView actually changes, instead of listening to every change event on the underlying collection. This would help avoid unnecessary template rendering.

Btw great work with LokiJS! I like that it's so small and easy to grasp compared to the other alternatives out there.

Collection option defaults vs. docs

Docs say that collection asyncListeners defaults to false, but in code it defaults to true (even though comment there says otherwise). I was wondering why inserting a new doc results in its meta.created being 0 if inspected in the same control flow right after insert, this explains why.

Also collection option disableChangesApi defaults to true in code, which is a good default I guess, but is said to default to false in docs.

use just one test framework

I found some new commit also use gordian instead of mocha, we should use just on test framework, and add more base unit test.

mocha is more popular, isn't it ?

Four easy steps to greatly improve LokiJS.

Hello All!
First of all sorry for the presumptuous title. I do not know much about the internals of lokiJS to state how easy it is to introduce the simple changes I'm thinking about. LokiJS seems very promising and prompted me to think of stuff that would improve it -in my mind-. I very well might have had things wrong, but the easiest and best for everyone is to write down my thoughts and await your feedback.

Please find the time to go through this post to see what I'm getting at.

1- localStorage that's being used as storage engine is already an 'in memory database'. Hence its synchronous nature. Users do not have access to when the actual flush to disk' happens. One option is to avoid loading all data into memory -it's already in memory- and saving it back at the end. Rather one would work on localStorage entities directly (actually through a wrapper/interface, more on that later).This means that if your 'MyApp' database has two tables/entities Todo_Items and Activity_Type the localStorage would have two key-value entries: Todo_Items and Activity_Type instead of a single entry/file: MyApp. This would also mean some extra work to allow porting data around (it's no longer a single JSOn-file that maps to a single key-value entry)

2- One could instead of using localStorage by default feed the storage engine to lokiJS (there'a a simple interface to implement). Better yet, one could have different storage engines for different entities. Since every entity has its own key-value entry. Some entities can live in sessionStorage, others in localStorage or in memory (real in memory storage that would be re-read from the server on page refresh).

3- Going further, one can use something like localForage to also have the option of using indexedDB/WebSQL as storage engine. Many valid use cases would require more than 5 Mega of storage and also need to use different storage engines at once -for instance using sessionStorage to save sensitive data such as authentication tokens etc...-. Note that introducing localForage would also require us to change the interface to become asynchronous. For localStorage's implementation that would simply mean the promise/callback will be immediately invoked/resolved.

4- On the server side Loki should be very easy to port as one could use levelDB as storage engine. One should simply need to implement the 'interface' with levelDB. One important advantage of levelDB is that it'll be used by the same process as the nodejs instance (I assume you want to use nodejs). This eases scalling and deployment ...etc

I hope that made sense.
Cheers~.

Documentation Issue: No automatic persistence in node.js

Hello,

The project README mentions: "In a nodejs/node-webkit environment LokiJS also persists to disk whenever an insert, update or remove is performed.".

Is this accurate? I tried to look for this functionality in the source and it doesn't seem to be there - nor could I reproduce it with code. It looks like we have to explicitly call db.save() when we want an on-disk checkpoint created.

Am I missing something? If not, might be worth correcting.

saveToDisk unlink issue

Because fs.unlink is asynchronous, sometimes the filesystem will attempt to write to a file currently being deleted (just how it looks like to me, I'm no expert) and that results in no file at all (win 8).

fs.writeFile should be called either from fs.unlink's callback, or use fs.unlinkSync.

Document which MongoDB compatible queries

Given the interest in lokijs' MongoDB compatibility it seems odd that there is no mention in the documentation as to what exactly is supported in terms of queries/methods.

Is there a one place where I can find all the currently supported queries?

"Data is undefined" thrown when using loadDatabase in browser

To verify that this was an issue, I made a simple index.html file w/ the following code (taken from the docs)

    var db = new loki('test', { env: 'BROWSER'}),
            db2 = new loki('test', { env: 'BROWSER'});

    var users = db.addCollection('users');
    users.insert({
        name: 'joe'
    });
    users.insert({
        name: 'john'
    });
    users.insert({
        name: 'jack'
    });
    console.log(users.data);
    db.saveDatabase();

    db2.loadDatabase(function () {
        var users2 = db2.getCollection('users')
        console.log(users2.data);
    });

loadDatabase breaks in the following code snippet (which exists in two areas):

        if (localStorageAvailable()) {
          self.loadJSON(localStorage.getItem(this.filename));
          cFun(null, data);
        } else {
          cFun(new Error('localStorage is not available'));
        }

Data is undefined and an error is thrown. I've verified that removing data from the callback resolves the issue.

the object is modified after inserted

I find some design problem, it will make people confused.

After I insert a object into collection, the origin object is modified, just like:

var john = {name: 'John'};
users.insert(john);
console.log(john);  //{ name: 'John', objType: 'user', meta: { version: 0 }, id: 1 }
  1. The insert() should clone a new object to insert.
  2. An array should also be inserted, instead of inserting every item.
  3. pass id to remove() instead of passing the whole obj
  4. I think using some api like mongoose is better for update and remove :
var john = users.find({name:'John'});
john.age = 20;
console.log(john);  //{ name: 'John', age: 20, objType: 'user', meta: { version: 0 }, id: 1 }
john.save();
john.remove();
  1. the obj save in db should distinguish the origin properties from Loki properties, the data may be better looks like:
{ data: {
    name: 'John',
    age: 20
  }, 
  objType: 'user', 
  meta: { version: 0 }, 
  id: 1 
} 

How about these 5 points ? I find it's complex for fix old unit test, so if modify these problems, I will make some new tests.

DynamicView

Could you tell me more about this, will it be a public function?
Want much about collections in docs

Is it like a set with id's only?
That you could filter without looking the original set?

In wakanda(wakanda.org, nosql) every set gets a unique entityset when u do a query.
This way you could just pass the unique ID to a method from client side to server side if you wanted to do work with on server side, this way you relaly dont need to pass a entire collection

DISCUSSION: My experience with LokiJS, especially with LokiJS ids and synchronous methods

Use Case

I work on a project involving the MEAN stack (without A). This project is divided into RESTful API server(s) and Web UI Server(s). We needed a way to mock data access and instead of using SinonJS to mock $.ajax requests we have deemed simpler to mock data access with a second set of observable models getting data and setting data to an in-memory database.

Reasons for choosing LokiJS

We have quickly evaluated PouchDB, TaffyDB, Lawnchair, DB.js, jQuery.IndexedDB.js, minimongo, etc. Just from reading the documentation we felt that having an in-memory database that would match mongoDB apis would make things simpler and since minimongo requires Browserify, we tunred to LockiJS.

On the long run, we need a database to store JSON documents in a Cordova app that we want to synchronize with our RESTful server backed by MongoDB, and this QA/test mockup exercise seemed like a good way to evaluate LokiJS.

Disappointments with LokiJS

Basically, everything that is good and appealing in LokiJS pertains to its resemblance with MongoDB. The bad comes from the differences.

The main issue with LokiJS is ids. IMHO, renaming an id of type string (actually a MongoDB ObjectId converted to a string) into originalId to have an id of type number is a terrible option that leads to all sorts of headaches either in our mockup scenario and most certainly in synchronization scenarios. In other words, do not change ids. As we have documents that reference documents in other collections, we could only use find({originalId: 'xxxxxxxxxxxxxxxxxxxxxxxx'}), and since we have never been able to use get, I doubt there is any performance benefit (unless LokiJS is used in scenarios that do not involve MongoDB, but then why all the fuss about matching its API?).

The second important issue is synchronicity. We heavily use callbacks in our server code and promises in our browser/cordova code. Using a deferred and setTimeout to wrap all synchronous code is tedious. In the long run, LokiJS should think about a plugin architecture for persistence to WebSQL, IndexedDB, localStorage and use callbacks/promises for all data access functions.

Opportunity

There is a real opportunity for LokiJS. IMHO, this is to become the PouchDB of MongoDB, not another light database that resembles more or less MongoDB and that requires all sorts of workarounds to make it store and find MongoDB documents.

Although there might be an opportunity for LokiJS to be competitive as a nodeJS database that I do not grasp, I recommend considering focusing on browser and cordova scenarios (including synchronization) where there is a definitive gap/need. At least, we have this need.

This is just one user's feedback that might trigger some thoughts. I hope this helps.

Clearing collection breaks index

I noticed that after clearing a collection I wasn't able to insert new objects without error. It seems that the clear collection code sets the idIndex to an object instead of an array which prevents insertion. The constructor does the same thing, but then also calls ensureIndex, which sets idIndex to an array.

Is this behavior intended for some reason?

Querying empty collection with binary index throws error

If a collection has a binary index set, and the collection is empty, querying it will result in an error. The error happens in the calculateRange function on the following lines:

var minVal = rcd[index[min]][prop];
var maxVal = rcd[index[max]][prop];

If the collection is empty, then rcd[index[min/max]] will be undefined. We may want to set default min and max values here, but also, maybe shortcut the find() function to return an empty result set if the data is empty to save some work.

Changes/Stream API

Do you plan to add a changes event feature like the CouchDB change API ?

Deserialization with Prototypes

Implement re-hydration of serialized data that enables to instantiate a particular prototype per object so methods are made available subsequently to a loadDatabase() operation.

Some small documentation discrepancies

  • Collection.insert()
    • Documentation and example is talking about the document(obj) function, which seems to have been renamed to insert(obj). At first I didn't realise that and I was wondering why I couldn't call the document function so I looked at the source and the comment here is rather confusing, especially the last line :-)
  • Loki.loadDatabase()
    • Documentation is missing the inflate option (btw "inflate" is a rather confusing word in this context, "loader" like in the source seems clearer imho)

Implement transactions

Implement some form of transaction that caches the collection's state and rolls back to it if something fails during the operation.

Numeric values

If i insert a float value with 4.51 and read the dataset after that from loki i get a value of 2.41 for this field. I have no idea why .... If i store it as string everything is fine...

db save circular structure issue

Currently I have a problem in the area of loading/saving database. After object update and try to save db the following error occurs:

stream.js:94
      throw er; // Unhandled stream error in pipe.
            ^
TypeError: Converting circular structure to JSON
    at Object.stringify (native)
    at LokiEventEmitter.Loki.serialize (/home/teef/leonardo/WebApplications/Leonardo-CommHub/node_modules/lokijs/src/lokijs.js:385:19)
    at LokiEventEmitter.Loki.saveDatabase (/home/teef/leonardo/WebApplications/Leonardo-CommHub/node_modules/lokijs/src/lokijs.js:744:47)

I am using one collection as well as one dynamic view.

Seems like there are two dynamic views which should not happen.

DynamicViews: 
   [ { collection: [Circular],
       name: 'aciveDevices',
       persistent: false,
       resultset: [Object],
       resultdata: [],
       resultsdirty: true,
       cachedresultset: null,
       filterPipeline: [],
       sortFunction: null,
       sortCriteria: null,
       sortDirty: false,
       events: [Object] },
     { collection: [Circular],
       name: 'aciveDevices',
       persistent: false,
       resultset: [Object],
       resultdata: [],
       resultsdirty: false,
       cachedresultset: null,
       filterPipeline: [Object],
       sortFunction: null,
       sortCriteria: null,
       sortDirty: false,
       events: [Object] } ],

Database: https://gist.github.com/teef/c3f8f2139a1e13188e09

Eliminate clash of id

Either rename our id something like lokiID or make the id field configurable through options object in the Collection constructor.

findOne, is this working, or under construction?

if I do this:

var loki = require('storage/lokijs')
var db = new loki('Example');
var users = db.addCollection('users','User', undefined, undefined, undefined);
users.insert(x);
var xt = [];
for(var i = 0; i < 100; i++){
    xt.push({ name : 'odin', email: '[email protected]', age: i });
}
users.insert(xt);
users.findOne({age:1});

I get this back... ( I would have expected the one with age 1

name:
"odin"
email:
"[email protected]"
age:
99
id:
500100
objType:
"User"

browserify support

Using browserify I'm getting this error message:

 Uncaught TypeError: undefined is not a functionlokijs.js:738 

It's not properly detecting ENV when commonjs modules are used in the browser. Easy fix would be to change line 226:

81:     var fs = (typeof exports === 'object') ? require('fs') : false;

226:      if (fs) {
227:        return 'NODEJS';
228:      }
226:      if (typeof window === 'undefined') {
227:        return 'NODEJS';
228:      }

Also need to configure browserify to ignoring the 'fs' module. I can submit a pull request for line 226.

Idea: Expose the Collection class

I'd like to be able to subclass Collection into a class that I'm building without getting any of the dynamicview, loadDatabase, or other loki things. The reason for this is because I want:

  • Loki's indexing.
  • Something small (code-wise).
  • Mongodb like query methods.

Pseudo:

class Foo extends LokiCollection {
  constructor() {
    this.name = 'foo'
    this.indices = ['bar']
  }

  getSomeBars(n = 4) {
    return this.where({ bar: n })
  }
}

var foo = new Foo()
foo.insert({ bar: 4, baz: 'awesome' })
foo.insert({ bar: 3 })

foo.getSomeBars() == [{ bar: 4, baz: 'awesome' }]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.