2.3.0 • Published 9 months ago

sagdb v2.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Sagdb

Image Image

Image

Sagdb is JSON database system.

Installation

$ npm install sagdb

Usage

//JavaScript version
const Sagdb = require("sagdb").default;
//TypeScript version
import Sagdb from "sagdb";
  • Default database name is "db".

  • Db name and folder name is must be String.

  • Database folder name is optional.

  • If you want readable database, set "minify" to false.

const db = new Sagdb({ name: "database", folder: "foldername", minify: true });
const db = new Sagdb({ name: "database", folder: "folder/database" });
const db = new Sagdb({ name: "database" });

Method's

set

  • Set any value with key.
db.set("key", "apple"); // -> apple

Can't set Function.

function test() {}
db.set("key", test); // -> return Error

get

  • Get any value with key.
db.set("key", "apple"); // -> apple

db.get("key"); // -> apple

update

  • Update get a callback function, give old data and return must be a same type old data.
db.update("key", (old_data) => {
  const new_data = old_data.toUpperCase();
  return new_data;
});

delete

  • Delete any key from database.
db.set("key", "apple"); // -> apple

db.delete("key"); // -> apple

db.get("key"); // -> undefined

add

  • Add number to number value.

  • Value must be a Number.

  • Default number is 1.

db.set("number", 1); // -> 1
db.get("number"); // -> 1

db.add("number", 3); // -> 4
db.get("number"); // -> 4

db.add("number"); // -> 5
db.get("number"); // 5

db.add("number", "asd"); // return false

Extra

U can set object in object.

db.set("key.value", "apple"); // -> apple
db.get("key"); // -> { value : "apple" }

Table

import Sagdb, { Table } from "sagdb";

const db = new Sagdb({ name: "database" });

const table = new Table(db, "table_name");

add

table.add(1); // -> {_id: "uuid", data: 1, createdAt: number, updatedAt: number}

find

table.find(callback | data_object); // -> {_id: "uuid", data: 1, createdAt: number, updatedAt: number} | undefined

findById

table.findById("uuid"); // -> {_id: "uuid", data: 1, createdAt: number, updatedAt: number} | undefined

update

table.update(callback | data_object, new_data, force?: boolean); // -> {_id: "uuid", data: 1, createdAt: number, updatedAt: number} | undefined

filter

table.filter(callback | data_object, new_data); // -> old_data:  {_id: "uuid", data: 1, createdAt: number, updatedAt: number}[] | undefined

remove

table.update(callback, all?: boolean); // -> {_id: "uuid", data: 1, createdAt: number, updatedAt: number} | undefined

Listeneer's

On

table.on("event_name", callback()); // -> Listening.

Example

table.on("add", callback(new_data));

table.on("update", callback(old_data, new_data));

table.on("remove", callback(old_data));

License MIT

2.3.0

9 months ago

2.2.1

9 months ago

2.1.2

11 months ago

2.0.3

11 months ago

2.2.0

9 months ago

2.1.1

11 months ago

2.0.2

11 months ago

2.2.3

9 months ago

2.1.4

11 months ago

2.0.5

11 months ago

2.2.2

9 months ago

2.1.3

11 months ago

2.0.4

11 months ago

2.2.5

9 months ago

2.1.6

10 months ago

2.0.7

11 months ago

2.2.4

9 months ago

2.1.5

11 months ago

2.0.6

11 months ago

2.2.7

9 months ago

2.1.8

10 months ago

2.2.6

9 months ago

2.1.7

10 months ago

2.0.8

11 months ago

2.1.0

11 months ago

2.0.1

11 months ago

2.0.0

11 months ago

2.2.9

9 months ago

2.2.8

9 months ago

2.1.9

9 months ago

1.1.2

12 months ago

1.1.1

12 months ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago