open-index/open-npm huggingface dataset:
npm package: @slonik/driver
Description: A Node.js PostgreSQL client with strict types, detailed logging and assertions.
Author: Gajus Kuizinas
Latest version: 48.14.0

# Slonik Driver

Slonik driver is an abstraction layer that provides a consistent API for interacting using different PostgreSQL clients.

This package is made available for developers who wish to create their own Slonik driver.
npm package: @slonik/pg-driver
Description: A Node.js PostgreSQL client with strict types, detailed logging and assertions.
Author: Gajus Kuizinas
Latest version: 48.14.0

# Slonik Driver for `pg`

```ts
import { createPgDriverFactory, DatabaseError } from "@slonik/pg-driver";
```

## Error handling

All Slonik errors extend from `SlonikError`. `SlonikError` uses `cause` property to store the original error, which might be a `DatabaseError` from `pg`. Example:

```ts
pool.on("error", (error) => {
  const cause = error.cause;

  if (cause instanceof DatabaseError) {
    console.log(cause.code);
  }
});
```

This allows you to handle errors based on the lower-level error codes provided by `pg` driver.

Example of handling all errors that could warrant a fatal error:

```ts
const fatalErrorClasses = [
  // Connection Exception
  "08",
  // Invalid Authorization Specification
  "28",
];

pool.on("error", (error) => {
  if (error.cause instanceof DatabaseError) {
    const classCode = error.cause.code.slice(0, 2);

    if (fatalErrorClasses.includes(classCode)) {
      // Initiate shutdown due to unexpected connection state.
    }
  }
});
```
npm package: @slonik/test-ssls
Description: SSLs used for testing Slonik.
Author: Gajus Kuizinas
Latest version: 48.14.0

# Test SSLs

SSLs used for testing Slonik.

## Generating SSL certificates

```bash
# Generate a Root Certificate (CA)
openssl genrsa -out root.key 2048
openssl req -x509 -new -nodes -key root.key -sha256 -days 365 -out root.crt -subj "/C=US/ST=State/L=City/O=Organization/OU=OrgUnit/CN=RootCA"

# Generate a Client Key
openssl genrsa -out slonik.key 2048

# Create a Certificate Signing Request (CSR) for the Client
openssl req -new -key slonik.key -out slonik.csr -subj "/C=US/ST=State/L=City/O=Organization/OU=OrgUnit/CN=Client"

# Sign the Client Certificate with the Root Certificate
openssl x509 -req -in slonik.csr -CA root.crt -CAkey root.key -CAcreateserial -out slonik.crt -days 365 -sha256

# Verify the Certificates
openssl verify -CAfile root.crt slonik.crt
```

## Running PostgreSQL with SSL

```bash
docker build -t slonik-ssl-test .
docker run --name slonik-ssl-test --rm -it -e POSTGRES_PASSWORD=postgres -p 5433:5432 slonik-ssl-test
```