Supabase

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

2. Create a project

On Supabase’s dashboard, create a new project.

image

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 key. Save these as two separate Val Town secrets as supabaseURL and supabaseKey respectively.

image

4. Create your first table

Head to the Table editor in the sidebar.

image

Create a new table called my_first_table with the following schema.

image

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

2. Create a project

On Supabase’s dashboard, create a new project.

image

Keep a note of your database password, you’ll need this to create a database connection string.

image

3. Get your database’s connection string

image

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 secret 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.