Supabase
Supabase provide a hosted Postgres database with 500MB of storage in the free tier.
You can query and create data inside your vals using either Supabase’s JavaScript SDK, or a Postgres client.
Using the SDK
1. Sign up to Supabase
Visit https://supabase.com/dashboard/sign-up.
2. Create a project
On Supabase’s dashboard, create a new project.
3. Get your API URL and service role key
Go to your project’s Settings via the sidebar. Inside API, scroll down
and copy the Project URL, and then, inside Project API Keys, copy the
service role secret. Save these as two separate
Val Town environment variables as supabaseURL
and
supabaseKey
respectively.
4. Create your first table
Head to the Table editor in the sidebar.
Create a new table called my_first_table
with the following schema.
5. Insert some data
Copy and paste the following val to insert some data.
6. Query back that data
Get back the data you just inserted by using eq()
(like SQL’s WHERE
).
7. Keep going!
Use Supabase’s JavaScript Client library documentation to write more queries!
Using a Postgres client
1. Sign up to Supabase
Visit https://supabase.com/dashboard/sign-up.
2. Create a project
On Supabase’s dashboard, create a new project.
Keep a note of your database password, you’ll need this to create a database connection string.
3. Get your database’s connection string
Go to your project’s Settings via the sidebar. Inside Database, scroll
down and copy the Connection string for Nodejs. Replace
[YOUR-PASSWORD]
(removing the square brackets) with your database password
(alternatively, reset your database password to create a new one).
Save this connection string as a
Val Town environment variable as supabasePostgres
.
4. Create your first table
Copy and paste this val to create a table with the given schema.
5. Insert some data
Use a prepared statement like below to prevent SQL injection.
6. Query back that data
Usually, you’ll just want the rows
property from the response.
7. More resources
Learn more about the Deno Postgres client used in this guide, view the Supabase Database documentation, or get help on Val Town’s Discord.