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
- 3. Get your API URL and service role key
- 4. Create your first table
- 5. Insert some data
- 6. Query back that data
- 7. Keep going!
- Using a Postgres client
- 1. Sign up to Supabase
- 2. Create a project
- 3. Get your database’s connection string
- 4. Create your first table
- 5. Insert some data
- 6. Query back that data
- 7. More resources
Using the SDK
1. Sign up to Supabase
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
key. Save these as two separate Val Town secrets as service role
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
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 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.