Skip to content

Repository files navigation

@vidkit-ai/nest-supabase

NestJS module for Supabase, exposing the Supabase JavaScript client (database, auth, storage, realtime).

Install

npm install @vidkit-ai/nest-supabase
# or
pnpm add @vidkit-ai/nest-supabase

Peer dependencies: @nestjs/common, @nestjs/core (v10 or v11).

Usage

Register with static options

// app.module.ts
import { Module } from "@nestjs/common";
import { NestSupabaseModule } from "@vidkit-ai/nest-supabase";

@Module({
  imports: [
    NestSupabaseModule.forRoot({
      supabaseUrl: process.env.SUPABASE_URL!,
      supabaseKey: process.env.SUPABASE_ANON_KEY!,
    }),
  ],
})
export class AppModule {}

Optional: make the module global:

NestSupabaseModule.forRoot({
  supabaseUrl: process.env.SUPABASE_URL!,
  supabaseKey: process.env.SUPABASE_ANON_KEY!,
  isGlobal: true,
});

Register with async options (e.g. ConfigService)

import { Module } from "@nestjs/common";
import { ConfigModule, ConfigService } from "@nestjs/config";
import { NestSupabaseModule } from "@vidkit-ai/nest-supabase";

@Module({
  imports: [
    NestSupabaseModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (config: ConfigService) => ({
        supabaseUrl: config.getOrThrow("SUPABASE_URL"),
        supabaseKey: config.getOrThrow("SUPABASE_ANON_KEY"),
      }),
    }),
  ],
})
export class AppModule {}

forRootAsync also supports useClass and useExisting.

Fetch data with select()

Inject NestSupabaseService and use .client to run queries. The client supports the full Supabase JavaScript API, including select.

import { Injectable } from "@nestjs/common";
import { NestSupabaseService } from "@vidkit-ai/nest-supabase";

@Injectable()
export class CharactersService {
  constructor(private readonly supabase: NestSupabaseService) {}

  async getAll() {
    const { data, error } = await this.supabase.client
      .from("characters")
      .select();
    if (error) throw error;
    return data;
  }

  async getColumns() {
    const { data, error } = await this.supabase.client
      .from("characters")
      .select("name");
    if (error) throw error;
    return data;
  }

  async getWithRelations() {
    const { data, error } = await this.supabase.client.from(
      "orchestral_sections",
    ).select(`
        name,
        instruments (name)
      `);
    if (error) throw error;
    return data;
  }

  async getWithFilters() {
    const { data, error } = await this.supabase.client
      .from("characters")
      .select("name")
      .eq("status", "active")
      .limit(10);
    if (error) throw error;
    return data;
  }
}
  • Select all columns: .select() or .select('*')
  • Select specific columns: .select('id, name')
  • Joins / relations: use nested select like instruments (name)
  • Filters: .eq(), .neq(), .gt(), .gte(), .lt(), .lte(), .like(), .in(), etc.
  • Modifiers: .order(), .limit(), .range(), .single(), .maybeSingle()

See Fetch data (select), Using filters, and Using modifiers.

TypeScript

For typed tables, generate types and pass them to createClient in your app, or use the service’s .client and cast as needed. The library re-exports SupabaseClient for typing.

Publish to npm

npm install
npm run build
npm publish

This package is scoped (@vidkit-ai/nest-supabase) and has "publishConfig": { "access": "public" }.

License

MIT