• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
peterqliu

peterqliu

SQLiteTable

Public
Like
SQLiteTable
Home
Code
6
README.md
H
client.ts
debug.tsx
http.tsx
main.tsx
utils
Environment variables
Branches
1
Pull requests
Remixes
History
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
README.md
Code
/
README.md
Search
…
README.md

SQLiteTable

A thin abstraction over SQLite, to work with tables from vals. All methods async.

Usage

new SQLiteTable("myTable") .create({ id: "unique primary key", title: "text", body: "text", created: "integer", });

API

Basics

new SQLiteTable(title:string)

Start an instance of SQLiteTable.

.create(scheme:TableScheme)

Create this table in your VT SQLite storage. scheme is a JSON with column names as keys, and definitions as values (see above for example). Run this only once per table.

.drop()

Drop this table from your VT SQLite storage.

.exists()

Returns whether this table exists in storage.

Table operations

.insertRow(rowData)

Add a new row to your table. rowData is a JSON with column names as keys, and row values as values.

table.insertRow({ id: 1234, title: "Post title", body: "Post body", created: 12345678, });

.getRow(conditions?, options?)

Returns the first row matching the given conditions.

conditions: Either a JSON object of column conditions, or a raw SQL WHERE clause as a string.

options (optional):

json (default false): Return a plain JS object instead of raw DB output.

table.getRow({ id: 1234, title: "Post title", });

.getRows(conditions?, options?)

Same, except returns all matching rows.

.countRows(conditions?)

Returns a count of all rows in the table that match the condition.

.deleteRows(conditions?)

Deletes all rows in the table that match the condition.

.updateRow(conditions?, rowData)

Modifies all rows in the table that match the condition. rowData is a JSON of key-value pairs to change; it does not affect any columns not mentioned.

table.updateRow( { id: 1234 }, { title: "New title! The existing body text is not mentioned here so it is unaffected", }, );

.getDescending({ by, limit? }, options?)

Returns rows sorted by by in descending order, optionally capped at limit rows.

options (optional):

  • excludedValue: Exclude rows where by equals this value.
  • json (default false): Return plain JS objects instead of raw DB output.
table.getDescending({ by: "created", limit: 10 });

.getAscending({ by, limit? }, options?)

Same, but sorted in ascending order.

table.getAscending({ by: "created", limit: 10 });

.streamRowBatches(onBatch: Function)

Iterate over all rows in batches of 1000, passing each batch to onBatch.

await table.streamRowBatches((batch) => { for (const row of batch) { console.log(row); } });

.http(req: Request): Promise<Response>

Exposes read operations (getRow, getRows, countRows, getInfo) as an HTTP handler, so your table can be queried directly over the network. Useful for building lightweight read APIs on top of your SQLite data without writing custom routing logic.

Pass it as the handler in an HTTP val, bound to the table instance:

import { SQLiteTable } from "https://esm.town/v/peterqliu/SQLiteTable/main.tsx"; const table = new SQLiteTable("posts"); export default (req: Request) => table.http(req);

Then query it via URL. The last path segment selects the operation, and query params become row conditions:

GET /getRows?title=Hello
GET /getRow?id=1234
GET /countRows?created=12345678

Use _columns to limit which columns are returned:

GET /getRows?_columns=id,title

Utilities

.AISuggestCmd(plainText: string): Promise<string>

Use AI to generate a suggested SQLite command for a given text description of your intent.

const cmd = await table.AISuggestCmd( "show me all active users sorted by join date", );
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.