Skip to content

The Native Jamstack Database. A NoSQL key-value database stored as a directory tree of small JSON files which can be deployed as part of a static website and queried from client browsers in an efficient manner.

master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

static-json-db

The Native Jamstack Database.

Build Status

A NoSQL key-value database stored as a directory tree of small JSON files which can be deployed as part of a static website and queried from client browsers in an efficient manner. Data is stored in JSON files which are branched into smaller JSON files as size tresholds are met. Minified JS for browser ~1.5KB.

Demo / Proof of Concept

Example Usage

Node.js

$ npm install static-json-db
const StaticJsonDb = require('static-json-db')
const db = new StaticJsonDb('data'); // using directory 'data'

(async () => {
  await db.set('key1','Hello World1')
  await db.set('key2','Hello World2')
  await db.set('abc','def')

  console.log(await db.get('key1')) // Hello World1

  // get all keys starting with 'key'
  console.log(await db.getAll('key')) // { key1: 'Hello World1', key2: 'Hello World2' }

  await db.delete('key2')

  // get all keys
  console.log(await db.getAll()) // { key1: 'Hello World1', abc: 'def' }

  //write to disk
  await db.write()
})();

HTML

https://jlxw.github.io/static-json-db/example.html

<html>
  <head>
    <script src="https://jlxw.github.io/static-json-db/static-json-db.min.js"></script>
    <script>
      const db = new StaticJsonDb(new URL('data',window.location));
      (async () => {
        console.log(await db.get('key1')) // Hello World1
        console.log(await db.getAll()) // {key1: "Hello World1", abc: "def"}
      })();
    </script>
  </head>
</html>

Notes

  • If you need to modify in place objects returned by .get() or sent to .set(), use .getSafe() or .setSafe() instead

Why?

Hosting for JAMStack / static websites are almost free now, and can be very easily and cheaply scaled. static-json-db can be a lower-cost alternative to traditional databases that do not need to be updated frequently. The proof of concept www.playliststar.com is updated on an hourly basis with ~200K tracks across ~7K playlists.

In the future I imagine adding a real-time component to complement static-json-db. Probably a very simple server that appends to a flat JSON file, which is served as a static file, and periodically "merged" with the "main" db.

License

MIT

About

The Native Jamstack Database. A NoSQL key-value database stored as a directory tree of small JSON files which can be deployed as part of a static website and queried from client browsers in an efficient manner.

Resources

License

Releases

No releases published
You can’t perform that action at this time.