Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sagdb

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sagdb

Local json database.

  • 2.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
43
increased by2050%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 11 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc