Repository: knex/knex
Pull request #4664 (2021-09-06 09:08:12)

Bump tedious from 11.8.0 to 12.2.0
Bumps [tedious](https://github.com/tediousjs/tedious) from 11.8.0 to 12.2.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/tediousjs/tedious/releases">tedious's releases</a>.</em></p>
<blockquote>
<h2>v12.2.0</h2>
<h1><a href="https://github.com/tediousjs/tedious/compare/v12.1.0...v12.2.0">12.2.0</a> (2021-08-29)</h1>
<h3>Features</h3>
<ul>
<li>express client support for UTF-8 in LOGIN7 (<a href="https://github.com/tediousjs/tedious/commit/e2f853d5f05b24f32c743ec744bb6b7f142c616d">e2f853d</a>), closes <a href="https://github-redirect.dependabot.com/tediousjs/tedious/issues/1143">#1143</a></li>
<li>parse UTF-8 support FeatureExtAck (<a href="https://github.com/tediousjs/tedious/commit/c91258e8b634955e5b9f50c52229e44b715c6e03">c91258e</a>), closes <a href="https://github-redirect.dependabot.com/tediousjs/tedious/issues/1143">#1143</a></li>
</ul>
<h2>v12.1.0</h2>
<h1><a href="https://github.com/tediousjs/tedious/compare/v12.0.0...v12.1.0">12.1.0</a> (2021-08-28)</h1>
<h3>Bug Fixes</h3>
<ul>
<li>improve collation parsing (<a href="https://github.com/tediousjs/tedious/commit/b8cfb08824ab9d3ed6862b5c3493cc54bcc37c35">b8cfb08</a>)</li>
</ul>
<h3>Features</h3>
<ul>
<li>encode <code>varchar</code>, <code>char</code> and <code>text</code> values based on the current database collation (<a href="https://github.com/tediousjs/tedious/commit/0dce3e3bfe88abb524164e02db1cbd159a1783fc">0dce3e3</a>)</li>
<li>track the current database collation on the connection (<a href="https://github.com/tediousjs/tedious/commit/d27a7e02077379c73f9a43ac6a22034bffc8dc3e">d27a7e0</a>)</li>
<li>write collation for <code>nvarchar</code>, <code>nchar</code>, <code>ntext</code> , <code>varchar</code>, <code>char</code> and <code>text</code> data types (<a href="https://github.com/tediousjs/tedious/commit/b1db199c1bc8535bf03b9f75f0eba72bb75ff6d7">b1db199</a>)</li>
</ul>
<h2>v12.0.0</h2>
<h1><a href="https://github.com/tediousjs/tedious/compare/v11.8.0...v12.0.0">12.0.0</a> (2021-08-15)</h1>
<h3>Features</h3>
<ul>
<li>drop support for Node.js 10.x (<a href="https://github.com/tediousjs/tedious/commit/6bd814ca9adc603abe9cae379846e4ae9faa6578">6bd814c</a>)</li>
<li>remove <code>validateBulkLoadParameters</code> connection option (<a href="https://github.com/tediousjs/tedious/commit/fbe3aebd109d3f8e73c879a1d92ed1ce0a9a5fd1">fbe3aeb</a>)</li>
<li>target Node.js 12.x when performing code transpilation (<a href="https://github.com/tediousjs/tedious/commit/738ac75dcec6a980e1d125eab9fc8d9bb9264679">738ac75</a>)</li>
</ul>
<h3>BREAKING CHANGES</h3>
<ul>
<li>This removes the <code>validateBulkLoadParameters</code> connection option and always enables validation of bulk load values.</li>
<li>Going forward, <code>tedious</code> will only support Node.js v12 or newer.</li>
</ul>
<h2>v12.0.0-beta.4</h2>
<h1><a href="https://github.com/tediousjs/tedious/compare/v12.0.0-beta.3...v12.0.0-beta.4">12.0.0-beta.4</a> (2021-08-15)</h1>
<h3>Features</h3>
<ul>
<li>add missing collation codepage information (<a href="https://github.com/tediousjs/tedious/commit/d93a7b5f7d6b8e7d46dd0aac0f26d929b8ca3b30">d93a7b5</a>)</li>
<li>support <code>ntext</code> data type in bulk loads and regular requests (<a href="https://github.com/tediousjs/tedious/commit/4a10ccb64dca8cfc89eef4b8925264e3f0b85898">4a10ccb</a>)</li>
<li>support <code>text</code> and <code>image</code> data type in bulk loads (<a href="https://github.com/tediousjs/tedious/commit/573426fca80b71a5e4d4e82e00dc5aa9d61678a9">573426f</a>)</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/tediousjs/tedious/commit/fac4e6e6e47a8ac189ecea097eb3b2df969a34af"><code>fac4e6e</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/tediousjs/tedious/issues/1317">#1317</a> from jeremy-w/jeremy-w/feat/login-with-utf8-option-1143</li>
<li><a href="https://github.com/tediousjs/tedious/commit/6f4a270a03173de4ef5198c7cfa164f9c082c64e"><code>6f4a270</code></a> Merge branch 'master' into jeremy-w/feat/login-with-utf8-option-1143</li>
<li><a href="https://github.com/tediousjs/tedious/commit/1189b4ad9666600d9656d28cc8198a1bdab4c703"><code>1189b4a</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/tediousjs/tedious/issues/1314">#1314</a> from tediousjs/arthur/track-database-collation</li>
<li><a href="https://github.com/tediousjs/tedious/commit/c4fc65e839e7b585f9340c68389a3f5fb0a0cef7"><code>c4fc65e</code></a> refactor: simplify type handling code for <code>char</code>/<code>text</code>/<code>varchar</code></li>
<li><a href="https://github.com/tediousjs/tedious/commit/0dce3e3bfe88abb524164e02db1cbd159a1783fc"><code>0dce3e3</code></a> feat: encode <code>varchar</code>, <code>char</code> and <code>text</code> values based on the current databas...</li>
<li><a href="https://github.com/tediousjs/tedious/commit/b1db199c1bc8535bf03b9f75f0eba72bb75ff6d7"><code>b1db199</code></a> feat: write collation for <code>nvarchar</code>, <code>nchar</code>, <code>ntext</code> , <code>varchar</code>, <code>char</code> an...</li>
<li><a href="https://github.com/tediousjs/tedious/commit/d27a7e02077379c73f9a43ac6a22034bffc8dc3e"><code>d27a7e0</code></a> feat: track the current database collation on the connection</li>
<li><a href="https://github.com/tediousjs/tedious/commit/b8cfb08824ab9d3ed6862b5c3493cc54bcc37c35"><code>b8cfb08</code></a> fix: improve collation parsing</li>
<li><a href="https://github.com/tediousjs/tedious/commit/6d3f675559a0abe0fe204ee3452c1d2b3c769c94"><code>6d3f675</code></a> Merge branch 'master' into jeremy-w/feat/login-with-utf8-option-1143</li>
<li><a href="https://github.com/tediousjs/tedious/commit/93c4bc639c7bd75de065bbd037a5f5ee920f518d"><code>93c4bc6</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/tediousjs/tedious/issues/1316">#1316</a> from tediousjs/beta</li>
<li>Additional commits viewable in <a href="https://github.com/tediousjs/tedious/compare/v11.8.0...v12.2.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=tedious&package-manager=npm_and_yarn&previous-version=11.8.0&new-version=12.2.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>


Patch:
diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml
index d2792397..e2e3481d 100644
--- a/.github/workflows/coverage.yml
+++ b/.github/workflows/coverage.yml
@@ -39,7 +39,7 @@ jobs:
         run: npm run test:coverage
         env:
           CI: true
-          DB: "postgres mysql mysql2 mssql sqlite3"
+          DB: "postgres pgnative mysql mysql2 mssql sqlite3"
           KNEX_TEST_TIMEOUT: 60000
 
       - name: Stop Databases
diff --git a/lib/constants.js b/lib/constants.js
index 44cca024..0b9e06f7 100644
--- a/lib/constants.js
+++ b/lib/constants.js
@@ -12,6 +12,7 @@ const SUPPORTED_CLIENTS = Object.freeze(
     'mysql2',
     'oracledb',
     'postgres',
+    'pgnative',
     'redshift',
     'sqlite3',
   ].concat(Object.keys(CLIENT_ALIASES))
@@ -23,6 +24,7 @@ const DRIVER_NAMES = Object.freeze({
   MySQL2: 'mysql2',
   Oracle: 'oracledb',
   PostgreSQL: 'pg',
+  PgNative: 'pgnative',
   Redshift: 'pg-redshift',
   SQLite: 'sqlite3',
 });
diff --git a/lib/dialects/pgnative/index.js b/lib/dialects/pgnative/index.js
new file mode 100644
index 00000000..4c0fb41b
--- /dev/null
+++ b/lib/dialects/pgnative/index.js
@@ -0,0 +1,59 @@
+// PostgreSQL Native Driver (pg-native)
+// -------
+const Client_PG = require('../postgres');
+
+class Client_PgNative extends Client_PG {
+  constructor(...args) {
+    super(...args);
+    this.driverName = 'pgnative';
+    this.canCancelQuery = true;
+  }
+
+  _driver() {
+    return require('pg').native;
+  }
+
+  _stream(connection, obj, stream, options) {
+    if (!obj.sql) throw new Error('The query is empty');
+
+    const client = this;
+    return new Promise((resolver, rejecter) => {
+      stream.on('error', rejecter);
+      stream.on('end', resolver);
+
+      return client
+        ._query(connection, obj)
+        .then((obj) => obj.response)
+        .then(({ rows }) => rows.forEach((row) => stream.write(row)))
+        .catch(function (err) {
+          stream.emit('error', err);
+        })
+        .then(function () {
+          stream.end();
+        });
+    });
+  }
+
+  async cancelQuery(connectionToKill) {
+    try {
+      return await this._wrappedCancelQueryCall(null, connectionToKill);
+    } catch (err) {
+      this.logger.warn(`Connection Error: ${err}`);
+    }
+  }
+
+  _wrappedCancelQueryCall(emptyConnection, connectionToKill) {
+    return new Promise(function (resolve, reject) {
+      connectionToKill.native.cancel(function (err) {
+        if (err) {
+          reject(err);
+          return;
+        }
+
+        resolve(true);
+      });
+    });
+  }
+}
+
+module.exports = Client_PgNative;
diff --git a/lib/dialects/postgres/index.js b/lib/dialects/postgres/index.js
index 5d5a9066..047299be 100644
--- a/lib/dialects/postgres/index.js
+++ b/lib/dialects/postgres/index.js
@@ -62,34 +62,40 @@ class Client_PG extends Client {
     return `"${value.replace(/"/g, '""')}"${arrayAccessor}`;
   }
 
+  _acquireOnlyConnection() {
+    const connection = new this.driver.Client(this.connectionSettings);
+
+    return connection.connect().then(() => connection);
+  }
+
   // Get a raw connection, called by the `pool` whenever a new
   // connection needs to be added to the pool.
   acquireRawConnection() {
     const client = this;
-    return new Promise(function (resolver, rejecter) {
-      const connection = new client.driver.Client(client.connectionSettings);
-      connection.connect(function (err, connection) {
-        if (err) {
-          return rejecter(err);
-        }
+
+    return this._acquireOnlyConnection()
+      .then(function (connection) {
         connection.on('error', (err) => {
           connection.__knex__disposed = err;
         });
+
         connection.on('end', (err) => {
           connection.__knex__disposed = err || 'Connection ended unexpectedly';
         });
+
         if (!client.version) {
           return client.checkVersion(connection).then(function (version) {
             client.version = version;
-            resolver(connection);
+            return connection;
           });
         }
-        resolver(connection);
+
+        return connection;
+      })
+      .then(function setSearchPath(connection) {
+        client.setSchemaSearchPath(connection);
+        return connection;
       });
-    }).then(function setSearchPath(connection) {
-      client.setSchemaSearchPath(connection);
-      return connection;
-    });
   }
 
   // Used to explicitly close a connection, called internally by the pool
diff --git a/lib/execution/batch-insert.js b/lib/execution/batch-insert.js
index 0549dc43..fbd4e2a8 100644
--- a/lib/execution/batch-insert.js
+++ b/lib/execution/batch-insert.js
@@ -4,8 +4,15 @@ const delay = require('./internal/delay');
 const { isNumber } = require('../util/is');
 
 function batchInsert(client, tableName, batch, chunkSize = 1000) {
-  let returning = void 0;
+  let returning = undefined;
   let transaction = null;
+  if (!isNumber(chunkSize) || chunkSize < 1) {
+    throw new TypeError(`Invalid chunkSize: ${chunkSize}`);
+  }
+  if (!Array.isArray(batch)) {
+    throw new TypeError(`Invalid batch: Expected array, got ${typeof batch}`);
+  }
+  const chunks = chunk(batch, chunkSize);
 
   const runInTransaction = (cb) => {
     if (transaction) {
@@ -16,18 +23,6 @@ function batchInsert(client, tableName, batch, chunkSize = 1000) {
 
   return Object.assign(
     Promise.resolve().then(async () => {
-      if (!isNumber(chunkSize) || chunkSize < 1) {
-        throw new TypeError(`Invalid chunkSize: ${chunkSize}`);
-      }
-
-      if (!Array.isArray(batch)) {
-        throw new TypeError(
-          `Invalid batch: Expected array, got ${typeof batch}`
-        );
-      }
-
-      const chunks = chunk(batch, chunkSize);
-
       //Next tick to ensure wrapper functions are called if needed
       await delay(1);
       return runInTransaction(async (tr) => {
diff --git a/lib/execution/transaction.js b/lib/execution/transaction.js
index dad41386..4e2c7cf3 100644
--- a/lib/execution/transaction.js
+++ b/lib/execution/transaction.js
@@ -266,8 +266,8 @@ class Transaction extends EventEmitter {
     return this._promise.then(onResolve, onReject);
   }
 
-  catch(onReject) {
-    return this._promise.catch(onReject);
+  catch(...args) {
+    return this._promise.catch(...args);
   }
 
   asCallback(cb) {
diff --git a/package.json b/package.json
index a652d585..8ede49de 100644
--- a/package.json
+++ b/package.json
@@ -29,6 +29,7 @@
     "test:oracledb": "cross-env DB=oracledb npm run test:db",
     "test:sqlite": "cross-env DB=sqlite3 npm run test:db",
     "test:postgres": "cross-env DB=postgres npm run test:db",
+    "test:pgnative": "cross-env DB=pgnative npm run test:db",
     "test:tape": "node test/tape/index.js | tap-spec",
     "test:cli": "cross-env KNEX_PATH=../knex.js KNEX=bin/cli.js jake -f test/jake/Jakefile",
     "db:start": "docker-compose -f scripts/docker-compose.yml up --build -d mysql oracledbxe postgres mssql && docker-compose -f scripts/docker-compose.yml up waitmssql waitmysql waitpostgres waitoracledbxe",
@@ -36,6 +37,8 @@
     "db:stop": "docker-compose -f scripts/docker-compose.yml down",
     "db:start:postgres": "docker-compose -f scripts/docker-compose.yml up --build -d postgres && docker-compose -f scripts/docker-compose.yml up waitpostgres",
     "db:stop:postgres": "docker-compose -f scripts/docker-compose.yml down",
+    "db:start:pgnative": "docker-compose -f scripts/docker-compose.yml up --build -d pgnative && docker-compose -f scripts/docker-compose.yml up waitpgnative",
+    "db:stop:pgnative": "docker-compose -f scripts/docker-compose.yml down",
     "db:start:mysql": "docker-compose -f scripts/docker-compose.yml up --build -d mysql && docker-compose -f scripts/docker-compose.yml up waitmysql",
     "db:stop:mysql": "docker-compose -f scripts/docker-compose.yml down",
     "db:start:oracle": "docker-compose -f scripts/docker-compose.yml up --build -d oracledbxe && docker-compose -f scripts/docker-compose.yml up waitoracledbxe",
@@ -72,6 +75,9 @@
     "pg": {
       "optional": true
     },
+    "pg-native": {
+      "optional": true
+    },
     "sqlite3": {
       "optional": true
     }
@@ -105,8 +111,9 @@
     "nyc": "^15.1.0",
     "oracledb": "^5.2.0",
     "pg": "^8.7.1",
+    "pg-native": "^3.0.0",
     "pg-query-stream": "^4.2.1",
-    "prettier": "2.3.2",
+    "prettier": "2.4.1",
     "rimraf": "^3.0.2",
     "sinon": "^11.1.2",
     "sinon-chai": "^3.7.0",
@@ -114,11 +121,11 @@
     "sqlite3": "^5.0.2",
     "tap-spec": "^5.0.0",
     "tape": "^5.3.1",
-    "tedious": "^11.4.0",
+    "tedious": "^12.2.0",
     "toxiproxy-node-client": "^2.0.6",
     "ts-node": "^10.2.1",
     "tsd": "^0.17.0",
-    "typescript": "4.4.2"
+    "typescript": "4.4.3"
   },
   "buildDependencies": [
     "rimraf"
@@ -177,6 +184,7 @@
     "mysql": false,
     "mysql2": false,
     "pg": false,
+    "pg-native": false,
     "pg-query-stream": false,
     "oracle": false,
     "sqlite3": false,
diff --git a/scripts/docker-compose.yml b/scripts/docker-compose.yml
index 8be9cc73..c79a7933 100644
--- a/scripts/docker-compose.yml
+++ b/scripts/docker-compose.yml
@@ -84,6 +84,27 @@ services:
       - -c
       - 'until /usr/local/bin/psql postgres://testuser:knextest@postgres/knex_test -c "SELECT 1"; do sleep 5; done'
 
+  pgnative:
+    image: postgres:alpine
+    # see https://www.postgresql.org/docs/current/non-durability.html
+    command: '-c full_page_writes=off -c fsync=off -c synchronous_commit=off'
+    ports:
+      - '25433:5432'
+    environment:
+      - POSTGRES_USER=testuser
+      - POSTGRES_PASSWORD=knextest
+      - POSTGRES_DB=knex_test
+  waitpgnative:
+    image: postgres:alpine
+    links:
+      - pgnative
+    depends_on:
+      - pgnative
+    entrypoint:
+      - bash
+      - -c
+      - 'until /usr/local/bin/psql postgres://testuser:knextest@pgnative/knex_test -c "SELECT 1"; do sleep 5; done'
+
   oracledbxe:
     image: quillbuilduser/oracle-18-xe
     container_name: oracledbxe_container


Test patch:
diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml
index 452a181c..40492ea4 100644
--- a/.github/workflows/integration-tests.yml
+++ b/.github/workflows/integration-tests.yml
@@ -19,7 +19,7 @@ jobs:
       fail-fast: false
       matrix:
         node-version: [16.x, 14.x, 12.x, 10.x]
-        database-type: [postgres, mysql, mssql, sqlite3]
+        database-type: [postgres, pgnative, mysql, mssql, sqlite3]
 
     steps:
       - name: Checkout Repository
diff --git a/scripts/stress-test/docker-compose.yml b/scripts/stress-test/docker-compose.yml
index 274e72d3..f384b164 100644
--- a/scripts/stress-test/docker-compose.yml
+++ b/scripts/stress-test/docker-compose.yml
@@ -7,11 +7,13 @@ services:
       - "8474:8474"
       - "23306:23306"
       - "25432:25432"
+      - "25433:25433"
       - "21521:21521"
       - "21433:21433"
     links:
       - "mysql"
       - "postgresql"
+      - "pgnative"
       - "oracledbxe"
       - "mssql"
 
@@ -31,6 +33,14 @@ services:
       - POSTGRES_PASSWORD=postgresrootpassword
       - POSTGRES_USER=postgres
 
+  pgnative:
+    image: mdillon/postgis
+    ports:
+      - "35433:5432"
+    environment:
+      - POSTGRES_PASSWORD=postgresrootpassword
+      - POSTGRES_USER=postgres
+
   oracledbxe:
     image: wnameless/oracle-xe-11g
     ports:
diff --git a/scripts/stress-test/knex-stress-test.js b/scripts/stress-test/knex-stress-test.js
index 2b8ff4cd..07586d08 100644
--- a/scripts/stress-test/knex-stress-test.js
+++ b/scripts/stress-test/knex-stress-test.js
@@ -13,6 +13,13 @@ const pg = Knex({
   pool: { max: 50 },
 });
 
+const pgnative = Knex({
+  client: 'pgnative',
+  connection:
+    'postgres://postgres:postgresrootpassword@localhost:25433/postgres',
+  pool: { max: 50 },
+});
+
 const mysql2 = Knex({
   client: 'mysql2',
   connection:
@@ -91,10 +98,10 @@ setInterval(() => {
   lastCounters = _.cloneDeep(counters);
 }, 2000);
 
-async function killConnectionsPg() {
-  return pg.raw(`SELECT pg_terminate_backend(pg_stat_activity.pid) 
+async function killConnectionsPg(client) {
+  return client.raw(`SELECT pg_terminate_backend(pg_stat_activity.pid)
     FROM pg_stat_activity
-    WHERE pg_stat_activity.datname = 'postgres' 
+    WHERE pg_stat_activity.datname = 'postgres'
       AND pid <> pg_backend_pid()`);
 }
 
@@ -154,6 +161,7 @@ async function main() {
   // create TCP proxies for simulating bad connections etc.
   async function recreateProxies() {
     await recreateProxy('postgresql', 25432, 5432);
+    await recreateProxy('postgresql', 25433, 5433);
     await recreateProxy('mysql', 23306, 3306);
     await recreateProxy('oracledbxe', 21521, 1521);
     await recreateProxy('mssql', 21433, 1433);
@@ -164,6 +172,9 @@ async function main() {
   loopQueries('PSQL:', pg.raw('select 1'));
   loopQueries('PSQL TO:', pg.raw('select 1').timeout(20));
 
+  loopQueries('PGNATIVE:', pgnative.raw('select 1'));
+  loopQueries('PGNATIVE TO:', pgnative.raw('select 1').timeout(20));
+
   loopQueries('MYSQL:', mysql.raw('select 1'));
   loopQueries('MYSQL TO:', mysql.raw('select 1').timeout(20));
 
@@ -181,7 +192,8 @@ async function main() {
     await delay(20); // kill everything every quite often from server side
     try {
       await Promise.all([
-        killConnectionsPg(),
+        killConnectionsPg(pg),
+        killConnectionsPg(pgnative),
         killConnectionsMyslq(mysql),
         //        killConnectionsMyslq(mysql2),
         killConnectionsMssql(),
diff --git a/test/integration/query/additional.js b/test/integration/query/additional.js
index a4540700..1e117c4a 100644
--- a/test/integration/query/additional.js
+++ b/test/integration/query/additional.js
@@ -14,6 +14,7 @@ const {
   isMysql,
   isMssql,
   isPgBased,
+  isPgNative,
 } = require('../../util/db-helpers');
 const { DRIVER_NAMES: drivers } = require('../../util/constants');
 
@@ -254,6 +255,7 @@ module.exports = function (knex) {
         .testSql(function (tester) {
           tester('mysql', 'truncate `test_table_two`');
           tester('pg', 'truncate "test_table_two" restart identity');
+          tester('pgnative', 'truncate "test_table_two" restart identity');
           tester('pg-redshift', 'truncate "test_table_two"');
           tester('sqlite3', 'delete from `test_table_two`');
           tester('oracledb', 'truncate table "test_table_two"');
@@ -295,6 +297,8 @@ module.exports = function (knex) {
         [drivers.MySQL2]: 'SHOW TABLES',
         [drivers.PostgreSQL]:
           "SELECT table_name FROM information_schema.tables WHERE table_schema='public'",
+        [drivers.PgNative]:
+          "SELECT table_name FROM information_schema.tables WHERE table_schema='public'",
         [drivers.Redshift]:
           "SELECT table_name FROM information_schema.tables WHERE table_schema='public'",
         [drivers.SQLite]: "SELECT name FROM sqlite_master WHERE type='table';",
@@ -363,6 +367,25 @@ module.exports = function (knex) {
               },
             }
           );
+          tester(
+            'pgnative',
+            'select * from information_schema.columns where table_name = ? and table_catalog = current_database() and table_schema = current_schema()',
+            null,
+            {
+              enum_value: {
+                defaultValue: null,
+                maxLength: null,
+                nullable: true,
+                type: 'text',
+              },
+              uuid: {
+                defaultValue: null,
+                maxLength: null,
+                nullable: false,
+                type: 'uuid',
+              },
+            }
+          );
           tester(
             'pg-redshift',
             'select * from information_schema.columns where table_name = ? and table_catalog = ? and table_schema = current_schema()',
@@ -463,6 +486,17 @@ module.exports = function (knex) {
               type: 'uuid',
             }
           );
+          tester(
+            'pgnative',
+            'select * from information_schema.columns where table_name = ? and table_catalog = current_database() and table_schema = current_schema()',
+            null,
+            {
+              defaultValue: null,
+              maxLength: null,
+              nullable: false,
+              type: 'uuid',
+            }
+          );
           tester(
             'pg-redshift',
             'select * from information_schema.columns where table_name = ? and table_catalog = ? and table_schema = current_schema()',
@@ -613,6 +647,9 @@ module.exports = function (knex) {
               tester('pg', [
                 'alter table "accounts" rename "about" to "about_col"',
               ]);
+              tester('pgnative', [
+                'alter table "accounts" rename "about" to "about_col"',
+              ]);
               tester('pg-redshift', [
                 'alter table "accounts" rename "about" to "about_col"',
               ]);
@@ -672,6 +709,9 @@ module.exports = function (knex) {
             .testSql(function (tester) {
               tester('mysql', ['alter table `accounts` drop `first_name`']);
               tester('pg', ['alter table "accounts" drop column "first_name"']);
+              tester('pgnative', [
+                'alter table "accounts" drop column "first_name"',
+              ]);
               tester('pg-redshift', [
                 'alter table "accounts" drop column "first_name"',
               ]);
@@ -724,6 +764,9 @@ module.exports = function (knex) {
         [drivers.PostgreSQL]: function () {
           return knex.raw('SELECT pg_sleep(1)');
         },
+        [drivers.PgNative]: function () {
+          return knex.raw('SELECT pg_sleep(1)');
+        },
         [drivers.MySQL]: function () {
           return knex.raw('SELECT SLEEP(1)');
         },
@@ -776,6 +819,9 @@ module.exports = function (knex) {
         [drivers.PostgreSQL]: function () {
           return knex.raw('SELECT pg_sleep(10)');
         },
+        [drivers.PgNative]: function () {
+          return knex.raw('SELECT pg_sleep(10)');
+        },
         [drivers.MySQL]: function () {
           return knex.raw('SELECT SLEEP(10)');
         },
@@ -813,6 +859,9 @@ module.exports = function (knex) {
         [drivers.PostgreSQL]: function () {
           return knex.raw('SELECT * from pg_stat_activity');
         },
+        [drivers.PgNative]: function () {
+          return knex.raw('SELECT * from pg_stat_activity');
+        },
         [drivers.MySQL]: function () {
           return knex.raw('SHOW PROCESSLIST');
         },
@@ -882,19 +931,22 @@ module.exports = function (knex) {
       // until the first query finishes. Setting a sleep time longer than the
       // mocha timeout exposes this behavior.
       const testQueries = {
-        pg: function () {
+        [drivers.PostgreSQL]: function () {
+          return knex.raw('SELECT pg_sleep(10)');
+        },
+        [drivers.PgNative]: function () {
           return knex.raw('SELECT pg_sleep(10)');
         },
-        mysql: function () {
+        [drivers.MySQL]: function () {
           return knex.raw('SELECT SLEEP(10)');
         },
-        mysql2: function () {
+        [drivers.MySQL2]: function () {
           return knex.raw('SELECT SLEEP(10)');
         },
-        mssql: function () {
+        [drivers.MsSQL]: function () {
           return knex.raw("WAITFOR DELAY '00:00:10'");
         },
-        oracledb: function () {
+        [drivers.Oracle]: function () {
           return knex.raw('begin dbms_lock.sleep(10); end;');
         },
       };
@@ -921,13 +973,16 @@ module.exports = function (knex) {
       }
 
       const getProcessesQueries = {
-        pg: function () {
+        [drivers.PostgreSQL]: function () {
+          return knex.raw('SELECT * from pg_stat_activity');
+        },
+        [drivers.PgNative]: function () {
           return knex.raw('SELECT * from pg_stat_activity');
         },
-        mysql: function () {
+        [drivers.MySQL]: function () {
           return knex.raw('SHOW PROCESSLIST');
         },
-        mysql2: function () {
+        [drivers.MySQL2]: function () {
           return knex.raw('SHOW PROCESSLIST');
         },
       };
@@ -998,6 +1053,9 @@ module.exports = function (knex) {
         [drivers.PostgreSQL]: function () {
           return knexDb.raw('SELECT pg_sleep(10)');
         },
+        [drivers.PgNative]: function () {
+          return knexDb.raw('SELECT pg_sleep(10)');
+        },
         [drivers.MySQL]: function () {
           return knexDb.raw('SELECT SLEEP(10)');
         },
@@ -1021,15 +1079,19 @@ module.exports = function (knex) {
 
       // We must use the original knex instance without the exhausted pool to list running queries
       const getProcessesForDriver = {
-        pg: async () => {
+        [drivers.PostgreSQL]: async () => {
           const results = await knex.raw('SELECT * from pg_stat_activity');
           return _.map(_.filter(results.rows, { state: 'active' }), 'query');
         },
-        mysql: async () => {
+        [drivers.PgNative]: async () => {
+          const results = await knex.raw('SELECT * from pg_stat_activity');
+          return _.map(_.filter(results.rows, { state: 'active' }), 'query');
+        },
+        [drivers.MySQL]: async () => {
           const results = await knex.raw('SHOW PROCESSLIST');
           return _.map(results[0], 'Info');
         },
-        mysql2: async () => {
+        [drivers.MySQL2]: async () => {
           const results = await knex.raw('SHOW PROCESSLIST');
           return _.map(results[0], 'Info');
         },
@@ -1046,7 +1108,7 @@ module.exports = function (knex) {
       try {
         const promise = query.timeout(50, { cancel: true }).then(_.identity);
 
-        await delay(10);
+        await delay(15);
         const processesBeforeTimeout = await getProcesses();
         expect(processesBeforeTimeout).to.include(query.toString());
 
@@ -1065,7 +1127,7 @@ module.exports = function (knex) {
 
     it('.timeout(ms, {cancel: true}) should release connections after failing if connection cancellation throws an error', async function () {
       // Only mysql/postgres query cancelling supported for now
-      if (!isPostgreSQL(knex)) {
+      if (!isPostgreSQL(knex) || isPgNative(knex)) {
         return this.skip();
       }
 
@@ -1079,6 +1141,8 @@ module.exports = function (knex) {
       const rawTestQueries = {
         [drivers.PostgreSQL]: (sleepSeconds) =>
           `SELECT pg_sleep(${sleepSeconds})`,
+        [drivers.PgNative]: (sleepSeconds) =>
+          `SELECT pg_sleep(${sleepSeconds})`,
       };
 
       const driverName = knex.client.driverName;
@@ -1097,11 +1161,15 @@ module.exports = function (knex) {
       const originalWrappedCancelQueryCall =
         knexPrototype._wrappedCancelQueryCall;
 
-      knexPrototype._wrappedCancelQueryCall = (conn) => {
-        return knexPrototype.query(conn, {
-          method: 'raw',
-          sql: 'TestError',
-        });
+      knexPrototype._wrappedCancelQueryCall = (conn, connectionToKill) => {
+        if (isPgNative(knex)) {
+          throw new Error('END THIS');
+        } else {
+          return knexPrototype.query(conn, {
+            method: 'raw',
+            sql: 'TestError',
+          });
+        }
       };
 
       const queryTimeout = 10;
diff --git a/test/integration/query/inserts.js b/test/integration/query/inserts.js
index 98b3ae9c..3d14d598 100644
--- a/test/integration/query/inserts.js
+++ b/test/integration/query/inserts.js
@@ -1130,35 +1130,32 @@ module.exports = function (knex) {
         items.push(item);
       }
 
-      beforeEach(function () {
-        return knex.schema.dropTableIfExists('BatchInsert').then(function () {
-          return knex.schema.createTable('BatchInsert', function (table) {
-            for (let i = 0; i < amountOfColumns; i++) {
-              table.string('Col' + i, 50);
-            }
-          });
+      beforeEach(async () => {
+        await knex.schema.dropTableIfExists('BatchInsert');
+        await knex.schema.createTable('BatchInsert', (table) => {
+          for (let i = 0; i < amountOfColumns; i++) {
+            table.string('Col' + i, 50);
+          }
         });
       });
 
-      it('#757 - knex.batchInsert(tableName, bulk, chunkSize)', function () {
+      it('#757 - knex.batchInsert(tableName, bulk, chunkSize)', async function () {
         this.timeout(30000);
-        return knex
+        const result = await knex
           .batchInsert('BatchInsert', items, 30)
-          .returning(['Col1', 'Col2'])
-          .then(function (result) {
-            //Returning only supported by some dialects.
-            if (isPostgreSQL(knex) || isOracle(knex)) {
-              result.forEach(function (item) {
-                expect(item.Col1).to.equal(fiftyLengthString);
-                expect(item.Col2).to.equal(fiftyLengthString);
-              });
-            }
-            return knex('BatchInsert').select();
-          })
-          .then(function (result) {
-            const count = result.length;
-            expect(count).to.equal(amountOfItems);
+          .returning(['Col1', 'Col2']);
+
+        //Returning only supported by some dialects.
+        if (isPostgreSQL(knex) || isOracle(knex)) {
+          result.forEach(function (item) {
+            expect(item.Col1).to.equal(fiftyLengthString);
+            expect(item.Col2).to.equal(fiftyLengthString);
           });
+        }
+
+        const selectResult = await knex('BatchInsert').select();
+        const count = selectResult.length;
+        expect(count).to.equal(amountOfItems);
       });
 
       it('#1880 - Duplicate keys in batchInsert should not throw unhandled exception', async function () {
diff --git a/test/integration/query/selects.js b/test/integration/query/selects.js
index 3bcd0665..b18c77ab 100644
--- a/test/integration/query/selects.js
+++ b/test/integration/query/selects.js
@@ -9,6 +9,7 @@ const { TEST_TIMESTAMP } = require('../../util/constants');
 const {
   isMysql,
   isPostgreSQL,
+  isPgNative,
   isMssql,
   isSQLite,
   isOracle,
@@ -38,6 +39,12 @@ module.exports = function (knex) {
             [],
             ['1', '2', '3', '4', '5', '7']
           );
+          tester(
+            'pgnative',
+            'select "id" from "accounts" order by "id" asc',
+            [],
+            ['1', '2', '3', '4', '5', '7']
+          );
           tester(
             'pg-redshift',
             'select "id" from "accounts" order by "id" asc',
@@ -83,6 +90,12 @@ module.exports = function (knex) {
             [],
             ['1', '2', '3', '4', '5', '7']
           );
+          tester(
+            'pgnative',
+            'select "accounts"."id" from "accounts" order by "accounts"."id" asc',
+            [],
+            ['1', '2', '3', '4', '5', '7']
+          );
           tester(
             'pg-redshift',
             'select "accounts"."id" from "accounts" order by "accounts"."id" asc',
@@ -129,6 +142,12 @@ module.exports = function (knex) {
             [2],
             ['3', '4', '5', '7']
           );
+          tester(
+            'pgnative',
+            'select "id" from "accounts" order by "id" asc offset ?',
+            [2],
+            ['3', '4', '5', '7']
+          );
           tester(
             'pg-redshift',
             'select "id" from "accounts" order by "id" asc offset ?',
@@ -227,6 +246,19 @@ module.exports = function (knex) {
               { id: '7' },
             ]
           );
+          tester(
+            'pgnative',
+            'select /*+ invalid() */ "id" from "accounts" order by "id" asc',
+            [],
+            [
+              { id: '1' },
+              { id: '2' },
+              { id: '3' },
+              { id: '4' },
+              { id: '5' },
+              { id: '7' },
+            ]
+          );
           tester(
             'pg-redshift',
             'select /*+ invalid() */ "id" from "accounts" order by "id" asc',
@@ -286,6 +318,12 @@ module.exports = function (knex) {
             [1],
             { id: '1', first_name: 'Test' }
           );
+          tester(
+            'pgnative',
+            'select "id", "first_name" from "accounts" order by "id" asc limit ?',
+            [1],
+            { id: '1', first_name: 'Test' }
+          );
           tester(
             'pg-redshift',
             'select "id", "first_name" from "accounts" order by "id" asc limit ?',
@@ -314,6 +352,9 @@ module.exports = function (knex) {
     });
 
     it('allows you to stream', function () {
+      if (isPgNative(knex)) {
+        return this.skip();
+      }
       let count = 0;
       return knex('accounts')
         .stream(function (rowStream) {
@@ -327,6 +368,10 @@ module.exports = function (knex) {
     });
 
     it('returns a stream if not passed a function', function (done) {
+      if (isPgNative(knex)) {
+        return this.skip();
+      }
+
       let count = 0;
       const stream = knex('accounts').stream();
       stream.on('data', function () {
@@ -498,6 +543,17 @@ module.exports = function (knex) {
                 },
               ]
             );
+            tester(
+              'pgnative',
+              'select "first_name", "last_name" from "accounts" where "id" = ?',
+              [1],
+              [
+                {
+                  first_name: 'Test',
+                  last_name: 'User',
+                },
+              ]
+            );
             tester(
               'pg-redshift',
               'select "first_name", "last_name" from "accounts" where "id" = ?',
@@ -572,6 +628,17 @@ module.exports = function (knex) {
                 },
               ]
             );
+            tester(
+              'pgnative',
+              'select "first_name", "last_name" from "accounts" where "id" = ?',
+              [1],
+              [
+                {
+                  first_name: 'Test',
+                  last_name: 'User',
+                },
+              ]
+            );
             tester(
               'pg-redshift',
               'select "first_name", "last_name" from "accounts" where "id" = ?',
@@ -634,6 +701,11 @@ module.exports = function (knex) {
               'select "email", "logins" from "accounts" where "id" > ?',
               [1]
             );
+            tester(
+              'pgnative',
+              'select "email", "logins" from "accounts" where "id" > ?',
+              [1]
+            );
             tester(
               'pg-redshift',
               'select "email", "logins" from "accounts" where "id" > ?',
@@ -700,6 +772,25 @@ module.exports = function (knex) {
                 },
               ]
             );
+            tester(
+              'pgnative',
+              'select * from "accounts" where "id" = ?',
+              [1],
+              [
+                {
+                  id: '1',
+                  first_name: 'Test',
+                  last_name: 'User',
+                  email: 'test@example.com',
+                  logins: 1,
+                  balance: 0,
+                  about: 'Lorem ipsum Dolore labore incididunt enim.',
+                  created_at: TEST_TIMESTAMP,
+                  updated_at: TEST_TIMESTAMP,
+                  phone: null,
+                },
+              ]
+            );
             tester(
               'pg-redshift',
               'select * from "accounts" where "id" = ?',
@@ -796,6 +887,12 @@ module.exports = function (knex) {
               [],
               []
             );
+            tester(
+              'pgnative',
+              'select "first_name", "email" from "accounts" where "id" is null',
+              [],
+              []
+            );
             tester(
               'pg-redshift',
               'select "first_name", "email" from "accounts" where "id" is null',
@@ -830,6 +927,12 @@ module.exports = function (knex) {
           .testSql(function (tester) {
             tester('mysql', 'select * from `accounts` where `id` = ?', [0], []);
             tester('pg', 'select * from "accounts" where "id" = ?', [0], []);
+            tester(
+              'pgnative',
+              'select * from "accounts" where "id" = ?',
+              [0],
+              []
+            );
             tester(
               'pg-redshift',
               'select * from "accounts" where "id" = ?',
@@ -944,6 +1047,37 @@ module.exports = function (knex) {
             },
           ]
         );
+        tester(
+          'pgnative',
+          'select distinct on ("id") "email", "logins" from "accounts" order by "id" asc',
+          [],
+          [
+            {
+              email: 'test@example.com',
+              logins: 1,
+            },
+            {
+              email: 'test2@example.com',
+              logins: 1,
+            },
+            {
+              email: 'test3@example.com',
+              logins: 2,
+            },
+            {
+              email: 'test4@example.com',
+              logins: 2,
+            },
+            {
+              email: 'test5@example.com',
+              logins: 2,
+            },
+            {
+              email: 'test6@example.com',
+              logins: 2,
+            },
+          ]
+        );
       });
     });
 
@@ -1034,6 +1168,25 @@ module.exports = function (knex) {
                 },
               ]
             );
+            tester(
+              'pgnative',
+              'select * from "composite_key_test" where ("column_a", "column_b") in ((?, ?), (?, ?)) order by "status" desc',
+              [1, 1, 1, 2],
+              [
+                {
+                  column_a: 1,
+                  column_b: 1,
+                  details: 'One, One, One',
+                  status: 1,
+                },
+                {
+                  column_a: 1,
+                  column_b: 2,
+                  details: 'One, Two, Zero',
+                  status: 0,
+                },
+              ]
+            );
             tester(
               'pg-redshift',
               'select * from "composite_key_test" where ("column_a", "column_b") in ((?, ?), (?, ?)) order by "status" desc',
@@ -1134,6 +1287,19 @@ module.exports = function (knex) {
                 },
               ]
             );
+            tester(
+              'pgnative',
+              'select * from "composite_key_test" where "status" = ? and ("column_a", "column_b") in ((?, ?), (?, ?))',
+              [1, 1, 1, 1, 2],
+              [
+                {
+                  column_a: 1,
+                  column_b: 1,
+                  details: 'One, One, One',
+                  status: 1,
+                },
+              ]
+            );
             tester(
               'pg-redshift',
               'select * from "composite_key_test" where "status" = ? and ("column_a", "column_b") in ((?, ?), (?, ?))',
@@ -1432,7 +1598,7 @@ module.exports = function (knex) {
               expect('Second query should have timed out').to.be.false;
             })
             .catch((err) => {
-              // mssql fails because it tires to rollback at the same time when update query is running
+              // mssql fails because it tries to rollback at the same time when update query is running
               // hopefully for share really works though...
               if (isMssql(knex)) {
                 expect(err.message).to.be.contain(
diff --git a/test/integration2/util/knex-instance-provider.js b/test/integration2/util/knex-instance-provider.js
index 49578fb2..6e85bc84 100644
--- a/test/integration2/util/knex-instance-provider.js
+++ b/test/integration2/util/knex-instance-provider.js
@@ -5,6 +5,7 @@ const testConfig =
 
 const Db = {
   PostgresSQL: 'postgres',
+  PgNative: 'pgnative',
   MySQL: 'mysql',
   MySQL2: 'mysql2',
   MSSQL: 'mssql',
@@ -12,7 +13,14 @@ const Db = {
   Oracle: 'oracledb',
 };
 
-const defaultDbs = [Db.PostgresSQL, Db.MySQL, Db.MySQL2, Db.SQLite, Db.MSSQL];
+const defaultDbs = [
+  Db.PostgresSQL,
+  Db.PgNative,
+  Db.MySQL,
+  Db.MySQL2,
+  Db.SQLite,
+  Db.MSSQL,
+];
 
 function getAllDbs() {
   return process.env.DB ? process.env.DB.split(' ') : defaultDbs;
@@ -97,6 +105,21 @@ const testConfigs = {
     seeds,
   },
 
+  pgnative: {
+    client: Db.PgNative,
+    connection: testConfig.pgnative || {
+      adapter: 'postgresql',
+      port: 25433,
+      host: 'localhost',
+      database: 'knex_test',
+      user: 'testuser',
+      password: 'knextest',
+    },
+    pool,
+    migrations,
+    seeds,
+  },
+
   sqlite3: {
     client: 'sqlite3',
     connection: testConfig.sqlite3 || ':memory:',
diff --git a/test/knexfile.js b/test/knexfile.js
index f085e09c..75163cbf 100644
--- a/test/knexfile.js
+++ b/test/knexfile.js
@@ -9,7 +9,7 @@ const _ = require('lodash');
 
 // excluding redshift, oracle, and mssql dialects from default integrations test
 const testIntegrationDialects = (
-  process.env.DB || 'sqlite3 postgres mysql mysql2 mssql oracledb'
+  process.env.DB || 'sqlite3 postgres pgnative mysql mysql2 mssql oracledb'
 ).match(/\w+/g);
 
 console.log(`ENV DB: ${process.env.DB}`);
@@ -108,6 +108,21 @@ const testConfigs = {
     seeds,
   },
 
+  pgnative: {
+    client: 'pgnative',
+    connection: testConfig.pgnative || {
+      adapter: 'postgresql',
+      port: 25433,
+      host: 'localhost',
+      database: 'knex_test',
+      user: 'testuser',
+      password: 'knextest',
+    },
+    pool,
+    migrations,
+    seeds,
+  },
+
   redshift: {
     client: 'redshift',
     connection: testConfig.redshift || {
diff --git a/test/unit/dialects/postgres.js b/test/unit/dialects/postgres.js
index cb860fa7..220b699b 100644
--- a/test/unit/dialects/postgres.js
+++ b/test/unit/dialects/postgres.js
@@ -2,7 +2,6 @@ const knex = require('../../../knex');
 const expect = require('chai').expect;
 const sinon = require('sinon');
 const pgDialect = require('../../../lib/dialects/postgres/index.js');
-const pg = require('pg');
 const _ = require('lodash');
 const { isFunction } = require('../../../lib/util/is');
 
@@ -25,10 +24,9 @@ describe('Postgres Unit Tests', function () {
       .callsFake(function () {
         return Promise.resolve('9.6');
       });
-
-    sinon.stub(pg.Client.prototype, 'connect').callsFake(function (cb) {
-      cb(null, fakeConnection);
-    });
+    sinon
+      .stub(pgDialect.prototype, '_acquireOnlyConnection')
+      .returns(Promise.resolve(fakeConnection));
   });
   afterEach(() => {
     querySpy.resetHistory();
@@ -37,18 +35,17 @@ describe('Postgres Unit Tests', function () {
     sinon.restore();
   });
 
-  it('does not resolve client version if specified explicitly', (done) => {
+  it('does not resolve client version if specified explicitly', () => {
     const knexInstance = knex({
-      client: 'postgresql',
+      client: 'postgres',
       version: '10.5',
       connection: {
         pool: {},
       },
     });
-    knexInstance.raw('select 1 as 1').then((result) => {
+    return knexInstance.raw('select 1 as 1').then((result) => {
       expect(checkVersionStub.notCalled).to.equal(true);
       knexInstance.destroy();
-      done();
     });
   });
 
@@ -75,17 +72,16 @@ describe('Postgres Unit Tests', function () {
     );
   });
 
-  it('resolve client version if not specified explicitly', (done) => {
+  it('resolve client version if not specified explicitly', () => {
     const knexInstance = knex({
       client: 'postgresql',
       connection: {
         pool: {},
       },
     });
-    knexInstance.raw('select 1 as 1').then((result) => {
+    return knexInstance.raw('select 1 as 1').then((result) => {
       expect(checkVersionStub.calledOnce).to.equal(true);
       knexInstance.destroy();
-      done();
     });
   });
 
@@ -130,12 +126,13 @@ describe('Postgres Unit Tests', function () {
         );
       });
   });
-  it('Uses documented query config as param when providing bindings', (done) => {
+
+  it('Uses documented query config as param when providing bindings', () => {
     const knexInstance = knex({
       client: 'postgresql',
       connection: {},
     });
-    knexInstance.raw('select 1 as ?', ['foo']).then((result) => {
+    return knexInstance.raw('select 1 as ?', ['foo']).then((result) => {
       sinon.assert.calledOnce(querySpy);
       sinon.assert.calledWithExactly(
         querySpy,
@@ -146,7 +143,6 @@ describe('Postgres Unit Tests', function () {
         sinon.match.func
       );
       knexInstance.destroy();
-      done();
     });
   });
 });
diff --git a/test/util/db-helpers.js b/test/util/db-helpers.js
index 6d5a54b1..b57cc6d3 100644
--- a/test/util/db-helpers.js
+++ b/test/util/db-helpers.js
@@ -6,11 +6,19 @@ function getDriverName(knex) {
 }
 
 function isPostgreSQL(knex) {
-  return getDriverName(knex) === drivers.PostgreSQL;
+  return isOneOfDbs(knex, [drivers.PostgreSQL, drivers.PgNative]);
+}
+
+function isPgNative(knex) {
+  return getDriverName(knex) === drivers.PgNative;
 }
 
 function isPgBased(knex) {
-  return isOneOfDbs(knex, [drivers.PostgreSQL, drivers.Redshift]);
+  return isOneOfDbs(knex, [
+    drivers.PostgreSQL,
+    drivers.PgNative,
+    drivers.Redshift,
+  ]);
 }
 
 function isMssql(knex) {
@@ -36,7 +44,7 @@ function isSQLite(knex) {
 /**
  *
  * @param knex
- * @param {('pg'|'pg-redshift'|'oracledb'|'mysql'|'mysql2'|'mssql'|'sqlite3')[]} supportedDbs - supported DB values in DRIVER_NAMES from lib/constants.
+ * @param {('pg'|'pgnative'|'pg-redshift'|'oracledb'|'mysql'|'mysql2'|'mssql'|'sqlite3')[]} supportedDbs - supported DB values in DRIVER_NAMES from lib/constants.
  * @returns {*}
  */
 function isOneOfDbs(knex, supportedDbs) {
@@ -49,6 +57,7 @@ module.exports = {
   isMssql,
   isOracle,
   isPostgreSQL,
+  isPgNative,
   isPgBased,
   isRedshift,
   isSQLite,