# KyselyPg

`class` in `plugins` · v0.6.1

<https://docs.seedcord.org/packages/plugins/0.6.1/classes/kysely-pg>

Postgres plugin using Kysely.

Handles setting up the connection pool, applying migrations, and registering decorated services so they can be resolved from the core.

```ts
class KyselyPg<Database extends object> extends Plugin
```

## Constructors

### constructor

```ts
KyselyPg(core: Core, options: KpgOptions)
```

Constructs a new instance of the `KyselyPg` class

## Properties

### connection

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

Exposed Kysely instance once `init` completes.

### core

```ts
public readonly core: Core
```

### logger

```ts
public readonly logger: Logger
```

### services

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

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

## Methods

### 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 or defaults to `latest`.

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

### stop

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

Tears down the connection pool and clears the migration manager reference.
