Skip to content

k.DB

Database operations - unified CRUD interface supporting multiple databases

Overview

k.DB provides access to Kooboo's built-in database, supporting:

  • IndexedDB (site dynamic table) — the background IndexedDB Tables page creates the table, and the script uses k.DB.indexedDb.{table name}
  • SQLite — works out of the box, no configuration required
  • MySQL / SQL Server — The connection string must be configured in the service integration (see MySQL Tables and SQL Server Tables in the admin UI)

Submodules

moduleDescription
k.DB.indexedDbSite IndexedDB dynamic table (object CRUD)
k.DB.keyValueSite key-value pairs
k.DB.sqliteSQLite(SQL)

TypeScript definition

ts
interface KDB {
    /** Site IndexedDB dynamic tables (table name as property) */
    indexedDb: IDatabase;
    sqlite: SQLiteDB;
    mysql: MysqlDatabase;
    sqlServer: SqlServerDatabase;
}

interface SQLiteDB {
    /** Get all table names in the database */
    getTables(): string[];
    /** Get the specified table object */
    getTable(name: string): ITable;
    /** Query data and return an array */
    query(sql: string, params?: object): any[];
    /** Execute a write operation and return a number (1 = success) */
    execute(sql: string, params?: object): number;
    /** Get the query operator set */
    operators(): Operators;
    /** Execute multiple operations in a transaction */
    transaction(action: Function): void;
}

Selection suggestions

  • The IndexedDB table has been built in the background and we hope to use objects to read and writek.DB.indexedDb
  • Simple string key value, no table structurek.DB.keyValue
  • Requires handwriting SQL or operating SQLite file tablesk.DB.sqlite
  • Connecting to MySQL / SQL Server → After configuring the connection, use k.DB.mysql / k.DB.sqlServer; see CMS Database