# Kysely

`class` in `plugin-kysely` · v0.9.0

<https://seedcord.org/docs/packages/plugin-kysely/0.9.0/classes/kysely>

Connects a bot to any database that Kysely has a dialect for.

Opens the connection, runs your migrations, and loads your service classes.

```ts
class Kysely extends Plugin<{
    transport: "any";
    runtime: "server";
}>
```

## Constructors

### constructor

```ts
Kysely(host: CoreBase, options: KyselyOptions)
```

Constructs a new instance of the `Kysely` class

## Properties

### connection

```ts
public get connection(): Kysely<KyselySchema>
```

The Kysely instance that the plugin built from your dialect.

### core

```ts
protected core: TCore
```

The host, typed to the transport whose `Plugin` base this class extends.

### dispatchMembers

```ts
readonly dispatchMembers?: DispatchMemberFunctions
```

Adds values that every handler can read. Each key becomes a member, like `this.tag`, and its
function returns the value. Gates and `Notice.render` read the same values on `ctx`.

Seedcord calls each function once per interaction, and once per event that has a handler.

`attach()` throws if seedcord already uses one of these keys, like `reply`, if another plugin on the
bot uses it, or if the bot attaches this plugin twice.

### id

```ts
public static readonly id
```

### kv

```ts
protected kv: Kv
```

This plugin's records in the bot's `config.kv`, stored under its attach key. Two attachments of
one plugin class each get their own records. Renaming the attach key leaves the records under
the old key behind.

### logger

```ts
protected readonly logger: Logger
```

Logs under the plugin's class name, on the channel its attach key sets.

### services

```ts
public get services(): KyselyServices
```

Your services, keyed by the name you pass to `@RegisterKyselyService`.

## Methods

### codegen

```ts
public override async codegen(): Promise<{
    services: Record<string, KyselyServiceConstructor>;
}>
```

### dispose

```ts
public override async dispose(): Promise<void>
```

### fetch

```ts
fetch?(
    request: Request
): Promisable<Response | undefined>
```

Answers a web request sent to the bot. seedcord calls this on each plugin in attach order and
answers with the first `Response`. On an http bot, seedcord calls it for interactions too.
Return `undefined` to pass the request on. If this method throws, seedcord logs the error on
this plugin's logger and answers the request with a 500.

On an http bot, check the path before you await anything because every interaction waits for
this method. On a server, requests reach it once the Ready phase begins. It can run before
`ready()` finishes, and before an `init()` that you moved to Ready.

### init

```ts
public async init(): Promise<void>
```

Connects through your dialect, runs any startup migrations, and loads decorated services.

### listMigrations

```ts
public async listMigrations(): Promise<readonly MigrationInfo[]>
```

Lists every migration and whether it has run.

### listPendingMigrations

```ts
public async listPendingMigrations(): Promise<MigrationInfo[]>
```

Lists unapplied migrations.

### migrate

```ts
public async migrate(
    options?: MigrationOptions
): Promise<void>
```

Runs migrations using the supplied options.

### migrateDown

```ts
public async migrateDown(
    options?: StepMigrationOptions
): Promise<void>
```

Reverts the last migration, or the last `steps` of them.

### migrateUp

```ts
public async migrateUp(
    options?: StepMigrationOptions
): Promise<void>
```

Runs the next pending migration, or `steps` of them.

### onHmr

```ts
onHmr(_event: HmrUpdateEvent): Promisable<void>
```

Override to reload plugin state on an HMR update.

### prepareCommands

```ts
prepareCommands?(
    commands: readonly RESTPostAPIApplicationCommandsJSONBody[]
): Promisable<void>
```

Changes commands before seedcord sends them to Discord. Write your changes onto these objects,
like setting `name_localizations`. Each command appears once, even when it deploys to several guilds.

If it throws, the deploy stops, and so do `seedcord codegen`, a Workers build, `seedcord commands deploy`,
and `seedcord commands list`.

The CLI calls this without running `init()`. Read only what the constructor stored and the bot's files.

### ready

```ts
ready?(): Promisable<void>
```

Runs in the Ready phase after every attached plugin's `init()` has resolved. The other Ready
tasks run alongside it, including the http server binding its port.

Override it when your work needs a logged-in client or a resolved application id.

### registerCommandFiles

```ts
protected registerCommandFiles(patterns: string[]): void
```

Tells `seedcord dev` which files your `prepareCommands` reads. Saving one of them in `seedcord dev`
shows the command refresh prompt.

### registerCriticalFiles

```ts
protected registerCriticalFiles(
    patterns: string[]
): void
```

Registers critical file patterns that should trigger a full restart when changed in Dev HMR.

### rejectOptions

```ts
protected rejectOptions(reason: string): never
```

Rejects the options this plugin got.
