ToollessToolless

Client

Create and manage database connections

Creating a Client

app.ts
import { createClient } from "toollessdb";

const client = createClient({ path: "./data" });

You can also pass a string directly:

app.ts
const client = createClient("./data");

Configuration Options

OptionTypeDefaultDescription
pathstringRequiredPath 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:

app.ts
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:

list-dbs.ts
const databases = await client.listDatabases();
// ['myapp', 'test', 'analytics']

close()

Close the client connection:

cleanup.ts
await client.close();

Always close the client when done to ensure all data is flushed to disk.

Complete Example

example.ts
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();

On this page