JavaScript Examples
Setup
No SDK needed. Use the native fetch API or any HTTP client.
js
const CELDRAX_TOKEN = process.env.CELDRAX_TOKEN // cxk_...
const DB = 'mydb'
async function query(table, body) {
const res = await fetch(`https://celdrax.com/api/${DB}/${table}`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${CELDRAX_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
})
if (!res.ok) {
const err = await res.json()
throw new Error(err.error)
}
return res.json()
}SELECT
js
// Get all active users
const { data } = await query('users', {
verb: 'select',
filters: { active: true },
orderBy: 'created_at DESC',
limit: 50,
})
console.log(data.rows) // array of rows
console.log(data.count) // number of rows returnedjs
// Get specific columns
const { data } = await query('products', {
verb: 'select',
columns: ['id', 'name', 'price'],
filters: { category: 'electronics' },
limit: 20,
})INSERT
js
const { data } = await query('users', {
verb: 'insert',
data: {
email: 'alice@example.com',
name: 'Alice',
active: true,
},
})
console.log(data.id) // auto-increment id of the new rowUPDATE
js
const { data } = await query('users', {
verb: 'update',
data: { active: false, updated_at: new Date().toISOString() },
filters: { id: 42 },
})
console.log(data.updated) // number of affected rowsDELETE
js
const { data } = await query('sessions', {
verb: 'delete',
filters: { user_id: 42 },
})
console.log(data.deleted) // number of deleted rowsError handling
js
try {
const result = await query('users', { verb: 'select' })
} catch (err) {
if (err.message.includes('REQUESTS_EXCEEDED')) {
console.error('Monthly limit reached — upgrade your plan')
} else {
console.error('Query failed:', err.message)
}
}With axios
js
import axios from 'axios'
const celdrax = axios.create({
baseURL: 'https://celdrax.com',
headers: { Authorization: `Bearer ${process.env.CELDRAX_TOKEN}` },
})
const { data } = await celdrax.post('/api/mydb/users', {
verb: 'select',
limit: 10,
})
console.log(data.data.rows)