JavaScript / TypeScript SDK

The official AetherDB SDK for JavaScript and TypeScript — works in Node.js and the browser.

Installation

npm install aetherdb-js

Initialisation

import { AetherDB } from 'aetherdb-js'

// With an existing token
const db = new AetherDB({
  url: 'https://aetherdb.cloud',
  token: 'your-jwt-token'
})

// Or sign in directly
const db = new AetherDB({ url: 'https://aetherdb.cloud' })
await db.signIn('you@example.com', 'your-password')

Authentication methods

register(email, password)

Create a new account. An isolated Postgres schema is provisioned automatically.

const user = await db.register('you@example.com', 'password')
// { id: 1, email: '...', schema: 'tenant_1' }

signIn(email, password)

Sign in and automatically set the token for subsequent requests.

const { access_token, user } = await db.signIn('you@example.com', 'password')

setToken(token)

Manually set a JWT token.

db.setToken('eyJhbGci...')

Database methods

from(table)

Returns a QueryBuilder for the given table in your isolated schema.

const { rows } = await db.from('products').select('*').execute()

createTable(name, columns)

Create a new table in your schema.

await db.createTable('orders', [
  { name: 'product_id', type: 'BIGINT',  nullable: false },
  { name: 'quantity',   type: 'INTEGER', nullable: false },
  { name: 'total',      type: 'NUMERIC', nullable: false },
])

query(sql)

Run a raw SELECT query in your isolated schema.

const { rows } = await db.query('SELECT COUNT(*) FROM products')

ai(question)

Natural language query — generates and executes SQL automatically.

const result = await db.ai('how many orders were placed today?')
console.log(result.generated_sql)
console.log(result.rows)

Tenant methods

getTenantInfo()

const info = await db.getTenantInfo()
// {
//   schema: 'tenant_42',
//   connection_string: 'postgres://...',
//   host: 'aetherdb.cloud',
//   port: 5432
// }

getSchema()

const { tables } = await db.getSchema()
// [{ name: 'products', columns: [...] }]

TypeScript support

Full TypeScript support with generic query results.

interface Product {
  id: number
  title: string
  price: number
}

const { rows } = await db.from('products').select('*').execute<Product>()
// rows is Product[]