Skip to content

SeaORM wrapper for NodeJS, providing basic key/value storage in SQLite/Postgres/MySQL/MariaDB

Notifications You must be signed in to change notification settings

dan-online/brinedb

Repository files navigation

npm version

BrineDB

SeaORM wrapper for NodeJS, providing basic key/value storage in SQLite/Postgres/MySQL/MariaDB.

Table of contents

Getting Started

Installation

To install and set up the library, run:

$ yarn add @brine-db/brine

Or if you prefer npm:

$ npm i @brine-db/brine

Quick Start

const { Brine } = require('@brine-db/brine');

// SQLite
const brinedb = new Brine('sqlite::memory:');
const brinedb = new Brine('sqlite:/path/to/database.sqlite');

// Postgres
const brinedb = new Brine('postgres://user:pass@localhost:5432/dbname');

// MySQL/MariaDB
const brinedb = new Brine('mysql://user:pass@localhost:3306/dbname');

// Initialize the database (also runs migrations)
await brinedb.init();

// Set a value
await brinedb.set('key', { hello: 'world' });

// Get a value
const value = await brinedb.get('key');

Typescript

This library is written in Typescript and includes type definitions. Here is an example that will be typed correctly:

import { Brine } from '@brine-db/brine';

type Value = { hello: string }

const brinedb = new Brine<Value>('sqlite::memory:');

await brinedb.set('key', { hello: 'world' });

const decoded = brinedb.get('key');

typeof decoded.hello; // string

Development

Prerequisites

This project requires NodeJS (version 18 or later) and yarn. Node and Yarn are really easy to install. To make sure you have them available on your machine, try running the following command.

$ yarn -v && node -v && rustc --version # Example output
3.6.3
v20.11.1
rustc 1.78.0-nightly (4a0cc881d 2024-03-11)

Building the entire package

Requirement: Rust is installed on your machine.

$ yarn build

This task will create a distribution version of the project inside your local dist/ folder and output a binary in native/

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Add your changes: git add .
  4. Commit your changes: git commit -am 'Add some feature'
  5. Push to the branch: git push origin my-new-feature
  6. Submit a pull request 😎

Built With

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

License

MIT License © DanCodes