Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
pull_request:
branches: [ main ]

env:
DATABASE_URL: "postgres://postgres:postgres@localhost/test"
NODE_ENV: test

jobs:
build:

Expand All @@ -18,7 +22,9 @@ jobs:
image: postgres:latest
ports: ['5432:5432']
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test
options: >-
--health-cmd pg_isready
--health-interval 10s
Expand All @@ -36,7 +42,9 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
# - run: psql -c 'create database test;' -U postgres
- run: npm ci
- run: npm run createTestDB
- run: npm run lint
- run: npm test
- name: Upload coverage to Codecov
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ available anywhere in your `Hapi` application.
## *Why*?

You are building a PostgreSQL-backed Hapi.js Application
but don't want to be initialising a connection to Postgres
but don't want to be initializing a connection to Postgres
in your route handler because it's *slow* and can lead
to [*interesting* errors](https://github.com/brianc/node-postgres/issues/725) ...
so instead, you spend 1 minute to include a *tiny, tried & tested* plugin
Expand Down Expand Up @@ -135,6 +135,13 @@ Then set your `DATABASE_URL` Environment Variable, on my localhost its:
export DATABASE_URL=postgres://postgres:@localhost/test
```

To `CREATE` the `test` Database, run the following command:

```sh
psql -c 'create database test;' -U postgres
```


(*the default `postgres` user does not have a password on localhost*)

## *Motivation?*
Expand Down
20 changes: 20 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { defineConfig } from "eslint/config";

export default defineConfig([
// File-pattern specific overrides
{
files: ["index.js", "test/*.js"],
rules: {
semi: ["warn", "always"],
"no-undef": "off",
"no-unused-vars": "off"
}
},
{
files:["test/*.js"],
rules: {
"no-console": "off",
"no-undef": "off"
}
}
]);
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const createPoolConnection = async () => {
} catch (err) {
assert(!err, pkg.name + ' ERROR Connecting to PostgreSQL!');
}
}
};

async function assign_connection (request, h) { // DRY
request.pg = await module.exports.getCon();
Expand Down
Loading