Skip to content

Commit d25969b

Browse files
author
Simone Sanfratello
committed
feature: native option
1 parent 157b09b commit d25969b

File tree

4 files changed

+11
-114
lines changed

4 files changed

+11
-114
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,6 @@ typings/
6262

6363
# vim swap files
6464
*.swp
65+
66+
# npm package lock
67+
package-lock.json

index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
'use strict'
22

33
const fp = require('fastify-plugin')
4+
let pg = require('pg')
45

56
function fastifyPostgres (fastify, options, next) {
6-
let pg
77
if (options.native) {
8-
pg = require('pg-native')
9-
} else {
10-
pg = require('pg')
8+
if (!pg.native) {
9+
console.warn('pg-native not installed, can\'t use native option')
10+
} else {
11+
pg = pg.native
12+
}
1113
}
1214

1315
const pool = new pg.Pool(options)

package-lock.json

Lines changed: 0 additions & 107 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@
2727
"homepage": "https://github.com/fastify/fastify-postgres#readme",
2828
"dependencies": {
2929
"fastify-plugin": "^0.1.1",
30-
"pg": "^7.3.0"
31-
},
32-
"optionalDependencies": {
30+
"pg": "^7.3.0",
3331
"pg-native": "^2.2.0"
3432
},
33+
"optionalDependencies": {},
3534
"devDependencies": {
3635
"fastify": "^0.29.2",
3736
"standard": "^10.0.3",

0 commit comments

Comments
 (0)