All Projects → StrykerKKD → SandDB

StrykerKKD / SandDB

Licence: MIT license
A simple immutable database for the masses.

Programming Languages

ocaml
1615 projects
Makefile
30231 projects

Projects that are alternatives of or similar to SandDB

Voik
♒︎ [WIP] An experimental ~distributed~ commit-log
Stars: ✭ 200 (+852.38%)
Mutual labels:  immutable
Collectable
High-performance immutable data structures for modern JavaScript and TypeScript applications. Functional interfaces, deep/composite operations API, mixed mutability API, TypeScript definitions, ES2015 module exports.
Stars: ✭ 233 (+1009.52%)
Mutual labels:  immutable
zab
C++20 liburing backed coroutine executor and event loop framework.
Stars: ✭ 54 (+157.14%)
Mutual labels:  asynchronous
Vue Tetris
Use Vue, Vuex to code Tetris.使用 Vue, Vuex 做俄罗斯方块
Stars: ✭ 2,446 (+11547.62%)
Mutual labels:  immutable
Hamt
Immutable and Memory-Efficient Maps and Sets in Go
Stars: ✭ 213 (+914.29%)
Mutual labels:  immutable
Model
Angular Model - Simple state management with minimalist API, one way data flow, multiple model support and immutable data exposed as RxJS Observable.
Stars: ✭ 242 (+1052.38%)
Mutual labels:  immutable
Python Lenses
A python lens library for manipulating deeply nested immutable structures
Stars: ✭ 179 (+752.38%)
Mutual labels:  immutable
Rump
REST client for Java that allows for easy configuration and default values. Allows for quick request construction and a huge range of modifications by using response/request interceptors, adjusting default values related to HTTP requests and creating custom instances for when you need multiple API connection setups.
Stars: ✭ 55 (+161.9%)
Mutual labels:  asynchronous
Static Frame
Immutable and grow-only Pandas-like DataFrames with a more explicit and consistent interface.
Stars: ✭ 217 (+933.33%)
Mutual labels:  immutable
go-clone
Clone any Go data structure deeply and thoroughly.
Stars: ✭ 182 (+766.67%)
Mutual labels:  immutable
Redux Freeze
Redux middleware that prevents state from being mutated anywhere in the app
Stars: ✭ 208 (+890.48%)
Mutual labels:  immutable
Music163 React
🔥基于React全家桶开发:「网易云音乐PC端项目」实战
Stars: ✭ 209 (+895.24%)
Mutual labels:  immutable
kotlin-ktor-exposed-sample-api
Kotlin Ktor Exposed SQL Immutable DB Rest API
Stars: ✭ 44 (+109.52%)
Mutual labels:  immutable
React Native Immutable List View
📜 Drop-in replacement for ListView, FlatList, and VirtualizedList.
Stars: ✭ 206 (+880.95%)
Mutual labels:  immutable
future.scala
Stack-safe asynchronous programming
Stars: ✭ 38 (+80.95%)
Mutual labels:  asynchronous
Ipmjs
Immutable Package Manager
Stars: ✭ 191 (+809.52%)
Mutual labels:  immutable
Unchanged
A tiny, fast, unopinionated handler for updating JS objects and arrays immutably
Stars: ✭ 237 (+1028.57%)
Mutual labels:  immutable
promise4j
Fluent promise framework for Java
Stars: ✭ 20 (-4.76%)
Mutual labels:  asynchronous
PandaDemo
Demo project for asynchronous render and Layout framework Panda
Stars: ✭ 15 (-28.57%)
Mutual labels:  asynchronous
futures-extra
Java library for working with Guava futures
Stars: ✭ 131 (+523.81%)
Mutual labels:  asynchronous

SandDB: A simple immutable database for the masses

