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

What's hot

TMDC Vidrio Presentation
TMDC Vidrio PresentationTMDC Vidrio Presentation
TMDC Vidrio Presentation
Ricardo Vidrio
 
seawater desalination using MoS2 nanopore POWER POINT
seawater desalination using MoS2 nanopore POWER POINTseawater desalination using MoS2 nanopore POWER POINT
seawater desalination using MoS2 nanopore POWER POINT
princely oriomojor
 
Poradnik jak zlozyc_dobry_wniosek_do_ncn
Poradnik jak  zlozyc_dobry_wniosek_do_ncnPoradnik jak  zlozyc_dobry_wniosek_do_ncn
Poradnik jak zlozyc_dobry_wniosek_do_ncn
granty-na-badania
 
Crystalography
CrystalographyCrystalography
Crystalography
md5358dm
 

What's hot (20)

TMDC Vidrio Presentation
TMDC Vidrio PresentationTMDC Vidrio Presentation
TMDC Vidrio Presentation
 
Invisible excitations in hexagonal Boron Nitride
Invisible excitations  in hexagonal Boron NitrideInvisible excitations  in hexagonal Boron Nitride
Invisible excitations in hexagonal Boron Nitride
 
Band structure and surface properties of 1-4 layers of MoS2
Band structure and surface properties of 1-4 layers of MoS2Band structure and surface properties of 1-4 layers of MoS2
Band structure and surface properties of 1-4 layers of MoS2
 
Mte 583 class 18b
Mte 583 class 18bMte 583 class 18b
Mte 583 class 18b
 
Gw renormalization of the electron phonon coupling
Gw renormalization of the electron phonon couplingGw renormalization of the electron phonon coupling
Gw renormalization of the electron phonon coupling
 
Solid state physics unit 1.pdf
Solid state physics unit 1.pdfSolid state physics unit 1.pdf
Solid state physics unit 1.pdf
 
Nanophotocatalyst in organic transformation
Nanophotocatalyst in organic transformationNanophotocatalyst in organic transformation
Nanophotocatalyst in organic transformation
 
seawater desalination using MoS2 nanopore POWER POINT
seawater desalination using MoS2 nanopore POWER POINTseawater desalination using MoS2 nanopore POWER POINT
seawater desalination using MoS2 nanopore POWER POINT
 
Buku siswa ipa smt 2
Buku siswa ipa smt 2Buku siswa ipa smt 2
Buku siswa ipa smt 2
 
Poradnik jak zlozyc_dobry_wniosek_do_ncn
Poradnik jak  zlozyc_dobry_wniosek_do_ncnPoradnik jak  zlozyc_dobry_wniosek_do_ncn
Poradnik jak zlozyc_dobry_wniosek_do_ncn
 
Ising model
Ising modelIsing model
Ising model
 
Burris AR-332 Instruction Manual | Optics Trade
Burris AR-332 Instruction Manual | Optics TradeBurris AR-332 Instruction Manual | Optics Trade
Burris AR-332 Instruction Manual | Optics Trade
 
Rietveld Refinements ppt
Rietveld Refinements pptRietveld Refinements ppt
Rietveld Refinements ppt
 
magnesium doped zinc oxide nano particle
magnesium doped zinc oxide nano particlemagnesium doped zinc oxide nano particle
magnesium doped zinc oxide nano particle
 
UCSD NANO106 - 04 - Symmetry in Crystallography
UCSD NANO106 - 04 - Symmetry in CrystallographyUCSD NANO106 - 04 - Symmetry in Crystallography
UCSD NANO106 - 04 - Symmetry in Crystallography
 
9 pengenalan-bangun-ruang-dan-sifat2nya
9 pengenalan-bangun-ruang-dan-sifat2nya9 pengenalan-bangun-ruang-dan-sifat2nya
9 pengenalan-bangun-ruang-dan-sifat2nya
 
Amorphous Materials: Structural Principles and Characterization
Amorphous Materials: Structural Principles and CharacterizationAmorphous Materials: Structural Principles and Characterization
Amorphous Materials: Structural Principles and Characterization
 
Characterization of CVD grown molybdenum disulfide monolayer and exfoliated M...
Characterization of CVD grown molybdenum disulfide monolayer and exfoliated M...Characterization of CVD grown molybdenum disulfide monolayer and exfoliated M...
Characterization of CVD grown molybdenum disulfide monolayer and exfoliated M...
 
Crystalography
CrystalographyCrystalography
Crystalography
 
Bismuth Ferrite Nano particles
Bismuth Ferrite Nano particlesBismuth Ferrite Nano particles
Bismuth Ferrite Nano particles
 

Similar to Lokijs

ArangoDB – A different approach to NoSQL
ArangoDB – A different approach to NoSQLArangoDB – A different approach to NoSQL
ArangoDB – A different approach to NoSQL
ArangoDB Database
 
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
bitragowthamkumar1
 

Similar to Lokijs (20)

Polyglot Database - Linuxcon North America 2016
Polyglot Database - Linuxcon North America 2016Polyglot Database - Linuxcon North America 2016
Polyglot Database - Linuxcon North America 2016
 
Introduction to NoSQL
Introduction to NoSQLIntroduction to NoSQL
Introduction to NoSQL
 
CSCi226PPT1
CSCi226PPT1CSCi226PPT1
CSCi226PPT1
 
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
 

Recently uploaded

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Recently uploaded (20)

MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 

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