Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aldotestino/db-eazy
A simple JSON based local database
https://github.com/aldotestino/db-eazy
Last synced: about 2 months ago
JSON representation
A simple JSON based local database
- Host: GitHub
- URL: https://github.com/aldotestino/db-eazy
- Owner: aldotestino
- License: mit
- Created: 2020-10-07T10:12:30.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-02-05T22:56:35.000Z (almost 4 years ago)
- Last Synced: 2024-11-04T23:35:17.733Z (2 months ago)
- Language: TypeScript
- Homepage: https://db-eazy.vercel.app
- Size: 398 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [db-eazy](https://db-eazy.vercel.app/) by aldotestino
## A simple JSON based local database
### Version: 1.0.4
### Languages:
* Typescript,
* Node### Dependencies:
* nanoid### Installation
```sh
npm install db-eazy
```### Quick Start
```typescript
import { Database } from 'db-eazy';
import path from 'path';// path to db folder (the db folder will be automatically created)
const db = new Database(path.join(__dirname, '..'));interface User = {
name: string;
email: string;
}const users = db.get('users');
```### Insert
```typescript
// returns the object that has been inserted
users.insert({
name: 'Dannel Bakesef',
email: '[email protected]',
});
```### Query
```typescript
// returns an array of users
users.findAll();// returns the user with that specific id
users.findOne('id_of_the_user');// returns an array of users that matches the query parameter
users.find({property: 'name', value: 'John'});
```### Update
```typescript
// update the specific user, setting the passed property
// with the new value and returns the updated user
users.updateOne('id_of_the_user', {type: '$set', property: 'email', value: 'new_email'});// if the property is of type number increments
// it by one and returns the updated user
users.updateOne('id_of_the_user', {type: '$inc', property: 'age'});
```### Remove
```typescript
// removes the specific user and returns it
users.remove('id_of_the_user');
```### Unique property
```typescript
// set the email as an unique property
// (checks for updates too)
users.setUniqueProperty('email');
```[Full example](src/example.ts)
[MIT license](LICENSE)