Skip to main content

Overview

The gdb() function is an async factory function that creates and configures a GenosDB database connection. It serves as the entry point for all GenosDB operations.

Signature

await gdb(name: string, options?: DatabaseOptions): Promise<GDB>

Parameters

name
string
required
Database name used for local storage and P2P synchronization.
options
object
Configuration options for the database instance.

Return Value

db
GDB
A configured GenosDB instance ready for data operations.

Examples

Basic Initialization

import { gdb } from "genosdb"

const db = await gdb("my-db")

With Password Encryption

const secureDb = await gdb("secure-db", { 
  password: "secret" 
})

Enable P2P Networking

const db = await gdb("my-db", { 
  rtc: true 
})

Custom Relay Configuration

const db = await gdb("my-db", {
  rtc: {
    relayUrls: ["wss://relay1.example.com", "wss://relay2.example.com"]
  }
})

TURN Server Configuration

const db = await gdb("my-db", {
  rtc: {
    turnConfig: [
      {
        urls: ["turn:your-turn-server.ok:1979"],
        username: "username",
        credential: "password"
      }
    ]
  }
})

Cellular Mesh for Massive Scale

// Default cellular mesh
const db = await gdb("my-db", {
  rtc: { cells: true }
})

// Custom cellular configuration
const db = await gdb("my-db", {
  rtc: {
    cells: {
      cellSize: "auto",
      bridgesPerEdge: 2,
      maxCellSize: 50,
      targetCells: 100,
      debug: false
    }
  }
})

Enable Security Manager

const db = await gdb("my-db", {
  rtc: true, // Required for SM
  sm: {
    superAdmins: ["0x1234...", "0x5678..."]
  }
})

Enable Multiple Modules

const db = await gdb("my-db", {
  rtc: true,
  nlq: true,  // Natural Language Queries
  rx: true,   // Radix Index
  geo: true,  // Geo-spatial queries
  audit: { 
    prompt: "detect offensive or inappropriate language" 
  }
})

Performance Tuning

const db = await gdb("my-db", {
  saveDelay: 500,   // Reduce disk writes
  oplogSize: 100    // Support longer offline periods
})

Best Practices

Use top-level await in modern environments (<script type="module">) to avoid unnecessary async function wrappers:
// ✅ Recommended
import { gdb } from "genosdb"
const db = await gdb("my-app")

// ❌ Avoid unless needed for user actions
async function init() {
  const db = await gdb("my-app")
}
When enabling the Security Manager, rtc: true is required as SM relies on the Real-Time Communication module for cryptographic signing and verification of P2P operations.