create-appncy
Version:
Create projects as goncy would
45 lines (34 loc) • 1.2 kB
Markdown
Instructions on how to setup db on the app.
[](https://database.new/) and add the following variables to the `.env.local` file:
```bash
NEXT_PUBLIC_SUPABASE_URL=
NEXT_PUBLIC_SUPABASE_KEY=
SUPABASE_ACCESS_TOKEN=
```
> Also create the schema and tables you need for the app now, we will generate types later and this is needed.
Install the Supabase client in your project:
```bash
pnpm add @supabase/supabase-js
```
Run the `gen types` command in your terminal specifying the project id:
```bash
pnpx supabase login
pnpx supabase gen types typescript --project-id yourprojectid > ./src/db/types.ts
```
> Run this command anytime your schema changes.
import the respective clients (server and client) from the `db` folder and use them in your app:
```ts
import db from "@/db/api/server";
async function getMatches() {
const {data: matches, error} = await supabase
.from("matches")
.select()
.order("date", {ascending: false});
return matches ?? [];
}
```