FluxbaseClient
Main Fluxbase client class
Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
Database | unknown |
_SchemaName extends string & keyof Database | string & keyof Database |
Advanced
Section titled “Advanced”Get Signature
Section titled “Get Signature”get http():
FluxbaseFetch
Get the internal HTTP client
Use this for advanced scenarios like making custom API calls or admin operations.
Example
Section titled “Example”// Make a custom API callconst data = await client.http.get('/api/custom-endpoint')Returns
Section titled “Returns”FluxbaseFetch
The internal FluxbaseFetch instance
setBeforeRequestCallback()
Section titled “setBeforeRequestCallback()”setBeforeRequestCallback(
callback):void
Register a callback that is called before every request. The callback receives the headers object and can modify it in place. This is useful for dynamically injecting headers at request time (e.g., reading tenant context from an external store).
The callback runs after static headers are merged, so it can override them.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
callback | ((headers) => void) | null | A function that receives the headers object, or null to remove |
Returns
Section titled “Returns”void
Authentication
Section titled “Authentication”getAuthToken()
Section titled “getAuthToken()”getAuthToken():
string|null
Get the current authentication token
Returns
Section titled “Returns”string | null
The current JWT access token, or null if not authenticated
setAuthToken()
Section titled “setAuthToken()”setAuthToken(
token):void
Set a new authentication token
This updates both the HTTP client and realtime connection with the new token.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
token | string | null | The JWT access token to set, or null to clear authentication |
Returns
Section titled “Returns”void
Branching
Section titled “Branching”branching
Section titled “branching”branching:
FluxbaseBranching
Branching module for database branch management
Database branches allow you to create isolated copies of your database for development, testing, and preview environments.
Example
Section titled “Example”// List all branchesconst { data } = await client.branching.list()
// Create a feature branchconst { data: branch } = await client.branching.create('feature/add-auth', { dataCloneMode: 'schema_only', expiresIn: '7d'})
// Reset branch to parent stateawait client.branching.reset('feature/add-auth')
// Delete when doneawait client.branching.delete('feature/add-auth')Database
Section titled “Database”from()
Section titled “from()”from<
T>(table):QueryBuilder<T>
Create a query builder for a database table
Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
T | unknown |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
table | string | The table name (can include schema, e.g., ‘public.users’) |
Returns
Section titled “Returns”QueryBuilder<T>
A query builder instance for constructing and executing queries
Example
Section titled “Example”// Simple selectconst { data } = await client.from('users').select('*').execute()
// With filtersconst { data } = await client.from('products') .select('id, name, price') .gt('price', 100) .eq('category', 'electronics') .execute()
// Insertawait client.from('users').insert({ name: 'John', email: 'john@example.com' }).execute()schema()
Section titled “schema()”schema(
schemaName):SchemaQueryBuilder
Access a specific database schema
Use this to query tables in non-public schemas.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
schemaName | string | The schema name (e.g., ‘jobs’, ‘analytics’) |
Returns
Section titled “Returns”SchemaQueryBuilder
A schema query builder for constructing queries on that schema
Example
Section titled “Example”// Query the logging.entries tableconst { data } = await client .schema('logging') .from('entries') .select('*') .eq('execution_id', executionId) .execute()
// Insert into a custom schema tableawait client .schema('analytics') .from('events') .insert({ event_type: 'click', data: {} }) .execute()GraphQL
Section titled “GraphQL”graphql
Section titled “graphql”graphql:
FluxbaseGraphQL
GraphQL module for executing queries and mutations
Provides a type-safe interface for the auto-generated GraphQL schema from your database tables.
Example
Section titled “Example”// Execute a queryconst { data, errors } = await client.graphql.query(` query GetUsers($limit: Int) { users(limit: $limit) { id email } }`, { limit: 10 })
// Execute a mutationconst { data, errors } = await client.graphql.mutation(` mutation CreateUser($data: UserInput!) { insertUser(data: $data) { id email } }`, { data: { email: 'user@example.com' } })Multi-Tenancy
Section titled “Multi-Tenancy”tenant
Section titled “tenant”tenant:
FluxbaseTenant
Tenant management module for multi-tenant operations
Example
Section titled “Example”// List tenants I have access toconst { data } = await client.tenant.listMine()
// Create a new tenant (instance admin only)const { data } = await client.tenant.create({ slug: 'acme-corp', name: 'Acme Corporation'})
// Get tenant detailsconst { data } = await client.tenant.get('tenant-id')
// Add a member to a tenant (tenant admin only)await client.tenant.addMember('tenant-id', { user_id: 'user-id', role: 'tenant_member'})forTenant()
Section titled “forTenant()”forTenant(
tenantId):FluxbaseClient<Database,_SchemaName>
Create a new client scoped to a specific tenant
This returns a new client instance with the tenant context set. The original client is not modified.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
tenantId | string | The tenant ID to scope to |
Returns
Section titled “Returns”FluxbaseClient<Database, _SchemaName>
A new FluxbaseClient instance scoped to the tenant
Example
Section titled “Example”// Create a tenant-scoped clientconst tenantClient = client.forTenant('tenant-uuid')
// Use the scoped client for tenant-specific operationsconst { data } = await tenantClient.from('users').select('*').execute()getTenantId()
Section titled “getTenantId()”getTenantId():
string|undefined
Get the current tenant ID
Returns the tenant ID from X-FB-Tenant header or JWT claim, or default tenant.
Returns
Section titled “Returns”string | undefined
The current tenant ID, or undefined if not set
setTenant()
Section titled “setTenant()”setTenant(
tenantId):void
Set the tenant context for all subsequent requests
This adds the X-FB-Tenant header to all HTTP requests and updates the realtime connection to filter by tenant.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
tenantId | string | undefined | The tenant ID to use for scoping |
Returns
Section titled “Returns”void
Example
Section titled “Example”// Switch to a specific tenantclient.setTenant('tenant-uuid-here')
// All subsequent requests will be scoped to this tenantconst { data } = await client.from('users').select('*').execute()admin:
FluxbaseAdmin
Admin module for instance management (requires admin authentication)
ai:
FluxbaseAI
AI module for chatbots and conversation history
auth:
FluxbaseAuth
Authentication module for user management
functions
Section titled “functions”functions:
FluxbaseFunctions
Functions module for invoking and managing edge functions
jobs:
FluxbaseJobs
Jobs module for submitting and monitoring background jobs
management
Section titled “management”management:
FluxbaseManagement
Management module for client keys, webhooks, and invitations
realtime
Section titled “realtime”realtime:
FluxbaseRealtime
Realtime module for WebSocket subscriptions
secrets
Section titled “secrets”secrets:
SecretsManager
Secrets module for managing edge function and job secrets
settings
Section titled “settings”settings:
SettingsClient
Settings module for reading public application settings (respects RLS policies)
storage
Section titled “storage”storage:
FluxbaseStorage
Storage module for file operations
rpc:
CallableRPC
RPC module for calling PostgreSQL functions - Supabase compatible
Can be called directly (Supabase-style) or access methods like invoke(), list(), getStatus()
Example
Section titled “Example”// Supabase-style direct call (uses 'default' namespace)const { data, error } = await client.rpc('get_user_orders', { user_id: '123' })
// With full optionsconst { data, error } = await client.rpc.invoke('get_user_orders', { user_id: '123' }, { namespace: 'custom', async: true})
// List available proceduresconst { data: procedures } = await client.rpc.list()Realtime
Section titled “Realtime”channel()
Section titled “channel()”channel(
name,config?):RealtimeChannel
Create or get a realtime channel (Supabase-compatible)
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
name | string | Channel name |
config? | RealtimeChannelConfig | Optional channel configuration |
Returns
Section titled “Returns”RealtimeChannel
RealtimeChannel instance
Example
Section titled “Example”const channel = client.channel('room-1', { broadcast: { self: true }, presence: { key: 'user-123' }}) .on('broadcast', { event: 'message' }, (payload) => { console.log('Message:', payload) }) .subscribe()removeChannel()
Section titled “removeChannel()”removeChannel(
channel):Promise<"ok"|"error">
Remove a realtime channel (Supabase-compatible)
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
channel | RealtimeChannel | The channel to remove |
Returns
Section titled “Returns”Promise<"ok" | "error">
Promise resolving to status
Example
Section titled “Example”const channel = client.channel('room-1')await client.removeChannel(channel)Vector Search
Section titled “Vector Search”vector
Section titled “vector”vector:
FluxbaseVector
Vector search module for pgvector similarity search
Provides convenience methods for vector similarity search:
embed()- Generate embeddings from textsearch()- Search for similar vectors with auto-embedding
Example
Section titled “Example”// Search with automatic embeddingconst { data } = await client.vector.search({ table: 'documents', column: 'embedding', query: 'How to use TypeScript?', match_count: 10})
// Generate embeddingsconst { data } = await client.vector.embed({ text: 'Hello world' })Note: For more control, use the QueryBuilder methods:
vectorSearch()- Filter and order by vector similarityorderByVector()- Order results by vector distance