Skip to content
Classplugin-kyselyv0.9.0

KyselyService

Base class for Kysely services.

Provides a small, typed shim around the shared Kysely instance and ensures that subclasses have been decorated with @RegisterKyselyService.

abstract class KyselyService<
    TTable extends LiteralUnion<KyselyTable, string> =
        KyselyTable
>
\@RegisterKyselyService('users')
export class UsersService extends KyselyService<'users'> {
  public async findById(id: string) {
    return this.db
      .selectFrom(this.table)
      .selectAll().where('id', '=', id)
      .executeTakeFirst();
  }
}

// Usage inside handlers:
const user = await this.core.db.services.users.findById('abc');

Member visibility

Filter class members by access level.

constructor

Constructs a new instance of the KyselyService class

KyselyService(kysely: Kysely, core: CoreBase)

Showing members with Protected visibility and higher.

kysely

protected readonly kysely: Kysely

table

public readonly table: TTable