The hackable quick.db.
You can easily switch between this library and quick.db (
7.0.0-b21
) if you are usingjson.sqlite
file as database.
- Beginner friendly
- Custom database file
- More control over your database
- More utility methods
- Simple and easy to use
- Based on original quick.db
- Key value based
- Easy to migrate from/to quick.db
Definitely not for professional people
const { Database } = require("@pisaucer/quick.db");
const db = new Database("./data/storage.db", { path: "./data", table: "ROOT" }); // you can also specify custom path/name
// add some data
db.set("foo", "bar");
db.set("hello", "world");
// log all data. You can also use db.all()
for (const data of db) {
console.log(data);
}
// Setting an object in the database:
console.log(db.set('userInfo', { difficulty: 'Easy' }))
// -> { difficulty: 'Easy' }
// Pushing an element to an array (that doesn't exist yet) in an object:
console.log(db.push('userInfo.items', 'Sword'))
// -> { difficulty: 'Easy', items: ['Sword'] }
// Adding to a number (that doesn't exist yet) in an object:
console.log(db.add('userInfo.balance', 500))
// -> { difficulty: 'Easy', items: ['Sword'], balance: 500 }
// Repeating previous examples:
console.log(db.push('userInfo.items', 'Watch'))
// -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 500 }
console.log(db.add('userInfo.balance', 500))
// -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 1000 }
// Fetching individual properties
console.log(db.get('userInfo.balance')) // -> 1000
console.log(db.get('userInfo.items')) // ['Sword', 'Watch']
const mytable = db.createTable("tableName");
db.set("foo", "bar");
mytable.set("foo", 123);
db.get("foo"); // bar
mytable.get("foo"); // 123
const tables = db.tables();
console.log(tables);
// { count: 2, tables: [ 'JSON', 'tableName' ] }
const sqlite = db.database;
const statement = sqlite.prepare("SELECT * FROM JSON WHERE ID IS NOT NULL");
for (const item of statement.iterate()) {
console.log(item);
}
This db behaves like quick.db.
const db = require("@pisaucer/quick.db").static();
db.set("foo", "bar");
console.log(db.get("foo"));
const db = require("@pisaucer/quick.db").static("./json.db");
db.set("foo", "bar");
console.log(db.get("foo"));
This method returns currently used table (or specified table) as array.
Alias of db.all()
.
This method can be used for addition (numbers).
This method can be used to remove specific data with its key.
This method can be used to get data from the database.
Alias of db.fetch
.
This method can be used to update existing data or add new data.
Similar to db.add
, this method can be used for subtraction.
Returns true if it finds the requested key in the database.
Returns data type of the value assigned to this key.
This method can be used to push the data (Similar to Array.prototype.push
).
Similar to Array.prototype.find
.
Similar to Array.prototype.some
.
Similar to Array.prototype.map
.
Similar to Array.prototype.flatMap
.
Similar to Array.prototype.forEach
.
Similar to Array.prototype.every
.
Similar to Array.prototype.findIndex
.
Similar to Array.prototype.indexOf
.
Similar to Array.prototype.reduce
.
Similar to Array.prototype.reduceRight
.
Similar to Array.prototype.sort
.
Returns all table name.
If not available, creates a new table with the given name otherwise uses existing table and returns new database with that table as root table.
Drops current table or specified table.
Returns array of keys.
Returns array of values.
Returns array of this table.
Division for existing data with the given number.
Multiplication for existing data with the given number.
Modulus for existing data with the given number.
Similar to db.all
but easier method to sort by key.
Similar to db.all
but easier method to sort by key.
Used to pull data from the array stored inside the database. (Reverse .push
)
Deletes all data from the specified table.
File size of this db.
Allows you to evaluate anything inside Database
class using this
.
A method that just creates table rather than returning new database.
Exports database into json data.
This method updates current database manager with a new one. Database parameter can either be Database
instance or BetterSQLite3.Database
instance.
Returns array of all tables with their table name.
This method is similar to db.allTableArray
but returns whole data as single array (like db.all
).
Current database manager.
Number of rows in this table.
Database path.
Database file name.
Root table name used while instantiating this database.
Alias of db.rowCount
.