# KyselyPostgres

`class` in `plugin-kysely-postgres` · v0.8.0

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

Postgres plugin using Kysely.

Sets up the connection pool, applies migrations, and registers decorated
services so the core can resolve them.

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

## Constructors

### constructor

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

Constructs a new instance of the `KyselyPostgres` class

## Properties

### connection

```ts
public connection: Kysely<KyselySchema>
```

Exposed Kysely instance once `init` completes.

### core

```ts
protected core: TCore
```

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

### 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
```

Map of all services registered with the plugin, keyed by their decorator name.

## Methods

### codegen

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

### dispose

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

### init

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

Connects to Postgres, runs any startup migrations, and loads decorated services.

Safe to call multiple times, subsequent calls exit early.

### listMigrations

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

Lists every migration registered with the manager along with its execution state.

### 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>
```

Runs a single downwards migration step unless a custom count is provided.

### migrateUp

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

Runs a single upwards migration step unless a custom count is provided.

### onHmr

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

Override to reload plugin state on an HMR update.

### 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.

### 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.
