open-index/open-npm huggingface dataset:
npm package: @pg-nano/plugin-crud
Description: This plugin generates CRUD routines for Postgres tables.
Latest version: 0.1.0-beta.8

# @pg-nano/plugin-crud

This plugin generates CRUD routines for Postgres tables.

## Usage

```ts
import crud from '@pg-nano/plugin-crud'

export default defineConfig({
  plugins: [
    crud()
  ],
})
```

## Generated routines

If you have a table named `widget` with a primary key of `id INT`, the following routines are generated by this plugin:

```ts
// Get a widget by ID
function getWidget(id: number): Promise<Widget>

// Create a new widget
function createWidget(data: Widget.InsertParams): Promise<Widget>

// Create a new widget with explicit ID or replace an existing one
function upsertWidget(data: Widget.UpsertParams): Promise<Widget>

// Update a widget by ID
function updateWidget(id: number, data: Partial<Widget>): Promise<Widget>

// Delete a widget by ID
function deleteWidget(id: number): Promise<boolean>
```

## Notes

### Composite primary keys

[Composite primary keys](https://www.perplexity.ai/search/what-is-a-composite-primary-ke-8Y_2yAQhQMu04qOOtZPHQg) are supported.

### Overriding generated routines

If you declare a function of the same name as any of the generated routines, your implementation will be used instead.

In other words, you can override the generated routine by defining a function of the same name.

## Caveats

### Null coercion when inserting

If a column has a [default value](https://www.postgresql.org/docs/current/ddl-default.html), and you pass `null` to it when inserting (or upserting), the default value will be used instead. This is because the generated routine doesn't currently distinguish an intentional `null` from an omission.

Updates are not affected by this limitation.

### Compatible table names

The table name is used in the generated JavaScript function names, so it should be a valid JavaScript identifier.

## License

MIT
npm package: @pg-nano/plugin-typebox
Description: This plugin generates [TypeBox](https://github.com/sinclairzx81/typebox) runtime type validators for your Postgres tables, enums, and composite types.
Latest version: 0.1.0-beta.3

# @pg-nano/plugin-typebox

This plugin generates [TypeBox](https://github.com/sinclairzx81/typebox) runtime type validators for your Postgres tables, enums, and composite types.

You must manually integrate the type validators with your application server's API layer (how is up to you). It's **not** used automatically by the Postgres function wrappers generated by pg-nano itself, as it's assumed that you've validated your data by the time you call into Postgres.

Under the hood, it uses [typebox-codegen](https://github.com/sinclairzx81/typebox-codegen) to generate the TypeBox definitions from the TypeScript types that were derived from the Postgres schema by pg-nano.

## Usage

```ts
import typebox from '@pg-nano/plugin-typebox'

export default defineConfig({
  plugins: [
    typebox({
      // Optional: A shell command to run after generating the TypeBox
      // definitions. The main use case is to format the generated code
      // into a more readable form.
      formatScript: 'pnpm format',
    })
  ],
})
```
npm package: @pg-nano/vitest-plugin
Description: This plugin helps you test your Postgres functions with Vitest.
Latest version: 0.1.5

# @pg-nano/vitest-plugin

This plugin helps you test your Postgres functions with Vitest.

### Features

- **Automatic schema migrations**: The plugin runs the same logic as the `pg-nano dev` command, so your database is instantly migrated to match your SQL files. In addition, your test suite will automatically rerun when you make changes to your SQL files.

- **Improved error messages**: Postgres errors are reformatted to provide a stack trace like you're used to with JavaScript. This gives you a preview of where the error occurred in your Postgres function, and you can effortlessly jump to the source code with a click of your mouse.

## Installation

```bash
pnpm add -D @pg-nano/vitest-plugin
```

## Usage

```ts
// vitest.config.ts
import { defineConfig } from 'vitest/config'
import pgNanoVitest from '@pg-nano/vitest-plugin'

export default defineConfig({
  plugins: [
    // Note: These are the default options.
    pgNanoVitest({
      // The directory containing your pg-nano.config.ts file
      root: './',
      // The connection string to your database
      connectionString: 'postgres://postgres:postgres@localhost:5432/postgres',
      // The log level to use for pg-nano migrations and code generation
      logLevel: 'info',
      // Partially override the config file
      config: {},
    })
  ],
})
```

### Using with `@pg-nano/pg-tmp`

The [`@pg-nano/pg-tmp`](https://github.com/pg-nano/pg-tmp) package is a great way to test your Postgres functions in a temporary database. This plugin works great with it!

```bash
pnpm add -D @pg-nano/pg-tmp
```

Start the temporary database before running your tests.

```ts
// vitest.config.ts
import { defineConfig } from 'vitest/config'
import pgNanoVitest from '@pg-nano/vitest-plugin'
import * as pgTmp from '@pg-nano/pg-tmp'

// Note: These are the default options
const connectionString = await pgTmp.start({
  // Seconds of inactivity before the database is automatically deleted.
  timeout: 60,
  // If true, the database won't be automatically deleted.
  keep: false,
  // If set to true, an HTTP connection is used instead of a Unix socket.
  host: false,
})

// This exposes the connection string to your globalSetup file.
process.env.TEST_DSN = connectionString

export default defineConfig({
  plugins: [pgNanoVitest({ connectionString })],
  test: {
    globalSetup: './globalSetup.ts',
  }
})
```

Connect your pg-nano client in a `globalSetup` file.

```ts
// globalSetup.ts
import pgClient from './path/to/pg-nano/client'

export default async () => {
  await pgClient.connect(process.env.TEST_DSN)

  return async () => {
    await pgClient.close()
  }
}
```

## Caveat

This plugin uses the [Test Runner API](https://vitest.dev/advanced/runner.html) of Vitest to intercept test errors for post-processing. This makes the plugin incompatible with other plugins that also use the Test Runner API.