0.0.7 • Published 1 year ago

neutron-db v0.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Neutron DB

This is an attempt at creating a (sync) JSON db for electron using typescript.

How to use

The DB is initialized with a "schema" :

interface Schema {
  tables: string[]; // names of the tables
  dbname: string; // name of the database used to create the JSON file
  oneIndexed?: boolean; // specify if the id of the objects should start from 1 or 0, by default the ids will start from 0
  compressedJson?: boolean; // specify if the JSON file should be compressed on one line
  location?: string; // path to the database location
}

The objects have to inherit from DbObject to expose an id

interface DbObject {
  id: number;
}

To use the database just instantiate the class Database by providing a schema.

The exposed primitives are :

insert<T extends DbObject>(row: T, tablename: string): T
update<T extends DbObject>(row: T, tablename: string): T | null
getAll<T extends DbObject>(tablename: string): T[]
get<T extends DbObject>(id: number, tablename: string): T | null
delete(id: number, tablename: string): void

clear(tablename: string): void
count(tablename: string): number

Heavily inspired by electron-db

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

1.0.0

2 years ago