# KyselyPostgres

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

<https://docs.seedcord.org/packages/plugin-kysely-postgres/0.3.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.

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

### dispose

```ts
public 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
async onHmr(_event: HmrUpdateEvent): Promise<void>
```

Override to reload plugin state on an HMR update.

### ready

```ts
async ready(): Promise<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
```

Throws a `SeedcordError` that contains the plugin class name and the reason.
