Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tailsjs/simpledb
Simple JSON database.
https://github.com/tailsjs/simpledb
Last synced: 4 days ago
JSON representation
Simple JSON database.
- Host: GitHub
- URL: https://github.com/tailsjs/simpledb
- Owner: tailsjs
- Created: 2021-10-31T17:07:01.000Z (about 3 years ago)
- Default Branch: cjs
- Last Pushed: 2022-02-09T11:46:47.000Z (almost 3 years ago)
- Last Synced: 2024-11-19T12:48:09.707Z (2 months ago)
- Language: JavaScript
- Size: 30.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SimpleDB [CJS]
Simple JSON database.## Example
```js
const DB = require("./index.js");
const db = new DB({
filename: "db.json",
name: "users"
});
let user = {};
if(db.get().length == 0)
user = db.new({
id: 1,
name: "Denis",
lastname: "Stasov",
phonenumber: "89275714852",
activated: false
});user.redeem_code = "tailsjs";
db.write()
```
## Need to work:
* Install module ```fs``` (or just type ```npm i``` in console)## Functions
* Retrieving all entrys.
```js
db.get() // [{...}]
```
* Searching entry by JSON or function
```js
db.search({ name: "Vlad", lastname: "Stasov" }); // Example of JSON searching. [{ id: 1, name: "Vlad", lastname: "Stasov" ... }]
db.search(entry => entry.name == "Vlad" && entry.lastname == "Stasov") // Example of arrow function. [{ id: 1, name: "Vlad", lastname: "Stasov" ... }]
```
* Writing any changes. (Must be used after every post DB request, like as db.new() or db.clear())
```js
user.password = "secretPass<3";
db.write() // true
```
* Adding entry.
```js
db.new({
id: 2,
name: "Ivan",
lastname: "Ivanov",
phonenumber: "89276518535",
activated: false
}) // { id: 2, name: "Ivan", lastname: "Ivanov" }
```
* Removing entry by key.
```js
db.remove({ id: 2 }) // true
```
* Add some values to all entries if they don't have this value.
```js
db.include({
discord: "",
minecraft: ""
}) // { discord: 2, minecraft: 2 }
```
* Clear DB.
```js
db.clear() // true
```
* Add some values to all entries with some key if they don't have this value.
```js
db.includeKey(e => e.activated == true, {
twitch: ""
}) // { twitch: 1 }
```## Some author words
### I do not recommend this database for large projects. Better use MySQL, MongoDB, etc.