Quickstarts

Quickstart: Database

Create a project, a table and your first query in a few minutes.

Every project is its own Postgres 17 with an auto-generated Supabase-compatible REST API. Below: a project, a migration and a query.

Variables used below: $HOSTBASE_TOKEN (access token), $REF (project ref). SDKs: @hostbase/management (TypeScript) and hostbase_management (Python); full reference at /docs/api.

1. Create a project

Generate a token (hb_pat_…) under Account → Access tokens.

curl -X POST https://host.ulewicz.space/api/v1/projects \
  -H "Authorization: Bearer $HOSTBASE_TOKEN" -H "Content-Type: application/json" \
  -d '{"name":"shop","organization_slug":"acme","region":"pl-waw-1"}'
import { Hostbase } from "@hostbase/management";
const hb = new Hostbase({ token: process.env.HOSTBASE_TOKEN! });
const project = await hb.createProject({ body: { name: "shop", organization_slug: "acme", region: "pl-waw-1" } as never });
from hostbase_management import Hostbase
hb = Hostbase(token=os.environ["HOSTBASE_TOKEN"])
project = hb.create_project(body={"name": "shop", "organization_slug": "acme", "region": "pl-waw-1"})
hostbase login
hostbase projects create shop --region pl-waw-1 --link

2. Apply a migration

Migrations are compatible with the Supabase CLI (supabase_migrations table).

curl -X POST https://host.ulewicz.space/api/v1/projects/$REF/database/migrations \
  -H "Authorization: Bearer $HOSTBASE_TOKEN" -H "Content-Type: application/json" \
  -d '{"name":"create_todos","sql":"create table todos(id bigint generated always as identity primary key, title text not null); alter table todos enable row level security;"}'
await hb.applyMigration({ ref, body: { name: "create_todos", sql: "create table todos(id bigint generated always as identity primary key, title text not null);" } as never });
hb.apply_migration(ref=ref, body={"name": "create_todos", "sql": "create table todos(id bigint generated always as identity primary key, title text not null);"})
hostbase migrations new create_todos   # edit supabase/migrations/<version>_create_todos.sql
hostbase db push

3. Query the database

Through the Management API (SQL) or through the project's REST API with the anon key.

curl -X POST https://host.ulewicz.space/api/v1/projects/$REF/database/query \
  -H "Authorization: Bearer $HOSTBASE_TOKEN" -H "Content-Type: application/json" \
  -d '{"query":"select now()"}'

# project REST API
curl "https://abcdefghijklmnopqrst.host.ulewicz.space/rest/v1/todos?select=*" -H "apikey: $ANON_KEY"
import { createClient } from "@supabase/supabase-js";
const supabase = createClient("https://abcdefghijklmnopqrst.host.ulewicz.space", process.env.ANON_KEY!);
const { data } = await supabase.from("todos").select("*");
from supabase import create_client
supabase = create_client("https://abcdefghijklmnopqrst.host.ulewicz.space", os.environ["ANON_KEY"])
print(supabase.table("todos").select("*").execute().data)
hostbase db query "select now()"
hostbase gen types typescript -o src/database.types.ts

Next: /docs/database, /docs/security/rls, /docs/pitr.