Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ciaanh/neutron-db
https://github.com/ciaanh/neutron-db
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/ciaanh/neutron-db
- Owner: Ciaanh
- License: mit
- Created: 2022-10-30T20:19:29.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-11-22T22:33:18.000Z (about 2 years ago)
- Last Synced: 2024-12-01T12:50:17.956Z (about 1 month ago)
- Language: TypeScript
- Size: 97.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# 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(row: T, tablename: string): T
update(row: T, tablename: string): T | null
getAll(tablename: string): T[]
get(id: number, tablename: string): T | null
delete(id: number, tablename: string): voidclear(tablename: string): void
count(tablename: string): number
```---
Heavily inspired by [electron-db](https://github.com/alexiusacademia/electron-db)