Skip to content

Commit

Permalink
Import postgres to mono repo (#159)
Browse files Browse the repository at this point in the history
* Initial commit

* docs(readme): add Greenkeeper badge

* Create Travis DB for tests

* Use pq@6

pq@7 appears to have issues with Sequelize

* 0.1.0

* Keyvpostgres => KeyvPostgres

* Remove Greenkeeper badge

* Use keyv-sql instead of keyv-sequelize

* Format pq query results as array of rows for keyv-sql

* Don't use obj destructuring for Node.js 4 compat

* Remove sequelize dependencies

* Update to keyv-sql 0.2.3 for latest Postgres compat

* Test against Postgres 9.5 on Travis

* Lock dependency versions

* Only accept opts object as constructor argument

* 1.0.0

* requireable => requirable

* 1.0.1

* fix(package): update keyv-sql to version 0.2.4 (#4)

* 1.0.2

* Finish docs

* Update keyv-sql to the latest version 🚀 (#5)

* 1.0.3

* fix(package): update keyv-sql to version 1.0.2 (#6)

Closes #5

* 1.0.4

* Update pg to the latest version 🚀 (#7)

* 1.0.5

* Update keyv-sql to the latest version 🚀 (#8)

* 1.0.6

* Scope to @keyv

* 1.0.7

* Import scoped test suite

* 1.0.8

* Update pg to the latest version 🚀 (#11)

* 1.0.9

* Update pg to the latest version 🚀 (#12)

* 1.0.10

* Update ava to the latest version 🚀 (#13)

* fix(package): update @keyv/sql to version 1.0.6 (#14)

* fix(package): update pg to version 7.2.0 (#15)

* 1.0.11

* Update pg to the latest version 🚀 (#17)

* 1.0.12

* Update @keyv/sql to the latest version 🚀 (#18)

* Update @keyv/sql to the latest version 🚀 (#19)

* 1.0.13

* fix(package): update @keyv/sql to version 1.1.2 (#20)

* 1.0.14

* Update coveralls to the latest version 🚀 (#21)

* Update ava to the latest version 🚀 (#22)

* Update pg to the latest version 🚀 (#23)

* 1.0.15

* Update ava to the latest version 🚀 (#24)

* Update pg to the latest version 🚀 (#25)

* 1.0.16

* Update package.json

Old versions of pg don't work with new versions of node.js (14+)

* moving github actions to build

* moving to local postgres

* updating to create the database

* creating database

* set the user password

* updating command formatting

* updating postgres password

* same user and pass

* user and pass the same

* updating to handle xo upgrade

* updating to handle new format with xo

* upgrading nyc to latest version 15.1.0

* removing travis ci as no longer needed

* updated build status badge on readme

* upgrade xo to version 0.45.0

* fix options to be named correctly

* upgrading ava to version 3.15.0

* moving testing to staged

* fixing tests

* updating to just Official Tests

* Update test.js

* adding in api tests

* adding in value tests

* moving build to 1 parallel process

* update to stop and start the service

* trying createdb

* trying create db

* adding in owner

* adding in multiple stores

* version bump for release v1.0.17

* updated for serial flag on ava

* updated tests to more uniform

* adding in docker compose for testing

* adding in docker compose for build

* adding in docker compose via scripts

* updating to use npm run

* moving to latest version of postgres

* correcting flow of build

* moved docker compose to test folder

* changed naming convention to be more uniform

* updating for new npm run command to start postgres

* updated compose to test folder and removed values

* updated readme around how to test

* naming adjusted

* updating for testing

* Update README.md

* updating licensing for all authors

* adding nvm and also removing yarn to standardize on npm

* upgrading xo to version 0.46.4

* updating build to reference correct testing

* upgrading @keyv/sql to version 1.1.3

* adding codecov on build workflow

* removing codecoverage output from project

* remving coveralls

* updating badge

* updating to run coverage

* version bump to v1.0.18

* no longer needed

* import @keyv/postgres to mono repo

Co-authored-by: Luke Childs <lukechilds123@gmail.com>
Co-authored-by: greenkeeper[bot] <greenkeeper[bot]@users.noreply.github.com>
Co-authored-by: Andrey Frimuchkov <afrimuchkov@yandex.ru>
  • Loading branch information
4 people authored Nov 22, 2021
1 parent 8f5bc01 commit c3baf04
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 0 deletions.
54 changes: 54 additions & 0 deletions packages/postgres/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# @keyv/postgres [<img width="100" align="right" src="https://rawgit.com/lukechilds/keyv/master/media/logo.svg" alt="keyv">](https://github.com/lukechilds/keyv)

> PostgreSQL storage adapter for Keyv
[![build](https://github.com/lukechilds/keyv-postgres/actions/workflows/build.yaml/badge.svg)](https://github.com/lukechilds/keyv-postgres/actions/workflows/build.yaml)
[![codecov](https://codecov.io/gh/jaredwray/keyv-postgres/branch/master/graph/badge.svg?token=SDFRdh5gQU)](https://codecov.io/gh/jaredwray/keyv-postgres)
[![npm](https://img.shields.io/npm/v/@keyv/postgres.svg)](https://www.npmjs.com/package/@keyv/postgres)

PostgreSQL storage adapter for [Keyv](https://github.com/lukechilds/keyv).

Requires Postgres 9.5 or newer for `ON CONFLICT` support to allow performant upserts. [Why?](https://stackoverflow.com/questions/17267417/how-to-upsert-merge-insert-on-duplicate-update-in-postgresql/17267423#17267423)

## Install

```shell
npm install --save keyv @keyv/postgres
```

## Usage

```js
const Keyv = require('keyv');

const keyv = new Keyv('postgresql://user:pass@localhost:5432/dbname');
keyv.on('error', handleConnectionError);
```

You can specify the `table` option.

e.g:

```js
const keyv = new Keyv('postgresql://user:pass@localhost:5432/dbname', { table: 'cache' });
```

## Testing

When testing you can use our `docker-compose` postgresql instance by having docker installed and running. This will start a postgres server, run the tests, and stop the server:

```shell
npm run test:db
```

To run each step manually do the following to start the server, and run the tests:

```shell
npm run test:postgres:start
npm run test
npm run test:postgres:stop
```

## License

MIT © Jared Wray & Luke Childs
59 changes: 59 additions & 0 deletions packages/postgres/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "@keyv/postgres",
"version": "1.0.18",
"description": "PostgreSQL storage adapter for Keyv",
"main": "src/index.js",
"scripts": {
"test": "xo && nyc ava --serial",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov",
"clean": "rm -rf node_modules && rm -rf .nyc_output && rm -rf coverage.lcov"
},
"xo": {
"extends": "xo-lukechilds",
"rules": {
"unicorn/prefer-module": 0
}
},
"ava": {
"require": [
"requirable"
]
},
"repository": {
"type": "git",
"url": "git+https://github.com/lukechilds/keyv-postgres.git"
},
"keywords": [
"postgres",
"postgresql",
"sql",
"keyv",
"storage",
"adapter",
"key",
"value",
"store",
"cache",
"ttl"
],
"author": "Luke Childs <lukechilds123@gmail.com> (http://lukechilds.co.uk)",
"license": "MIT",
"bugs": {
"url": "https://github.com/lukechilds/keyv-postgres/issues"
},
"homepage": "https://github.com/lukechilds/keyv-postgres",
"dependencies": {
"@keyv/sql": "1.1.3",
"pg": "8.7.1"
},
"devDependencies": {
"@keyv/test-suite": "*",
"ava": "^3.15.0",
"eslint-config-xo-lukechilds": "^1.0.0",
"keyv": "*",
"nyc": "^15.1.0",
"requirable": "^1.0.4",
"this": "^1.0.2",
"xo": "^0.46.4"
}
}
24 changes: 24 additions & 0 deletions packages/postgres/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

const KeyvSql = require('@keyv/sql');
const Pool = require('pg').Pool;

class KeyvPostgres extends KeyvSql {
constructor(options) {
options = Object.assign({
dialect: 'postgres',
uri: 'postgresql://localhost:5432',
}, options);

options.connect = () => Promise.resolve()
.then(() => {
const pool = new Pool({ connectionString: options.uri });
return sql => pool.query(sql)
.then(data => data.rows);
});

super(options);
}
}

module.exports = KeyvPostgres;
11 changes: 11 additions & 0 deletions packages/postgres/test/postgres.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '2'
services:
postgres:
image: postgres
command: postgres -c 'max_connections=200'
environment:
POSTGRES_DB: keyv_test
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
ports:
- 5432:5432/tcp
11 changes: 11 additions & 0 deletions packages/postgres/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const test = require('ava');
const keyvTestSuite = require('@keyv/test-suite').default;
const { keyvOfficialTests } = require('@keyv/test-suite');
const Keyv = require('keyv');
const KeyvPostgres = require('this');

keyvOfficialTests(test, Keyv, 'postgresql://postgres:postgres@localhost:5432/keyv_test', 'postgresql://foo');

const store = () => new KeyvPostgres({ uri: 'postgresql://postgres:postgres@localhost:5432/keyv_test' });
keyvTestSuite(test, Keyv, store);

0 comments on commit c3baf04

Please sign in to comment.