0.0.1 • Published 4 years ago
amb-fsdb v0.0.1
fsdb (File System Database)
Simple NodeJS File System Database.
Install
npm install amb-fsdb
Use
Getting Started
const fsdb = require("amb-fsdb");
async function main() {
// Initialize & Create by default a "db.json" in current directory
const db = await fsdb();
// Create an item in a collection named "users"
// If it doesn't exist it will be created automatically
db("users").create({
name: "ambratolm",
level: 99,
inventory: ["sword", "shield", "potion"]
});
// Read all items in "users" collection
const users = db("users").read();
// Read items matching a query object
const ambUsers = db("users").read({ name: "ambratolm" });
// Read items matching a query function
const ambUsers = db("users").read(user => user.level >= 90);
// Read items matching a query with some options
const ambUsers = db("users").read(
{ name: "AmBrAtOlM" },
{
ignoreCase: true, // Ignore case when comparing strings
one: true // return only one result (an object instead of array)
}
);
}
Initialize
// Initialize with a "db.json" file in current directory
const db = await fsdb();
// Initialize with a custom named ".json" file in current directory
const db = await fsdb("my-database-file");
// Initialize with a custom named ".json" file in the specified directory
const db = await fsdb("my-database-file", "../some/directory");
CRUD Functions
Query Types
Options
0.0.1
4 years ago