SlideShare a Scribd company logo
1 of 16
LokiJS
Javascript In-Memory Database
@tech_fort
??? WHAT ???
WHY?
● In-memory is faster than I/O
● SQLite is great but there is no NoSQL / document-oriented equivalent of it
● SQLite is cumbersome in a mobile / embedded context (who can be bothered
with SQL in a mobile app?)
● Phonegap and Node-Webkit apps would benefit from a javascript database where
data is plain javascript objects, and persisted on disk as JSON.
● Traditional databases rely on platform libraries which impose portability contraints
and version conflicts. Data is frequently 'locked-in'
● For many applications NoSql is a far more preferable and better performing
approach than relational data when working with complex object stores which are
built for consumption.
Enter Loki
●
LokiJS is compatible with browser and node.js
●
Persistence to disk on inserts/updates/deletes (in node.js, node-webkit and cordova
environments)
●
Available on bower and npm
●
Extremely low footprint - 28KB uncompressed!!
●
Supports indexing, and uses Binary Search for search granting fast performance
●
NoSQL jargon: documents, collections, map, reduce
●
Compatibility: dependency free, native, pure javascript runs across many js environments
●
Portablility : entire database state can be serialized as a single entity to be restored in an
identical state or transferred across environments as a single JSON entity.
●
Performs better than similar products (NeDB, TaffyDB, PouchDB etc.), and it's much smaller
Sample Usage
var loki = require('lokijs'),
  db = new loki('demo.json'),
  doctors;
doctors = db.addCollection('doctors', { indices: 
['name']});
doctors.insert({ name: 'David Tennant', doctor: 
10});
doctors.insert({ name: 'Matt Smith', doctor: 11});
doctors.insert({ name: 'Peter Capaldi', doctor: 
12});
Updates
● Updates are optional. LokiJS holds references
to objects so there's no need to update an
object. However, update(obj) can be called to
force re-indexing of collections.
Querying
● Querying is quite intuitive:
doctors.get(index);
doctors.find({ doctors: 10}); 
doctors.find({ doctors: { '$gte' : 
9}});
Querying (Mongo Style)
Mongo style queries will benefit from access to
index optimizations.
● Declarative query definition via a query object
● Current supported operators include $eq, $gt,
$gte, $lt, $lte, $ne, $regex, $in, $contains
● Supports dot notation for deep querying
Querying (Javascript views)
● Means of specifying complex 'edge case' query filters
● Write your own javascript filter function which can be
anonymous or persisted with a name as a view.
● Has access to the entire (possibly hierarchical) document
object
● Used for chained queries and dynamic views
● Worse performance / cant be serialized (need to be
reattach to dynview on load)
Fluent API
You can resort to functions to obtain your data by
leveraging the built-in ResultSet class:
doctors.chain()
  .find({ doctor: { '$gte': 9 }})
  .where(function (obj) { return 
obj.name.indexOf(“t”) != ­1; })
  .simplesort(“name”)
  .data(); // this exposes the data
Dynamic Views
Views hold references to filtered data to optmize search even further
(avoiding to scan the entire collection).
Thet maintain freshness of query results optimally as they are notified of
data inserts, updates and deletes.
var view = doctors.addDynamicView(“latestDoctors”);
view.applyFind({ doctor: { '$gte': 8}});
view.applySort(function (a, b) {
  return a.doctor < b.doctor;
});
// inspect the data
console.log(view.data());
Persistence
● Loki now supports three primary persistence methods : filesystem
(Node), localStorage (cordova/browser), and indexedDB
(cordova/browser)
● A new persistence adapter interface allows for interoperability with
other popular and/or custom data stores. Community members can
develop and submit adapters for popular datastores and submit a pull
request to share them.
● Autosave/Autoload capabilities exist for you to optionally utilize for
automating and bootstrapping persistence.
IndexedDB Support for browsers
● Loki now implements an indexedDB App/Key/Value Catalog,
implemented using the new persistence adapter interface.
● This catalog can contain as many databases as your storage
quota allows, organized by application. This allows grouping,
listing and querying the catalog of databases by 'application'
groups.
● Loki's indexedDB adapter supports console use for easily
managing your catalog from a browser console.
Summary
● Use collection operations (insert, update, delete)
for document-oriented maintenance
● Use collection operations (find, where) for optimal
query performance
● Use resultset with fluent-like syntax for defining
complex query-oriented pipelines
● Use dynamic view for defining views which inherit
the resultset pipeline, yet avoid needing to requery
RoadMap
● MRU cache / Key-value store option
● TCP and HTTP Wrappers to enable running
LokiJS on dedicated (virtual) machines
● Replication
● Horizontal scaling
● MongoDB API subset compatibility
Links:
Web: http://lokijs.org
Github: https://github.com/techfort/LokiJS
Contributors:
Joe Minichino
Dave Easterday
@tech_fort

