Giter VIP home page Giter VIP logo

strato-db's Introduction

Note: The most recent developments are in the https://github.com/StratoKit/strato-db/tree/improvements branch

Strato-DB

NoSQL-hybrid with Event Sourcing based on SQLite

The overall concept is to be a minimal wrapper that keeps SQL close by, but allows schemaless storage for where you want it.

DB: Wraps a Sqlite3 database with a lazy-init promise interface; has easy migrations

JsonModel: Stores given objects in a DB instance as JSON fields with an id column, other columns can be calculated or be virtual. You can only perform searches via the wrapper on defined columns.

EventQueue: Stores events in an auto-incrementing DB table. Minimal message queue.

EventSourcingDB: Implements the Event Sourcing concept using EventQueue. See [Server Side Redux](./Server Side Redux.md).

ESModel: A drop-in replacement for JsonModel to use ESDB

Install

$ npm install @yaska-eu/strato-db
...

Usage

import config from 'stratokit/config'
import {DB, EventQueue, EventSourcingDB, JsonModel} from 'strato-db'

const {
	main: {file},
	queue: {file: qFile},
	debug: verbose,
} = config.db

const db = new DB({file, verbose})
const qDb = qFile && qFile !== file ? new DB({file: qFile, verbose}) : db

export const queue = new EventQueue({db: qDb})

class Things extends JsonModel {
	constructor(options) {
		super({
			...options,
			name: 'things',
			columns: {
				...options.columns,
				info: {index: 'SPARSE'},
			},
		})
	}
}

db.addModel(Things)

const eSDB = new EventSourcingDB({
	db,
	queue,
	models: {dateRanges, derivedStuff},
})

// only opens the db once this runs
await db.store.things.set({id: 'foo', info: 'is a foo'})
await db.store.things.search({info: 'is a foo'})

Status

This project is used in production environments, but it doesn't have documentation other than the code for now.

Since it is based on SQLite, the actual storage of data is rock-solid.

It works fine with multi-GB databases, and if you choose your queries and indexes well, you still have single-digit-ms query times.

The important things are tested, our goal is 100% coverage.

Multi-process behavior is not very worked out for the EventSourcingDB. Since it's layering a single-locking queue on top of SQLite, it works without problems, but no effort is made to avoid double work. To have DB slaves, the idea would be to either use distributed SQLite as implemented by BedrockDB, or to distribute the event queue to slaves and have them derive their own copy of the data.

Take a look at the TODO.md, there are plenty of improvements planned.

License

MIT © Wout Mertens

strato-db's People

Contributors

wmertens avatar dzieni avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.