Models & Schema
Quickstart
-
Install the CLI and SDK
See the Installation guide to install the CLI and your preferred SDK.
-
Login and initialize your project
Terminal window pulsabase login # Opens browser for authenticationpulsabase init # Create or link a project, saves .pulsabase/config.jsonThis generates a
config.tsfile and a local.pulsabase/config.jsonthat the CLI uses for all subsequent commands. -
Initialize the client
src/pulsabase.ts import { PulsaClient } from '@pulsabase/sdk';import User from './models/User';const pb = new PulsaClient({engineUrl: 'https://api.yourproject.pulsabase.io',apiKey: 'pk_live_your_api_key',auth: {clientId: 'your-client-id',},models: [User], // Register your models for type-safe queries});export default pb;lib/pulsabase.dart import 'package:pulsabase/pulsabase.dart';final pb = PulsaClient(PulsabaseClientOptions(engineUrl: 'https://api.yourproject.pulsabase.io',apiKey: 'pk_live_your_api_key',clientId: 'your-client-id',)); -
Define a model and sync the schema
src/models/User.ts import { primary, text, ModelSchema } from 'pulsabase';export default class User {@primary id: string;@text(false) name: string;@text(false) email: string;static schema: ModelSchema = {tableName: 'users',timestamps: true,};}Terminal window # Preview changespulsabase db:sync --dry-run# Apply migrationspulsabase db:syncTerminal window # Pull the existing database schema as Dart modelspulsabase db:pull -
Query your data
import pb from './pulsabase';import User from './models/User';const users = await pb.from(User).where('status', 'active').orderBy('name', 'asc').limit(20).find();final users = await pb.from('users').where('status', 'active').orderBy('name', ascending: true).limit(20).find();Terminal window curl -X POST https://api.yourproject.pulsabase.io/v1/query \-H "X-Api-Key: pk_live_your_api_key" \-H "Content-Type: application/json" \-d '{"action":"find","table":"users","query":{"status":"active"},"sort":[{"field":"name","order":"asc"}],"limit":20}' -
Authenticate a user
import pb from './pulsabase';// Sign up a new userawait pb.auth.signUpWithPassword('user@email.com', 'StrongPassword123!');// Sign in an existing userawait pb.auth.signInWithPassword('user@email.com', 'StrongPassword123!');// Access the current user's profileconst user = await pb.auth.getUser();console.log(`Hello, ${user.given_name}`);// Sign inawait pb.auth.signInWithPassword('user@email.com', 'StrongPassword123!');// Access the current userfinal user = await pb.auth.getUser();print('Hello, ${user.givenName}'); -
Listen to real-time changes
import pb from './pulsabase';import User from './models/User';// Listen to all INSERT events on the users tableconst unsubscribe = pb.on(User).insert().listen((change) => {console.log('New user:', change.data);});// Clean upunsubscribe();final sub = pb.listen((msg) => print('New user: ${msg.data}'),filterTable: 'users',filterAction: 'INSERT',);// Unsubscribesub();
Next Steps
Section titled “Next Steps”Queries
Authentication
Real-Time
Edge Functions
CLI Reference