More Related Content

Similar to Lokijs

Elasticsearch vs MongoDB comparison
Elasticsearch vs MongoDB comparisonElasticsearch vs MongoDB comparison
Elasticsearch vs MongoDB comparisonjeetendra mandal
 
Couchbase - Introduction
Couchbase - IntroductionCouchbase - Introduction
Couchbase - IntroductionKnoldus Inc.
 
ArangoDB – A different approach to NoSQL
ArangoDB – A different approach to NoSQLArangoDB – A different approach to NoSQL
ArangoDB – A different approach to NoSQLArangoDB Database
 
Analysis on NoSQL: MongoDB Tool
Analysis on NoSQL: MongoDB ToolAnalysis on NoSQL: MongoDB Tool
Analysis on NoSQL: MongoDB Toolijtsrd
 
Mongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorialMongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorialMohan Rathour
 
NoSQL Endgame LWJUG 2021
NoSQL Endgame LWJUG 2021NoSQL Endgame LWJUG 2021
NoSQL Endgame LWJUG 2021Thodoris Bais
 
MongoDB Lab Manual (1).pdf used in data science
MongoDB Lab Manual (1).pdf used in data scienceMongoDB Lab Manual (1).pdf used in data science
MongoDB Lab Manual (1).pdf used in data sciencebitragowthamkumar1
 
Couchbase - Yet Another Introduction
Couchbase - Yet Another IntroductionCouchbase - Yet Another Introduction
Couchbase - Yet Another IntroductionKelum Senanayake
 
SQL vs MongoDB
SQL vs MongoDBSQL vs MongoDB
SQL vs MongoDBcalltutors
 
SQL vs NoSQL, an experiment with MongoDB
SQL vs NoSQL, an experiment with MongoDBSQL vs NoSQL, an experiment with MongoDB
SQL vs NoSQL, an experiment with MongoDBMarco Segato
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsWinston Hsieh
 
A Presentation on MongoDB Introduction - Habilelabs
A Presentation on MongoDB Introduction - HabilelabsA Presentation on MongoDB Introduction - Habilelabs
A Presentation on MongoDB Introduction - HabilelabsHabilelabs
 
Mongodb - NoSql Database
Mongodb - NoSql DatabaseMongodb - NoSql Database
Mongodb - NoSql DatabasePrashant Gupta
 
Azure DocumentDB 101
Azure DocumentDB 101Azure DocumentDB 101
Azure DocumentDB 101Ike Ellis
 

Similar to Lokijs (20)

Elasticsearch vs MongoDB comparison
Elasticsearch vs MongoDB comparisonElasticsearch vs MongoDB comparison
Elasticsearch vs MongoDB comparison
 
NoSql Databases
NoSql DatabasesNoSql Databases
NoSql Databases
 
Unit 3 MongDB
Unit 3 MongDBUnit 3 MongDB
Unit 3 MongDB
 
Couchbase - Introduction
Couchbase - IntroductionCouchbase - Introduction
Couchbase - Introduction
 
ArangoDB – A different approach to NoSQL
ArangoDB – A different approach to NoSQLArangoDB – A different approach to NoSQL
ArangoDB – A different approach to NoSQL
 
Analysis on NoSQL: MongoDB Tool
Analysis on NoSQL: MongoDB ToolAnalysis on NoSQL: MongoDB Tool
Analysis on NoSQL: MongoDB Tool
 
Mongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorialMongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorial
 
NoSQL Endgame LWJUG 2021
NoSQL Endgame LWJUG 2021NoSQL Endgame LWJUG 2021
NoSQL Endgame LWJUG 2021
 
MongoDB Lab Manual (1).pdf used in data science
MongoDB Lab Manual (1).pdf used in data scienceMongoDB Lab Manual (1).pdf used in data science
MongoDB Lab Manual (1).pdf used in data science
 
Couchbase - Yet Another Introduction
Couchbase - Yet Another IntroductionCouchbase - Yet Another Introduction
Couchbase - Yet Another Introduction
 
Jooq java object oriented querying
Jooq java object oriented queryingJooq java object oriented querying
Jooq java object oriented querying
 
SQL vs MongoDB
SQL vs MongoDBSQL vs MongoDB
SQL vs MongoDB
 
No sq lv1_0
No sq lv1_0No sq lv1_0
No sq lv1_0
 
Oslo bekk2014
Oslo bekk2014Oslo bekk2014
Oslo bekk2014
 
SQL vs NoSQL, an experiment with MongoDB
SQL vs NoSQL, an experiment with MongoDBSQL vs NoSQL, an experiment with MongoDB
SQL vs NoSQL, an experiment with MongoDB
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
A Presentation on MongoDB Introduction - Habilelabs
A Presentation on MongoDB Introduction - HabilelabsA Presentation on MongoDB Introduction - Habilelabs
A Presentation on MongoDB Introduction - Habilelabs
 
