Skip to content

Tables (Tier 2)

import { Aside } from ‘@astrojs/starlight/components’;

Structured records — tasks, leads, entries — with a query builder. Access via sdk.table(name).

insert(doc): Promise<T>
insertMany(docs): Promise<T[]>
findById(id): Promise<T | null>
findOne(filter): Promise<T | null>
find(filter?): Query<T> // chainable
updateById(id, changes): Promise<T | null>
update(filter, changes): Promise<{ updated: number }>
deleteById(id): Promise<boolean>
delete(filter): Promise<{ deleted: number }>
count(filter?): Promise<number>
distinct(field, filter?): Promise<value[]>
find(filter).filter(f).sort(field, 'asc' | 'desc').limit(n).skip(n).select(fields).exec()

Filter operators: $eq $ne $gt $gte $lt $lte $in $nin $contains $startsWith $endsWith.

const tasks = sdk.table('tasks');
await tasks.insert({ title: 'Build', status: 'pending', priority: 1 });
const urgent = await tasks
.find({ status: { $in: ['pending', 'active'] }, priority: { $lte: 2 } })
.sort('priority', 'asc')
.limit(10)
.exec();
const pending = await tasks.count({ status: 'pending' });
const statuses = await tasks.distinct('status');
<script type="shareout/manifest">
{
"version": "2.0",
"sources": {
"tables": {
"tasks": {
"schema": [
{ "name": "id", "type": "string", "primary": true },
{ "name": "title", "type": "string" },
{ "name": "status", "type": "string" },
{ "name": "priority", "type": "number" }
]
}
}
}
}
</script>
  • Fetch once at app root; pass data down as props.
  • Paginate large sets with .limit(50).
  • After mutations, sdk.invalidateTableCache('tasks').