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
Selecting data
Inserting data
Deleting data
Batches
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:
Later, we realize we also want to store names. We update the same val to alter the table:
Connecting with ORMs
Writing SQL is really fast and it’s great for small projects. As your projects grow, you might want to take advantage of an ORM or query builder instead. Here are a few examples of how to do that with popular tools.
Drizzle
Prisma
Prisma isn’t supported in Val Town because it relies on functionality that only exists in a classic server environment.
Sequelize
Sequelize isn’t supported in Val Town because it relies on specific database drivers and is not extensible.
Other SQLite options
For all your other SQLite needs, you can run SQLite in WASM and save data as a blob, or use your own Turso account. See: