v1.2.0 Stable Release

Developer Documentation

RepoDB is a performance-first, multi-tenant SQLite-as-a-Service designed to scale. By abstracting the complexities of database management into a high-speed HTTP API, we allow developers to deploy production-ready databases in seconds.

The RepoDB Architecture

Unlike traditional databases that require persistent TCP connections (which can exhaust resources on Edge runtimes like Vercel or Cloudflare), RepoDB uses a stateless REST architecture. Every query is an encrypted HTTP request, making it the perfect choice for serverless environments.


Quick Start

Get your first database running in under 60 seconds.

1 Get your Credentials

Log in to the Dashboard and generate an API Token. Note down your unique Host URL (usually https://repodb.ogensync.com).

2 Install the Library
npm install @suman-malik-repo/repodb-client
3 Run your first query
import Repodb from '@suman-malik-repo/repodb-client';

const db = new Repodb({
    host: 'https://repodb.ogensync.com',
    token: 'your_api_token_here'
});

const result = await db.execute("SELECT 'Hello World' as greeting");
console.log(result.rows[0].greeting);

Installation

The RepoDB client is a lightweight, zero-dependency wrapper around the Fetch API. It is designed to run in Node.js, Browsers, and Edge environments.

NPM
npm i @suman-malik-repo/repodb-client
Yarn
yarn add @suman-malik-repo/repodb-client
PNPM
pnpm add @suman-malik-repo/repodb-client

Configuration & Host Management

RepoDB requires explicit configuration to route your requests to the correct cluster. The host parameter is mandatory.

Option Type Requirement Description
host URL String Required The base URL of your RepoDB instance. (e.g., https://repodb.ogensync.com)
token JWT String Required Your organization or project API token.
dialect 'sqlite' | 'mysql' Optional Defaults to sqlite. Determines syntax interpretation.

CJS vs ESM Support

We provide full support for both modern ES Modules and legacy CommonJS environments.

CommonJS (Node.js default) index.js
const Repodb = require('@suman-malik-repo/repodb-client');
const db = new Repodb({ host: '...', token: '...' });

(async () => {
    const res = await db.execute("SELECT datetime('now')");
    console.log(res.rows);
})();
ES Modules (Modern / TypeScript) index.mjs
import Repodb from '@suman-malik-repo/repodb-client';

const db = new Repodb({ host: '...', token: '...', dialect: 'mysql' });
const { rows } = await db.execute("SHOW TABLES");

Client Initialization

The constructor accepts a configuration object. Using environment variables is strongly recommended.

const db = new Repodb({
    host: process.env.REPODB_HOST, 
    token: process.env.REPODB_TOKEN,
    dialect: 'mysql', // optional
    timeout: 10000    // internal fetch timeout
});

The .execute() Method

The core of the SDK. It handles parameterized queries and returns structured data.

Safe Parameterization
await db.execute("SELECT * FROM users WHERE email = ?", [userEmail]);
Batch Execution
const sql = `
    INSERT INTO logs (action) VALUES ('init');
    UPDATE session SET last_active = datetime('now');
`;
await db.execute(sql);

Response Structure

{
  "rows": [ { "id": 1, "name": "Suman" } ],
  "columns": ["id", "name"],
  "meta": {
    "duration": 25,
    "changes": 0,
    "lastInsertRowid": null
  }
}

SQLite (Default)

  • FTS5: Powerful full-text search engine.
  • JSON1: Query JSON fields using json_extract.
  • UPSERT: Using ON CONFLICT syntax.

MySQL Compatibility

Translation Layer: RepoDB translates MySQL-style identifiers (backticks) and specific date functions to their SQLite equivalents on the fly.

Direct Syntax Comparison

Feature MySQL SQLite
Quoting `backtick` "double quote"
Auto Inc INT AUTO_INCREMENT INTEGER PK AUTOINC
Date Now NOW() datetime('now')
Concat CONCAT(a, b) a || b

Transactions

RepoDB supports standard SQL transactions to ensure data integrity.

await db.execute("BEGIN TRANSACTION;");
try {
    await db.execute("UPDATE accounts SET bal = bal - 10 WHERE id = 1");
    await db.execute("UPDATE accounts SET bal = bal + 10 WHERE id = 2");
    await db.execute("COMMIT;");
} catch (e) {
    await db.execute("ROLLBACK;");
}

Error Handling

The client throws an error if the status code is not 2xx. Catch these errors to handle database constraints or network issues.

try {
    await db.execute("INSERT INTO users (id) VALUES (1)");
} catch (error) {
    console.error("Query failed:", error.message);
    // Possible errors: "UNIQUE constraint failed", "SQLITE_ERROR", etc.
}

Performance Tips

Indexing

Index every column used in WHERE and JOIN. It's the #1 speed boost for SQLite.

Avoid Roundtrips

Use multi-statement strings to combine related operations into a single network call.

Questions?
Documentation Menu