Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/5antos/simpl.db
A lightweight, 0 dependency, easy-to-use local database using JSON to store data
https://github.com/5antos/simpl.db
database db easy-to-use json lightweight localstorage quick simple
Last synced: about 1 month ago
JSON representation
A lightweight, 0 dependency, easy-to-use local database using JSON to store data
- Host: GitHub
- URL: https://github.com/5antos/simpl.db
- Owner: 5antos
- License: mit
- Created: 2021-05-07T01:55:42.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-16T04:19:04.000Z (10 months ago)
- Last Synced: 2024-10-02T03:03:20.344Z (about 2 months ago)
- Topics: database, db, easy-to-use, json, lightweight, localstorage, quick, simple
- Language: JavaScript
- Homepage: https://simpldb.js.org
- Size: 545 KB
- Stars: 36
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A lightweight, 0 dependency, easy-to-use local database using JSON to store data.
- **[Documentation](https://simpldb.gitbook.io/docs/)**
- **[Yarn Package](https://yarnpkg.com/package/simpl.db)**
- **[NPM Package](https://npmjs.com/package/simpl.db)**
- **[NPM Package Statistics](https://npm-stat.com/charts.html?package=simpl.db&from=2021-05-07)**Installation
------------```sh-session
npm install simpl.db
yarn add simpl.db
pnpm add simpl.db
```Example Usage
-------------Database
```js
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'); // falsedb.get('person.name'); // 'Peter'
db.get('person.job'); // undefineddb.toJSON(); // { money: 100, person: { name: 'Peter' } }
```Collections
```js
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'
);
// or ([email protected]+)
const user = Users.get(target => target.name === 'Peter');
user.age = 20;
user.save();Users.get(user => user.name === 'Peter'); // { name: 'Peter', age: 20 }
Users.getMany(user => user.age > 18); // [{ name: 'Peter', age: 20 }, { name: 'John', age: 19 }]
```With TypeScript:
```ts
import { Database, Modifiable } from 'simpl.db';
const db = new Database();type User = {
name: string
age: number
}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'
);
// or ([email protected]+)
const user = > Users.get(target => target.name === 'Peter');
user.age = 20;
user.save();Users.get(user => user.name === 'Peter'); // { name: 'Peter', age: 20 }
Users.getMany(user => user.age > 18); // [{ name: 'Peter', age: 20 }, { name: 'John', age: 19 }]
```Contributing
------------Before [creating an issue](https://github.com/5antos/simpl.db/issues), please ensure that it hasn't already been reported or suggested.
When [submitting a new pull request](https://github.com/5antos/simpl.db/pulls), please make sure the code style/format used is the same as the one used in the original code.
License
-------Refer to the [LICENSE](LICENSE) file.