A lightweight, 0 dependency, easy-to-use local database using JSON to store data.
npm install simpl.db
yarn add simpl.db
pnpm add simpl.db
const SimplDB = require('simpl.db');
const db = new SimplDB();
db.set('money', 100);
db.set('person.name', 'Peter');
db.has('money'); // true
db.has('person.name'); // true
db.has('person.age'); // false
db.get('person.name'); // 'Peter'
db.get('person.job'); // undefined
db.toJSON(); // { money: 100, person: { name: 'Peter' } }
const SimplDB = require('simpl.db');
const db = new SimplDB();
const Users = db.createCollection('users');
Users.create({ name: 'Peter', age: 19 });
Users.create({ name: 'John', age: 19 });
Users.update(
user => user.age = 20,
target => target.name === 'Peter'
);
Users.get(user => user.name === 'Peter'); // { name: 'Peter', age: 20 }
Users.get(user => user.age > 18); // [{ name: 'Peter', age: 20 }, { name: 'John', age: 19 }]
With TypeScript:
import SimplDB from 'simpl.db';
const db = new SimplDB();
type User = {
name: string
age: number
}
const Users = db.createCollection<User>('users');
Users.create({ name: 'Peter', age: 19 });
Users.create({ name: 'John', age: 19 });
Users.update(
user => user.age = 20,
target => target.name === 'Peter'
);
Users.get(user => user.name === 'Peter'); // { name: 'Peter', age: 20 }
Users.get(user => user.age > 18); // [{ name: 'Peter', age: 20 }, { name: 'John', age: 19 }]
Before creating an issue, please ensure that it hasn't already been reported or suggested.
When submitting a new pull request, please make sure the code style/format used is the same as the one used in the original code.
Refer to the LICENSE file.