Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

lokijs

techfort2mMIT1.5.12TypeScript support: definitely-typed

Fast document oriented javascript in-memory database

javascript, document-oriented, mmdb, json, nosql, lokijs, in-memory, indexeddb

readme

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 joe.minichino@gmail.com

Commercial Support

For commercial support contact info.techfort@gmail.com

License

Copyright (c) 2015 TechFort joe.minichino@gmail.com

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.

changelog

Changelog

  • add IncrementalIndexedDBAdapter
  • make ensureIndex faster
  • LokiEventEmitter.emit faster
  • make batch inserts faster (add option to overrideAdaptiveIndices)

1.5.6

  • added support for indexes on nested properties (#718)
  • more robust environment detection (#717)
  • precompile $regex filters recursively (#710)
  • Corrected $aeq example in Query Examples (#706)
  • change 'shallow-recurse-objects' clone to support deep array clone (#692)
  • jsdoc fixes for compoundsort example (#691)

1.5.5

  • fixed issue where batch removes did not update unique index (#677)

1.5.4

  • fixes to checkIndex maintenance fn (#654, #661)
  • bulk remove optimizations (#663)
  • fix to meta when cloning (#666)
  • AWS S3 sync adapter added (#670)
  • fix for browser project: fs not found (#674)
  • added comparators to default export (#672)

1.5.3

  • simplesort can leverage binary index (via index intersect) when weakly filtered (#645)
  • the simplesort 'descending' param is now multipurposed (with bw-compat) see jsdocs
  • added new simplified js comparison ops for unindexed optimizations (commit bb011d)
  • added collection.checkIndex() and collection.checkIndexes() for diagnostics (#654,#47)

1.5.2

  • fixed error when transform steps have non-serializable parameters (#624)
  • addCollection will return existing collection when collection named already exists (#635)
  • batch updates when not cloning no longer risk invalidating adaptive binary indices (#639)
  • fixed autosave race condition when using async adapter (#643)
  • collection option added to disableMeta if not using changes api or ttl (#644)

1.5.1

  • added disableDeltaChangesApi (default:true) collection option to store only differences. (#582)
  • loki indexed adapter deleteDatabase method will now wait until complete before callback (#584)
  • fixed clone methods correctly assigning object prototypes (#586)
  • partitioning adapter and memory adapter no longer throw error when database doesn't exist (yet)
  • simplesort and compoundsort now support sorting on nested properties via dot-notation (#574)
  • added support for binary indices on nested properties (#574)
  • fixed jsdoc syntax error causing vscode to crash (#614)
  • fixed error when using partitioning adapter with nativescript adapter (#615)
  • added optional 'dataOptions' to eqJoin and map (chain/transform) (see #618)

1.5.0

  • refactored binary indices sorting order
  • date values in properties with binary index will be converted to epoch time
  • fix to LokiFsStructuredAdapter first time autoload error where file doesn't exist yet
  • fixed simplesort descending with binary indices and no filters
  • with 'clone' option collection 'insert' events no longer emit internal obj reference
  • fix to clone method 'shallow'
  • added 'removeMeta' option to chained data calls to shallow clone and remove $loki and meta
  • added quickstart examples for node and updated loki sandbox with online web quickstarts
  • fixes to async unit tests
  • npm release trimmed from 5 megs to 500k (no examples, jsdocs, tests)

1.4.3

  • added throttled saves and loads (enabled by default) to ensure no overlapping calls
  • unfiltered simplesorts can leverage binary index
  • collection.clear now clears indices correctly
  • fix to LokiPartitioning adapter resetting maxId across saves
  • meta set correctly on batch inserts
  • LokiMemoryAdapter now configurable to simulate async
  • fix changesApi not enabled after loading database

1.4.2

  • added 'adaptiveBinaryIndices' option to collections (default true) to avoid rebuilds on inserts/updates/removes
  • added higher performance LokiFsStructuredAdapter for node
  • added destructured serialization methods for partitioning and exporting
  • added 'addListener' method alias of 'on' method
  • LokiFsAdapter doesn't throw exception when file doesn't exist (yet)
  • fix for circular structure error when setting ttl
  • fix unit testing on windows
  • experimental implementation of an incremental adapter

1.4.1

  • minor fixes
  • updated jsdoc coverage

1.4.0

  • fixes to loki indexed adapter
  • added nativescript adapter
  • added $aeq, $contains, $containsAny, $ne
  • fix unique index update with new object
  • expose persistence adapters to module export
  • fix to loki-crypted-file-adapter

1.3.0

  • UniqueIndex and by() method
  • staging API
  • count() utility method
  • RethinkDB-style joins (eqJoin)
  • moved testing to Karma
  • moved builds and run to npm instead of gulp
  • added $containsAny operator
  • statistical functions: average, max, maxRecord, min, minRecord, median, mode
  • extract() to extract a flat array of values for one field in each record
  • extractNumerical() - same as extract() for numerical values
  • pre-insert and pre-update events