UNPKG

1.63 kBMarkdownView Raw
1# LokiJS
2
3[LokiJS.org web site](http://lokijs.org) |
4[LokiJS GitHub page](https://github.com/techfort/LokiJS) |
5[Sandbox / Playground](https://rawgit.com/techfort/LokiJS/master/examples/sandbox/LokiSandbox.htm)
6
7## Documentation Overview
8
9This 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
10maintaining this documentation.
11
12## Getting Started
13
14Creating a database :
15
16```javascript
17var db = new loki('example.db');
18```
19
20Add a collection :
21
22```javascript
23var users = db.addCollection('users');
24```
25
26Insert documents :
27
28```javascript
29users.insert({
30 name: 'Odin',
31 age: 50,
32 address: 'Asgard'
33});
34
35// alternatively, insert array of documents
36users.insert([{ name: 'Thor', age: 35}, { name: 'Loki', age: 30}]);
37```
38
39Simple find query :
40
41```javascript
42var results = users.find({ age: {'$gte': 35} });
43
44var odin = users.findOne({ name:'Odin' });
45```
46
47Simple where query :
48
49```javascript
50var results = users.where(function(obj) {
51 return (obj.age >= 35);
52});
53```
54
55Simple Chaining :
56
57```javascript
58var results = users.chain().find({ age: {'$gte': 35} }).simplesort('name').data();
59```
60
61Simple named transform :
62
63```javascript
64users.addTransform('progeny', [
65 {
66 type: 'find',
67 value: {
68 'age': {'$lte': 40}
69 }
70 }
71]);
72
73var results = users.chain('progeny').data();
74```
75
76Simple Dynamic View :
77
78```javascript
79var pview = users.addDynamicView('progeny');
80
81pview.applyFind({
82 'age': {'$lte': 40}
83});
84
85pview.applySimpleSort('name');
86
87var results = pview.data();
88```
\No newline at end of file