Mongodb - NoSql Database
Mongodb - NoSql DatabaseMongodb - NoSql Database
Mongodb - NoSql Database
 
Handy annotations-within-oracle-10g
Handy annotations-within-oracle-10gHandy annotations-within-oracle-10g
Handy annotations-within-oracle-10g
 
Azure DocumentDB 101
Azure DocumentDB 101Azure DocumentDB 101
Azure DocumentDB 101
 

Recently uploaded

Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 

Recently uploaded (20)

Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 

Lokijs

  • 3. WHY? ● In-memory is faster than I/O ● SQLite is great but there is no NoSQL / document-oriented equivalent of it ● SQLite is cumbersome in a mobile / embedded context (who can be bothered with SQL in a mobile app?) ● Phonegap and Node-Webkit apps would benefit from a javascript database where data is plain javascript objects, and persisted on disk as JSON. ● Traditional databases rely on platform libraries which impose portability contraints and version conflicts. Data is frequently 'locked-in' ● For many applications NoSql is a far more preferable and better performing approach than relational data when working with complex object stores which are built for consumption.
  • 4. Enter Loki ● LokiJS is compatible with browser and node.js ● Persistence to disk on inserts/updates/deletes (in node.js, node-webkit and cordova environments) ● Available on bower and npm ● Extremely low footprint - 28KB uncompressed!! ● Supports indexing, and uses Binary Search for search granting fast performance ● NoSQL jargon: documents, collections, map, reduce ● Compatibility: dependency free, native, pure javascript runs across many js environments ● Portablility : entire database state can be serialized as a single entity to be restored in an identical state or transferred across environments as a single JSON entity. ● Performs better than similar products (NeDB, TaffyDB, PouchDB etc.), and it's much smaller
  • 6. Updates ● Updates are optional. LokiJS holds references to objects so there's no need to update an object. However, update(obj) can be called to force re-indexing of collections.
  • 7. Querying ● Querying is quite intuitive: doctors.get(index); doctors.find({ doctors: 10});  doctors.find({ doctors: { '$gte' :  9}});
  • 8. Querying (Mongo Style) Mongo style queries will benefit from access to index optimizations. ● Declarative query definition via a query object ● Current supported operators include $eq, $gt, $gte, $lt, $lte, $ne, $regex, $in, $contains ● Supports dot notation for deep querying
  • 9. Querying (Javascript views) ● Means of specifying complex 'edge case' query filters ● Write your own javascript filter function which can be anonymous or persisted with a name as a view. ● Has access to the entire (possibly hierarchical) document object ● Used for chained queries and dynamic views ● Worse performance / cant be serialized (need to be reattach to dynview on load)
  • 10. Fluent API You can resort to functions to obtain your data by leveraging the built-in ResultSet class: doctors.chain()   .find({ doctor: { '$gte': 9 }})   .where(function (obj) { return  obj.name.indexOf(“t”) != ­1; })   .simplesort(“name”)   .data(); // this exposes the data
  • 11. Dynamic Views Views hold references to filtered data to optmize search even further (avoiding to scan the entire collection). Thet maintain freshness of query results optimally as they are notified of data inserts, updates and deletes. var view = doctors.addDynamicView(“latestDoctors”); view.applyFind({ doctor: { '$gte': 8}}); view.applySort(function (a, b) {   return a.doctor < b.doctor; }); // inspect the data console.log(view.data());
  • 12. Persistence ● Loki now supports three primary persistence methods : filesystem (Node), localStorage (cordova/browser), and indexedDB (cordova/browser) ● A new persistence adapter interface allows for interoperability with other popular and/or custom data stores. Community members can develop and submit adapters for popular datastores and submit a pull request to share them. ● Autosave/Autoload capabilities exist for you to optionally utilize for automating and bootstrapping persistence.
  • 13. IndexedDB Support for browsers ● Loki now implements an indexedDB App/Key/Value Catalog, implemented using the new persistence adapter interface. ● This catalog can contain as many databases as your storage quota allows, organized by application. This allows grouping, listing and querying the catalog of databases by 'application' groups. ● Loki's indexedDB adapter supports console use for easily managing your catalog from a browser console.
  • 14. Summary ● Use collection operations (insert, update, delete) for document-oriented maintenance ● Use collection operations (find, where) for optimal query performance ● Use resultset with fluent-like syntax for defining complex query-oriented pipelines ● Use dynamic view for defining views which inherit the resultset pipeline, yet avoid needing to requery
  • 15. RoadMap ● MRU cache / Key-value store option ● TCP and HTTP Wrappers to enable running LokiJS on dedicated (virtual) machines ● Replication ● Horizontal scaling ● MongoDB API subset compatibility