Skip to content

Commit

Permalink
Explicit jsonb support for custom pg clients (#5201)
Browse files Browse the repository at this point in the history
Co-authored-by: Igor Savin <iselwin@gmail.com>
  • Loading branch information
viqueen and kibertoad committed Aug 31, 2022
1 parent 1cc1df9 commit 97fccdf
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/dialects/postgres/schema/pg-columncompiler.js
Expand Up @@ -145,6 +145,7 @@ function jsonColumn(client, jsonb) {
if (
!client.version ||
client.config.client === 'cockroachdb' ||
client.config.jsonbSupport === true ||
parseFloat(client.version) >= 9.2
) {
return jsonb ? 'jsonb' : 'json';
Expand Down
35 changes: 35 additions & 0 deletions test/unit/schema-builder/postgres.js
Expand Up @@ -93,6 +93,41 @@ describe('PostgreSQL Config', function () {
);
});
});

describe('check custom pg client', function () {
it('jsonb as text', function () {
knexInstance = knex({
...config,
version: 'custom-pg',
jsonbSupport: false,
});
tableSql = knexInstance.schema
.table('public', function (t) {
t.jsonb('test_name');
})
.toSQL();
equal(1, tableSql.length);
expect(tableSql[0].sql).to.equal(
'alter table "public" add column "test_name" text'
);
});
it('jsonb', function () {
knexInstance = knex({
...config,
version: 'custom-pg',
jsonbSupport: true,
});
tableSql = knexInstance.schema
.table('public', function (t) {
t.jsonb('test_name');
})
.toSQL();
equal(1, tableSql.length);
expect(tableSql[0].sql).to.equal(
'alter table "public" add column "test_name" jsonb'
);
});
});
});
});

Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Expand Up @@ -2699,6 +2699,7 @@ export declare namespace Knex {
debug?: boolean;
client?: string | typeof Client;
dialect?: string;
jsonbSupport?: boolean;
version?: string;
connection?: string | StaticConnectionConfig | ConnectionConfigProvider;
pool?: PoolConfig;
Expand Down

0 comments on commit 97fccdf

Please sign in to comment.