Skip to content

MartinKondor/LuxDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

☀ LuxDB

version Project Status Contributions welcome GitHub Issues Size License

LuxDB is a tiny, lightweight, 0 dependency, easy-to-use JSON-based database

const luxdb = new LuxDB('cache/testdb.json');
luxdb.set('users', []);
luxdb.point('users');
luxdb.push({'id': 0, 'name': 'Joe Doe'})
console.log(luxdb.get({'id': 0}));
// Prints { id: 0, name: 'Joe Doe' }

Usage

Pointer use

luxdb.point('users');
luxdb.point('..');  // Sets the pointer to the last pointer
luxdb.point('.');  // Sets the pointer to the database (starting point)

Creating a 'table' called 'users'

luxdb.set('users', []);

Inserting a 'row' to the 'users' table

luxdb.point('users');  // Always need to point to something first
luxdb.push({id: 0, name: 'Joe Doe'});

Inserting multiple rows to the 'users' table

luxdb.point('users')
    .push({id: 0, name: 'Joe Doe', gender: 'male'})
    .push({id: 1, name: 'Jane Doe', gender: 'female'})
    .push({id: 2, name: 'Aadam Doe', gender: 'male'})
    .push({id: 3, name: 'Eve Doe', gender: 'female'})

Select a specific row by column value

let query = luxdb.point('users').get({id: 2})
console.log(query);
>> [ {id: 2, name: 'Aadam Doe', gender: 'male'} ]

Select row by column value

let query = luxdb.point('users').get({gender: 'female'})
console.log(query);
>> [ {id: 0, name: 'Joe Doe', gender: 'male'}, {id: 2, name: 'Aadam Doe', gender: 'male'} ]

Update a specific row by column value

luxdb.update({name: 'Jane Doe'}, {name: 'Jane Janett Doe'})

Set an attribute to be auto added and incremented (TODO)

luxdb.point('users')
    .push({id: 0, name: 'Joe Doe', gender: 'male'})
    .push({id: 1, name: 'Jane Doe', gender: 'female'})
    .conf({id: luxdb.configs.AUTO_INCREMENT})
    .push({name: 'Aadam Doe', gender: 'male'})  // Will have id: 2
    .push({name: 'Eve Doe', gender: 'female'})  // Will have id: 3 

For a full example implementation, see the file tests/example.js.

Speed

Test data structure: {'n': [Attributes]}

No. of Attributes Written Time Elapsed Attributes Wrote/sec Data Size Wrote
100,000 30ms 3,333,333,333/sec 575 KB
1,000,000 40ms 25,000,000,000/sec 6,56 MB

Contributing

Ways to contribute:

  • Check for open issues
  • Read the TODO file
  • Make an improvement

Steps

  1. Fork this repository
  2. Create a new branch (optional)
  3. Clone it
  4. Make your changes
  5. Upload them
  6. Make a pull request here

Authors

License

Copyright © Martin Kondor 2022.

MIT license, see the LICENSE file for more details.

About

☀ LuxDB is a tiny, lightweight, 0 dependency, easy-to-use JSON-based database

Topics

Resources

License

Stars

Watchers

Forks