Client
Create and manage database connections
Creating a Client
import { createClient } from "toollessdb";
const client = createClient({ path: "./data" });You can also pass a string directly:
const client = createClient("./data");Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
path | string | Required | Path to database directory |
The path can be relative or absolute. Toolless will create the directory if it doesn't exist.
Methods
db(name)
Get a database instance:
const db = client.db("myapp");If the database directory doesn't exist, it will be created automatically as myapp.tdb/ inside your data path.
listDatabases()
List all databases:
const databases = await client.listDatabases();
// ['myapp', 'test', 'analytics']close()
Close the client connection:
await client.close();Always close the client when done to ensure all data is flushed to disk.
Complete Example
import { createClient } from "toollessdb";
async function main() {
const client = createClient({ path: "./data" });
const databases = await client.listDatabases();
console.log("Databases:", databases);
const db = client.db("myapp");
const users = db.collection("users");
await users.insertOne({ name: "Alice" });
await client.close();
}
main();