TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

LokiJS – Lightweight JavaScript in-memory database

130 pointsby joeminichinoover 10 years ago

10 comments

skrebbelover 10 years ago
Great!<p>I&#x27;m really no expert, but I think that language-specific persistent in-memory databases are the way to go.<p>Deep inside, what I really want on my backends is just a data structure. A single big tree (or graph) of objects. Some primitives to make it thread-safe somehow (immutable collections, or mutexes, or just old-fashioned single-threadedness like Node - whatever), and that&#x27;s it. Requests from the client query and mutate that data. In <i>very many</i> situations, I wouldn&#x27;t need anything special to make this work fine with an application up to a pretty large number of users. Not all apps do big data analyses. RAMs are gigantic these days, bigger than the SQL datafiles of swathes of webapps.<p>However, there&#x27;s that pesky problem of code upgrades and crashing servers. If my server would never crash and I could hot-swap the code, I wouldn&#x27;t need persistence at all. But I do, so I don&#x27;t just want an in-memory datastructure, but a <i>persistent</i> in-memory data structure. I want to use this datastructure as easily as the programming language could possibly make it be for me while still guaranteeing some sane level of persistence and fault tolerance.<p>Redis is a nice idea, but the fact that it&#x27;s a separate server, with a client and a protocol and data structures that <i>just not precisely</i> map to my programming language&#x27;s data structures force me to write a whole bunch of boilerplate anyway. Even more so with other databases like Mongo or Postgres.<p>If I understand it well, Loki doesn&#x27;t entirely do what I&#x27;d want: it does not save the data to disk on every change, but less often, if I get it right. That might be good enough if my problem allows for many little independent Loki databases, but if the dataset is a gigabyte and persistence means flushing that whole gigabyte to disk after every data change, it probably won&#x27;t work very well.<p>I&#x27;m really curious if other people here have similar ideas, maybe implementations, of these concepts. Maybe Loki could be extended with a snapshot+operation_log type of data storage like Redis has and then it&#x27;d be pretty close.
评论 #8558257 未加载
评论 #8560753 未加载
评论 #8558738 未加载
Sir_Cmpwnover 10 years ago
Related: SQL.js, which is sqlite compiled with emscripten<p><a href="https://github.com/kripken/sql.js" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kripken&#x2F;sql.js</a>
评论 #8558774 未加载
imslavkoover 10 years ago
From skimming the presentation it looks like a project similar to Meteor&#x27;s Minimongo and Miniredis (<a href="https://www.meteor.com/mini-databases" rel="nofollow">https:&#x2F;&#x2F;www.meteor.com&#x2F;mini-databases</a>) used for browser caches. Minimongo, for example, implements a great majority of Mongo selectors (there are no secondary indexes, though).<p>(I contributed to both Minimongo and Miniredis)
jedirezaover 10 years ago
I&#x27;m curious why NeDB wouldn&#x27;t suffice.<p><a href="https://github.com/louischatriot/nedb" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;louischatriot&#x2F;nedb</a>
评论 #8557920 未加载
keithwhorover 10 years ago
How does this compare to DataCollection.js?<p><a href="https://www.npmjs.org/package/data-collection" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.org&#x2F;package&#x2F;data-collection</a> <a href="http://thestorefront.github.io/DataCollection.js/" rel="nofollow">http:&#x2F;&#x2F;thestorefront.github.io&#x2F;DataCollection.js&#x2F;</a><p>They look fairly similar. What&#x27;s the test coverage and do you have performance benchmarks?
remonover 10 years ago
Out of pure curiosity, what are the common use cases for a fast in-memory database? Are they exclusive to server-side applications (e.g. caching)?
评论 #8558375 未加载
评论 #8558211 未加载
评论 #8559066 未加载
评论 #8558455 未加载
marknadalover 10 years ago
Excellent project, there needs to be more focus in this space. I&#x27;ve been feeling a general trend of developers going back to basic embedded databases.<p>I&#x27;m working on a similar project, that is focused on ease of use combined with distributed&#x2F;decentralized (concurrency safe) behavior. Http:&#x2F;&#x2F;github.com&#x2F;amark&#x2F;gun
cloudsheetover 10 years ago
Has anyone used this is lieu of or in comparison to Redis? Am I correct in assuming that with LokiJS, one could move in-memory data storage from the server (with Redis) to the browser (with LokiJS)?<p>This project looks quite interesting. Thanks for sharing. Could be a great solution for single-page web apps (and mobile, Cordova, etc.).
评论 #8558396 未加载
leeberover 10 years ago
This looks interesting. Coincidentally I was just searching around for something like this to run in the browser.<p>I&#x27;ll play around with it myself, but is there anyone who has used this that knows how well it does with memory usage?
评论 #8557888 未加载
评论 #8557831 未加载
quartzmoover 10 years ago
I want a very fast, client-side, read-only database with rich query support. Is this the best choice?