Skip to content

SupabaseRepository

Defined in: supabase-repository.ts:57

Abstract base class for Supabase-backed repositories.

Extend this class and set tableName to implement a Mantle Repository<T> backed by a Supabase (PostgreSQL) table via the Supabase JS client.

class UserRepository extends SupabaseRepository<User> {
readonly tableName = "users";
async findByEmail(email: string): Promise<User | null> {
const { data, error } = await this.db.select("*").eq("email", email).maybeSingle();
if (error) throw this.wrapError(error);
return data ?? null;
}
}

T extends Record<string, unknown>

D = Partial<T>

new SupabaseRepository<T, D>(app): SupabaseRepository<T, D>

Defined in: supabase-repository.ts:89

MantleApplication

SupabaseRepository<T, D>

protected readonly app: MantleApplication

Defined in: supabase-repository.ts:61


protected readonly client: SupabaseClient

Defined in: supabase-repository.ts:60


readonly listenToChanges: boolean = false

Defined in: supabase-repository.ts:87

When true, subscribes to Postgres Changes for this table and re-emits direct DB mutations (PostgREST, migrations, Supabase Studio) as Mantle service:event emissions on the app event bus. These emissions carry { external: true } as their params so consumers can distinguish them from hook-pipeline events; external UPDATEs always map to "patched".

false

readonly primaryKey: string = "id"

Defined in: supabase-repository.ts:70

The primary key column name.

"id"

abstract readonly tableName: string

Defined in: supabase-repository.ts:64

Supabase table name.


readonly timestamps: boolean = true

Defined in: supabase-repository.ts:77

When true, save / saveAll / updateById / patchById automatically write created_at and updated_at ISO-8601 timestamps.

true

get protected db(): AnyQuery

Defined in: supabase-repository.ts:153

Returns a query builder scoped to this repository’s table. Useful for writing custom queries in subclasses.

AnyQuery

protected applyParams(query, params?): AnyQuery

Defined in: supabase-repository.ts:176

Apply QueryParams filters, sorting, and pagination to a query builder. Subclasses may call this to re-use the standard filter logic in custom queries.

AnyQuery

QueryParams

AnyQuery


count(params?): Promise<number>

Defined in: supabase-repository.ts:477

QueryParams

Promise<number>

Repository.count


deleteById(id): Promise<T>

Defined in: supabase-repository.ts:456

Id

Promise<T>

Repository.deleteById


describe(): RepositoryCapabilities

Defined in: supabase-repository.ts:341

Optional capability introspection. All

RepositoryCapabilities

adapters implement it; user repositories may omit it.

Repository.describe


findAll(params?): Promise<T[]>

Defined in: supabase-repository.ts:353

QueryParams

Promise<T[]>

Repository.findAll


findById(id): Promise<T | null>

Defined in: supabase-repository.ts:369

Id

Promise<T | null>

Repository.findById


patchById(id, data): Promise<T>

Defined in: supabase-repository.ts:432

Id

D

Promise<T>

Repository.patchById


save(data): Promise<T>

Defined in: supabase-repository.ts:383

D

Promise<T>

Repository.save


saveAll(data): Promise<T[]>

Defined in: supabase-repository.ts:398

D[]

Promise<T[]>

Repository.saveAll


updateById(id, data): Promise<T>

Defined in: supabase-repository.ts:413

Id

D

Promise<T>

Repository.updateById


protected wrapError(err): Error

Defined in: supabase-repository.ts:504

unknown

Error