0.1.1 ā€¢ Published 8 months ago

flow.db v0.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

flow.db

šŸ’» A lightweight Node.js package that uses the better-sqlite3 library to manage an SQLite database.

Installation

šŸ“¦ Add this to your project using your preferred package manager:

npm install flow.db

or

pnpm add flow.db

or

yarn add flow.db

Example Usage

šŸ› ļø Below is a mini-tutorial on how to use flow.db.

Setup

const { Database } = require("flow.db");

// Default configuration.
// Creates db.sqlite in the root folder & WAL disabled
const db = new Database();

// Enable WAL:
const db = new Database({ wal: true });

// Custom path:
const db = new Database({ path: "/path/to/db.sqlite" });

// Readonly:
const db = new Database({ readonly: true, path: `/path/to/db.sqlite` });

Tables

// Create a table.
db.createTable("table");
db.createTable("users");

// Delete a table.
db.deleteTable("table");

// Rename a table
db.renameTable("table", "myTable");

Handling Data

// Assign a value to a key.
db.set("myKey", { data: "myData" });
db.set("balance", 1000);

// Assign a value to a key in a table.
// Here, the table's name is "users".
// Note: You need to run `db.createTable("table_name")` first.
db.set("admin", { username: "admin", id: 1 }, "users");

// Retrieve a value by key.
const value = db.get("myKey");
const value2 = db.get("balance");

console.log(value); // => { data: "myData" }
console.log(value2); // => 1000

// Delete a key.
db.delete("myKey");

All Data

// Get all data from a table.
// Tables are optional ā€” the name of the default table is "main".
const allData = db.all();
console.log(allData);
/*
[
  { table: 'main', key: 'myKey', value: { data: 'myData' } },
  { table: 'main', key: 'balance', value: 1000 }
]
*/

// All data in a table:
const allUsers = db.all("users");
console.log(allUsers);

/*
[
  { table: 'users', key: 'admin', value: { username: 'admin', id: 1 } }
]
*/

Clearing

// Clear all data from all tables.
db.clear();

// Clear all data from a specific table.
db.clearTable("myTable");
0.1.1

8 months ago

0.1.0

8 months ago

0.0.8

8 months ago

0.0.7

8 months ago

0.0.5

8 months ago

0.0.4

8 months ago

0.0.3

8 months ago

0.0.2

8 months ago

0.0.1

8 months ago