Skip to content

Latest commit

 

History

History
88 lines (62 loc) · 1.59 KB

OVERVIEW.md

File metadata and controls

88 lines (62 loc) · 1.59 KB

LokiJS

LokiJS.org web site | LokiJS GitHub page | Sandbox / Playground

Documentation Overview

This is an early effort to provide a more accurate and up-to-date version of LokiJS documentation by using jsdoc. Since modifications arise from various contributors, this should allow distributed effort toward maintaining this documentation.

Getting Started

Creating a database :

var db = new loki('example.db');

Add a collection :

var users = db.addCollection('users');

Insert documents :

users.insert({
	name: 'Odin',
	age: 50,
	address: 'Asgard'
});

// alternatively, insert array of documents
users.insert([{ name: 'Thor', age: 35}, { name: 'Loki', age: 30}]);

Simple find query :

var results = users.find({ age: {'$gte': 35} });

var odin = users.findOne({ name:'Odin' });

Simple where query :

var results = users.where(function(obj) {
	return (obj.age >= 35);
});

Simple Chaining :

var results = users.chain().find({ age: {'$gte': 35} }).simplesort('name').data();

Simple named transform :

users.addTransform('progeny', [
  {
    type: 'find',
    value: {
      'age': {'$lte': 40}
    }
  }
]);

var results = users.chain('progeny').data();

Simple Dynamic View :

var pview = users.addDynamicView('progeny');

pview.applyFind({
	'age': {'$lte': 40}
});

pview.applySimpleSort('name');

var results = pview.data();