# @keystone-alpha/adapter-knex

> KeystoneJS Knex Database Adapter

Latest version **6.0.2** (published 2019-10-23) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @keystone-alpha/adapter-knex
pnpm add @keystone-alpha/adapter-knex
yarn add @keystone-alpha/adapter-knex
bun add @keystone-alpha/adapter-knex
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 6.0.2 |
| Published | 2019-10-23 |
| First published | 2019-03-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.4.0 |
| Dependencies | 8 |
| Unpacked size | 40.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | The KeystoneJS Development Team |
| Maintainers | dominikwilkowski, jedwatson, jesstelford, mitchellhamilton, molomby, timl |

## Links

- npm: https://www.npmjs.com/package/@keystone-alpha/adapter-knex
- npm.io page: https://npm.io/package/@keystone-alpha/adapter-knex

## Dependencies (8)

- [pg](https://npm.io/package/pg.md) ^7.10.0
- [knex](https://npm.io/package/knex.md) ^0.19.5
- [p-settle](https://npm.io/package/p-settle.md) ^3.1.0
- [@keystone-alpha/utils](https://npm.io/package/@keystone-alpha/utils.md) ^3.1.0
- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) ^0.6.0
- [@keystone-alpha/logger](https://npm.io/package/@keystone-alpha/logger.md) ^2.0.1
- [@keystone-alpha/keystone](https://npm.io/package/@keystone-alpha/keystone.md) ^16.1.0
- [@keystone-alpha/fields-auto-increment](https://npm.io/package/@keystone-alpha/fields-auto-increment.md) ^2.0.5

## Recent versions

- 6.0.2 (latest) — 2019-10-23
- 6.0.1 — 2019-10-15
- 6.0.0 — 2019-10-15
- 5.0.0 — 2019-10-09
- 4.0.11 — 2019-09-27
- 4.0.10 — 2019-09-17
- 4.0.9 — 2019-09-17
- 4.0.8 — 2019-09-12
- 4.0.7 — 2019-09-02
- 4.0.6 — 2019-08-28
- 4.0.5 — 2019-08-27
- 4.0.4 — 2019-08-23
- 4.0.3 — 2019-08-22
- 4.0.2 — 2019-08-16
- 4.0.1 — 2019-08-13
- … 15 more at https://npm.io/package/@keystone-alpha/adapter-knex/versions

## README

<!--[meta]
section: api
subSection: database-adapters
title: Knex Adapter
[meta]-->

# Knex Database Adapter

The [Knex](https://knexjs.org/#changelog) adapter is a general purpose adapter which can be used to connect to a range of different database backends.
At present, the only fully tested backend is `Postgres`, however Knex gives the potential for `MSSQL`, `MySQL`, `MariaDB`, `SQLite3`, `Oracle`, and `Amazon Redshift` to be supported.

## Usage

```javascript
const { KnexAdapter } = require('@keystone-alpha/adapter-knex');

const keystone = new Keystone({
  name: 'My Awesome Project',
  adapter: new KnexAdapter(),
});
```

## API `new KnexAdapter(options)`

### `options.schemaName`

_**Default:**_ `'public'`

All postgres tables are grouped within a schema and `public` is the default schema.

### `options.knexOptions`

These options are passed directly through to Knex.

See the [knex docs](https://knexjs.org/#Installation-client) for more details.

_**Default:**_

```javaScript
{
  client: 'postgres',
  connection: '<DEFAULT_CONNECTION_URL>'
}
```

The `DEFAULT_CONNECTION_URL` will be either one of the following environmental variables:

- `CONNECT_TO`,
- `DATABASE_URL`,
- `KNEX_URI`

or `'postgres://localhost/<DATABASE_NAME>'`where `DATABASE_NAME` is be derived from the KeystoneJS project name.

## Debugging

To log all Knex queries, run the server with the environment variable `DEBUG=knex:query`.

## Setting Up a Database

Before running Keystone with the Knex adapter you should configure a database. By default Knex will look for a Postgres database on the default port, matching the project name, as the current user.

In most cases this database will not exist and you will want to configure a user and database for your application.

Assuming you're on MacOS and have Postgres installed the `build-test-db.sh` does this for you:

```sh
./build-test-db.sh
```

Otherwise, you can run these steps manually:

```shell
createdb -U postgres keystone
psql ks5_dev -U postgres -c "CREATE USER keystone5 PASSWORD 'k3yst0n3'"
psql ks5_dev -U postgres -c "GRANT ALL ON DATABASE keystone TO keystone5;"
```

If using the above, you will want to set a connection string of: `postgres://keystone5:k3yst0n3@localhost:5432/keystone`

---
_Source: https://npm.io/package/@keystone-alpha/adapter-knex · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
