GithubHelp home page GithubHelp logo

gaia.db-lite's Introduction

Gaia.DB-Lite

A lite version of Gaia.DB.

Examples

Singlethreaded

const { Database } = require(`gaia.db-lite`);
const db = new Database;

(async () => {
    await db.setup();
    db.set(0, "hi");
    console.log(db.data, db.get("hi"));
    await db.save();
})();

Multithreaded

index.js

const { Master } = require(`${__dirname}/../src/index.js`);
const master = new Master;

setImmediate(async () => {
    await master.setup();
    await master.fork(`${__dirname}/child.js`);
});

child.js

console.log(`[${process.pid}] Here!`);
setImmediate(async () => {
    await $set(true, process.pid.toString());
    console.log(`[${process.pid}] ${await $get(process.pid.toString())}`);
    await $save();
});

Methods

Singlethreaded

new Database(folderPath?: String = "./database")

  • folderPath Database's folder path. Create new database instance.

Database#save(maxSizePerFile?: Number = 1024) -> Promise<Database#read()>

  • maxSizePerFile Max buffer size per db file in bytes. Save the database.
    Note: Stored in multiple files.

Database#read() -> Promise<this>

Read the database files and refresh cache (database object).

Database#setup() -> Promise<this>

Create the database folder if it's not exist and do other stuffs.

Database#set(value: Any, path?: String) -> this

Change path's value of database object. If path is a falsy value, it will change the database object and the value must be an object.

Database#get(path?) -> Any

Get path's value of database object. If path is a falsy value, it will returns the database object.

Database#delete(path?) -> Any

Unset path's value of database object. If path is a falsy value, it will set database object's value to a blank object.

Database#data

Database object.

Database#folderPath

Database's folder path.

Multithreaded

new Master(folderPath?: String = "./database", childFilePath?: String)

  • folderPath Database's folder path.
  • childFilePath Default child's file path for Master#spawn. Master class have same properties and methods with Database and EventEmitter.

Master#fork(childFilePath?: String) -> Promise<ChildProcess>

Fork a file to create new child.

Child

global.$set(value: Any, path?: String) -> Promise<this>

A copy of Database#set.

global.$get(value: Any) -> Promise<Any>

A copy of Database#get.

global.$delete(path?: String) -> Promise<this>

A copy of Database#delete.

global.$save(maxSizePerFile?: Number = 1024) -> Promise<this>

A copy of Database#save.

global.$folderPath

Database's folder path.

Support Us

PayPal

Developer

Discord: Ganora Mirush#9524
NPM: nekomaru76
GitHub: NekoMaru76

gaia.db-lite's People

Contributors

nekomaru76 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.