Val Town comes with SQLite built-in. You can store store and query any relational data. It’s backed by Turso.

You can store 10mb on the free plan and up to 1gb on the paid plan. Contact us if you need more.

Running some simple queries

These are the simplest ways to run queries, by directly sending SQL to the database. We can build on top of these vals, but they’re essential to understand.

Creating tables

https://www.val.town/embed/andreterron/createSqliteTable

Selecting data

https://www.val.town/embed/andreterron/selectFromSqlite

Inserting data

https://www.val.town/embed/andreterron/insertIntoSqlite

Deleting data

https://www.val.town/embed/andreterron/deleteFromSqlite

Batches

https://www.val.town/embed/andreterron/batchSqlite

Migrations

Migrations can be difficult in traditional server environments: you need to execute some SQL, but this should only happen once. In Val Town, managing migrations is easy.

The best way to run migrations in Val Town is to write a single val and keep updating it with each migration. Because vals have versions, each version of a val is run exactly once.

Let’s look at an example…

In our first migration, we create a users table: