Skip to content
/ dbng Public

prototype database engine written in nodejs

Notifications You must be signed in to change notification settings

estraco/dbng

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dbng

Datababse engine written in Node.js

Installation

npm install dbng

Usage

import { Database, Table } from 'dbng';

const db = new Database('testDB', {
    users: new Table([
        { name: 'id', type: 'number', required: true, unique: true },
        { name: 'name', type: 'string', required: true },
        { name: 'age', type: 'number', required: true },
        { name: 'isCool', type: 'boolean', required: true },
        { name: 'createdAt', type: 'date', required: true },
        { name: 'metadata', type: 'json', required: true }
    ]),
    guilds: new Table([
        { name: 'id', type: 'number', required: true, unique: true },
        { name: 'name', type: 'string', required: true },
        { name: 'createdAt', type: 'date', required: true },
        { name: 'metadata', type: 'json', required: true }
    ])
});

const userRow = {
    id: { data: 1 },
    name: { data: 'John' },
    age: { data: 20 },
    isCool: { data: true },
    createdAt: { data: new Date() },
    metadata: {
        data: {
            favoriteColor: 'blue',
            favoriteNumber: 42
        }
    }
};

const guildRow = {
    id: { data: 1 },
    name: { data: 'My Server' },
    createdAt: { data: new Date() },
    metadata: {
        data: {
            owner: 'John',
            members: 20
        }
    }
};

db.getTable('users').insert(userRow);
db.getTable('guilds').insert(guildRow);

db.save();

const db2 = new Database('testDB', {
    users: new Table([
        { name: 'id', type: 'number', required: true, unique: true },
        { name: 'name', type: 'string', required: true },
        { name: 'age', type: 'number', required: true },
        { name: 'isCool', type: 'boolean', required: true },
        { name: 'createdAt', type: 'date', required: true },
        { name: 'metadata', type: 'json', required: true }
    ]),
    guilds: new Table([
        { name: 'id', type: 'number', required: true, unique: true },
        { name: 'name', type: 'string', required: true },
        { name: 'createdAt', type: 'date', required: true },
        { name: 'metadata', type: 'json', required: true }
    ])
});

db2.load();

console.log(db2.getTable('users').select());
console.log(db2.getTable('guilds').select());

db2.getTable('users').deleteWhere({ id: { data: 1 } });
db2.getTable('guilds').deleteWhere({ id: { data: 1 } });

db2.save();

console.log(db2.getTable('users').select());
console.log(db2.getTable('guilds').select());

License

MIT

About

prototype database engine written in nodejs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published