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

peterqliu

SQLiteTable

Public
Like
SQLiteTable
Home
Code
3
README.md
main.tsx
utils
Branches
1
Pull requests
Remixes
History
Environment variables
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
7/24/2025
Viewing readonly version of main branch: v183
View latest version
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'} )

.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); } }); 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 intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
ExploreDocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.