Skip to content

Quickstart

  1. Install the CLI and SDK

    See the Installation guide to install the CLI and your preferred SDK.

  2. Login and initialize your project

    Terminal window
    pulsabase login # Opens browser for authentication
    pulsabase init # Create or link a project, saves .pulsabase/config.json

    This generates a config.ts file and a local .pulsabase/config.json that the CLI uses for all subsequent commands.

  3. 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;
  4. 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 changes
    pulsabase db:sync --dry-run
    # Apply migrations
    pulsabase db:sync
  5. 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();
  6. Authenticate a user

    import pb from './pulsabase';
    // Sign up a new user
    await pb.auth.signUpWithPassword('user@email.com', 'StrongPassword123!');
    // Sign in an existing user
    await pb.auth.signInWithPassword('user@email.com', 'StrongPassword123!');
    // Access the current user's profile
    const user = await pb.auth.getUser();
    console.log(`Hello, ${user.given_name}`);
  7. Listen to real-time changes

    import pb from './pulsabase';
    import User from './models/User';
    // Listen to all INSERT events on the users table
    const unsubscribe = pb.on(User)
    .insert()
    .listen((change) => {
    console.log('New user:', change.data);
    });
    // Clean up
    unsubscribe();