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