1.0.3 • Published 4 years ago

tempdb.js v1.0.3

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
4 years ago

TempDB

TempDB is a handy yet small side-project I made to easily be able to store user-specific settings. It allows developers to store data in the database either temporary or permanently.

Due to TempDB's connection system it'll keep reading and writing to the database's local file as minimalistic as possible. This also helps prevent data loss.

TempDB stores it's data in a local JSON file, by default this file is called tempdb.json, although this can be customized.

How to install

npm install tempdb.js

Example

/*
 Load the module, also immediately instantiates an object of the TempDBClient class.
*/
const tempdb = require("tempdb.js");

/*
 Sets a custom database path, by default this is tempdb.json. Whatever you set it to make sure it has the json extension
*/
tempdb.setPath("tempdb.json");

/*
 Connect to the database. Since there wasn't an active connection prior, this reads from tempdb.json.
*/
tempdb.connect();

/*
 Add data to the database, because we didn't specify a 3rd argument it'll be a permanent entry.
*/
tempdb.set("foo", "bar");

/*
 Add even more data! This entry expires after 1 minute (1 minute = 60 seconds).
*/
tempdb.set("thisBelongsToAcingDevelopment", true, 60);

/*
 Get the value belonging to the foo entry. Will return the following:
 {value: "bar", expireTime: null}
 After this it'll log it's value to the console.
*/
console.log(tempdb.get("foo").value);

/*
 After 30 seconds the thisBelongsToAcingDevelopment entry will still be valid, after 90 (30 + 60) seconds it won't and instead return null.
*/
setTimeout(function() {
 console.log(tempdb.get("thisBelongsToAcingDevelopment")); // {value: true, expireTime: (this will vary depending on when you've added the entry)}

 setTimeout(function() {
  console.log(tempdb.get("thisBelongsToAcingDevelopment")); // null

  /*
   Disconnect after we're done, this saves everything to the local JSON file.
  */
  tempdb.disconnect();
 }, 60000);
}, 30000);
1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago