SDK
Use the SparkDB JavaScript/TypeScript client with your database connection URL and API key.
@shellhaki/sparkdb-sdk
API key
Postgres, MySQL, MongoDB
ORM helpers + raw queries
Install
1npm install @shellhaki/sparkdb-sdkQuick Start
1import { client } from '@shellhaki/sparkdb-sdk';23type User = {4 id: number;5 email: string;6 name: string | null;7};89const db = new client(10 process.env.SPARK_DATABASE_URL!,11 process.env.SPARK_API_KEY!12);1314await db.from<User>('users').insert({15 email: 'ada@sparkdb.pro',16 name: 'Ada'17});1819const users = await db20 .from<User>('users')21 .where({ email: 'ada@sparkdb.pro' })22 .limit(1)23 .select();Database Examples
Postgres
Postgres supports typed table creation, row helpers, and raw SQL through db.query().
1import { client } from '@shellhaki/sparkdb-sdk';23const postgres = new client(process.env.POSTGRES_URL!, process.env.SPARK_API_KEY!);45await postgres.createTable('users', [6 { name: 'id', type: 'serial', primaryKey: true },7 { name: 'email', type: 'text' },8 { name: 'name', type: 'text', nullable: true },9 { name: 'created_at', type: 'timestamp', nullable: true }10]);1112await postgres.from('users').insert({13 email: 'ada@sparkdb.pro',14 name: 'Ada Lovelace'15});1617const users = await postgres18 .from('users')19 .where({ email: 'ada@sparkdb.pro' })20 .select();2122const raw = await postgres.query('select id, email from users limit 10');API Reference
new client(databaseUrl, apiKey, options?)
Create a database-scoped SDK client.
db.from('table').select()
Read rows or Mongo documents. Chain where and limit first.
db.from('table').insert(values)
Insert one SQL row or Mongo document.
db.from('table').where(filter).update(values)
Update matching rows or documents.
db.from('table').where(filter).delete()
Delete matching rows or documents.
db.createTable(name, columns, mongoSchema?)
Create a SQL table or Mongo collection.
db.dropTable(name)
Drop a SQL table or Mongo collection.
db.schema()
Load tables, columns, collections, and inferred schema.
db.query(query)
Run SQL for Postgres/MySQL or a JSON Mongo command string.
| Call | Use |
|---|---|
| new client(databaseUrl, apiKey, options?) | Create a database-scoped SDK client. |
| db.from('table').select() | Read rows or Mongo documents. Chain where and limit first. |
| db.from('table').insert(values) | Insert one SQL row or Mongo document. |
| db.from('table').where(filter).update(values) | Update matching rows or documents. |
| db.from('table').where(filter).delete() | Delete matching rows or documents. |
| db.createTable(name, columns, mongoSchema?) | Create a SQL table or Mongo collection. |
| db.dropTable(name) | Drop a SQL table or Mongo collection. |
| db.schema() | Load tables, columns, collections, and inferred schema. |
| db.query(query) | Run SQL for Postgres/MySQL or a JSON Mongo command string. |