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

ldbjs

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ldbjs

Create and manage local db files and data

  • 0.1.5
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

ldb

A lib to create and manage local db files and data, whit a simple send and get system,
save any data, html content, js objects and arrays, some texts, anything.

The erros in the operations is automatically returned not include in yours callbacks.

Creating a db location folder

const ldb = require('ldbjs');

ldb.createDB('.', 'myDB'); // optional callback

And your db are created.

Creating DB file

const ldb = require('ldbjs');

ldb.createDB('.', 'myDB'); // optional callback
ldb.createDBFile('.', 'myDB', 'myDBFile'); // optional callback

The file extension are .ldb.

Sending data to my dbfile

const ldb = require('ldbjs');

ldb.createDB('.', 'myDB');
ldb.createDBFile('.', 'myDB', 'myDBFile');

let myData = 'Hello World!';

ldb.sendData('.', 'myDB', 'myDBFile', myData, ()=>{
	// this callback is optional
	console.log(`${myData} as been sended to my ldb DB!`);
});

Sent data is saved exactly as sent

Getting data from dbfile

// electron example
const ldb = require('ldbjs');

let myPTag = document.getElementById('myP');

myPTag.innerHTML = ldb.getData('.', 'myDB', 'myDBFile'); // returns data of the file
console.log(ldb.getData('.', 'myDB', 'myDBFile')); // returns data in buffer format of the file

ldb.getData('.', 'myDB', 'myDBFile', (data)=>{ // optional callback
	myPTag.innerHTML = data;
});

The returned value is a json with the properties type and data, type is buffer and data is content,
while on console prints array with buffer, while on html component returns
exactly the data on the screen
.

To overwrite data of the file

const ldb = require('ldbjs');

ldb.createDB('.', 'myDB');
ldb.createDBFile('.', 'myDB', 'myDBFile');

let myData = 'I overwrited data!';

ldb.overwriteData('.', 'myDB', 'myDBFile', myData); // optional callback

That action is irreversible.

Cloning the content to other dbfile

const ldb = require('ldbjs');

ldb.createDB('.', 'myDB');
ldb.createDBFile('.', 'myDB', 'myDBFile');
ldb.createDBFile('.', 'myDB', 'myDBFile');

let myData = 'I overwrited data!';

ldb.sendData('.', 'myDB', 'myDBFile', myData); // optional callback

ldb.cloneDBFile('.', 'myDB', 'myDBFile', '.', 'myDB', 'myOtherDBFile', ()=>{ // optional callback
	console.log('')
});

To clone a file you need the two files created.

Deleting a dbfile

const ldb = require('ldbjs');

ldb.deleteDBFile('.', 'myDB', 'myDBFile', ()=>{ // optional callback
	console.log('the dbfile as been deleted');
});

That action is irreversible.

To rename a dbfile

const ldb = require('ldbjs');
ldb.renameDBFile('.', 'myDB', 'myDBFile', 'myNewDBFileName');

This function not receive a callback, are shown in the console the new stats of the file

Using events

const ldb = require('ldbjs');

ldb.event.on('create a DB', (path, name)=>{
	ldb.createDB(path, name);
});

ldb.event.emit('create a DB', '.', 'myDB');

Events are a very simple way to create and manage DBs and DBfiles in your application, don't repeat code anymore.

Sendding and getting data in a json

const ldb = require('ldbjs');

// createing a json dbfile
ldb.json.createDBFile('.', 'myJSONDBName', 'myJSONFileName', ()=>{
    // optional callback
    console.log('json dbfile created');
});

// sending the data

let myJSObj = {
    name: "Jhon",
    age: 27
};

ldb.json.sendData('.', 'myJSONDBName', 'myJSONFileName', myJSObj);

// getting the data
ldb.json.getData('.', 'myJSONDBName', 'myJSONFileName', (data)=>{
    document.getElementById('demo').innerHTML = JSON.parse(data);
});
// or to auto parse
document.getElementById('demo').innerHTML =  ldb.json.getDate('.', 'myJSONDBName', 'myJSONFileName');

While a data are getted a js obj are return, the api automatically convert the json to a js object for you.

Keywords

FAQs

Package last updated on 04 Aug 2019

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