SandDB is:

  • Simple: It only does one thing, which is persisting data in a file.
  • Easy to use: SandDB's API is extremely small, so you only need to know few functions to use it.
  • Type safe: Every common dangerous operation (like parsing) is covered by the Result type, so you will know where to expect errors.
  • Immutable: Database is based on the immutable stack idea, where you can only push onto the stack.
  • Crud capable: Even though the database is immutable you still can update and delete records, by shadowing them.
  • Version keeping: Every update and delete operation will produce a new version of the affected record, without modifying the original, so you will have all versions of your data.
  • Concurrent: SandDB is based on lwt, so every database operation is asynchronous.
  • Supports multiple serializers: SandDB supports both json and biniou serialization format thanks to the atdgen library.

Documentation

API documentation

How to use it?

This how to is based on the example that you can find in the examples directory.

  1. Install SandDB

    opam install sanddb
    
  2. Define your record's type with atd

    One of the most important component of SandDB is the atd library, so you must be a little bit familiar with it to be able to use the database.

    You can see below we defined a record which contains a date fields and a data field. It's important to notice that your record's root type's name must be t, because otherwise SandDB can't recognize which type to use. You can learn more about atd here.

    type t = {
        year : int;
        month : int;
        day : int;
        data: string;
    }
    
  3. Generate atd serializers for your record's type

    a. Generate with dune

    This will generate the serializers in the build directory, so it will keep your work directory clean of generated files.

    ;This rule generates your records type file
    (rule
        (targets record_t.ml record_t.mli)
        (deps record.atd)
        (action (run atdgen -t %{deps})))
    
    ;This rule generates the json serializer
    (rule
        (targets record_j.ml record_j.mli)
        (deps record.atd)
        (action (run atdgen -j %{deps})))
    
    ;This rule generates the biniou serializer
    (rule
        (targets record_b.ml record_b.mli)
        (deps record.atd)
        (action (run atdgen -b %{deps})))
    

    b. Generate maualy by using atdgen

    In this case you will generate the serializers in your working directory.

    $ atdgen -t record.atd     # produces OCaml type definitions
    $ atdgen -j record.atd     # produces OCaml code dealing with JSON
    $ atdgen -b record.atd     # produces OCaml code dealing with Biniou

    Notice: You don't need to generate both json and biniou serializer if you are only using one of them.

  4. Create the database

    Database creation only needs two things:

    • Database file, which in our case will be test.txt
    • Data serializer, which we generated in the previous steps
    (*Creating a json based database with test.txt file and Record_j generated serializer*)
    let database = Sanddb.create_json_database "test.txt" (module Record_j)
    
    (*or*)
    
    (*Creating a biniou based database with test.txt file and Record_b generated serializer*)
    let database = Sanddb.create_biniou_database "test.txt" (module Record_b)
  5. Insert record

    When you are inserting a record into the database you basically appending the record into the database file with a generated uuid, which will be the record's id.

    let record = { year = 2018; month = 4; day = 30; data="Some data 1"}
    Sanddb.insert_record database record
  6. Insert shadowing record

    One of the main feature of SandDb is that it's immutable, which is a good thing, but sometimes you want to update or delete a record. That's the time when you want to use a shadowing insert, because you can insert with it a record, which will overshadow the older record, so the older record won't be visible. This is achived by using the old record's id for the new record.

    let shadowing_record = { year = 2018; month = 5; day = 1; data="Some data 2"}
    Sanddb.insert_shadowing_record database id shadowing_record
  7. Read all records

    This will read out every record in the database both visible and shadowed record. You will get a list of tuples, where the first item is the oldest and the last item is the newest in the list. The tuple will consist of a record id and the record's content.

    Sanddb.read_all_records database ()
  8. Read visible records

    This will only read out the visible records in the database and will give back a list of tuples, where the first item is the newest and the last item is the oldest. So the order of the list items will be different in this case.

    Sanddb.read_visible_records database ()

How to run example

Install opam: https://opam.ocaml.org/doc/Install.html

Install dependencies: opam install . --deps-only --with-test

Build repository: dune build

Run example: dune exec examples/main.exe

How to for contributors

Test it: dune test

Run repl: dune utop

Generate Doc: dune doc

Update docs folder: make update-doc

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].