New:Microsoft Teams Notifications Are Now Available in Socket.Learn more →
Get Started

nocon-db

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nocon-db

NoSQL local file storage with constraints -- unique keys, null check and indexing, akin to SQLite, with API similar to liteorm

latest
Source
npmnpm
Version
0.1.5
Version published
Maintainers
1
Created
Source

nocon-db

NoSQL local file storage with constraints -- unique keys, null check and indexing, akin to SQLite, with API similar to liteorm. Powered by TypeScript decorators and interface. Also with async event-emitter, thanks to emittery.

Can save as BSON with BsonAdapter.

Filtering and mapping with objects (in find, update, delete) is possible, thanks to lodash.

If you need typings, you can also enforce constraints.

Usage

import { Db } from "nocon-db";

(async () => {
  const db = new Db("foo.nocon");
  await db.load();
  const col = db.collection<any>("bar");
  await col.insert({a: 1, b: new Date()});
  console.log(await col.find({a: 1}));
})();

You can even define Schema and unique keys. In this case, you will need to use Class decorators.

import { Db, prop, Table, BsonAdapter } from "nocon-db";

@Table()
class UniqueA {
  @prop({unique: true}) a!: string;
  b!: Date;
}

(async () => {
  let db = new Db("test.nocon", new BsonAdapter());
  await db.load();
  const col = db.collection(new UniqueA());
  await col.insert({a: "any", b: new Date()});
  console.log(await col.find());
  await db.close();

  db = new Db("test.nocon", new BsonAdapter());
  await db.load();
  const col = db.collection(new UniqueA());
  await col.insert({a: "any", b: new Date()});  // Error
})();

Keywords

nosql

FAQs

Package last updated on 18 Sep 2019

Related posts