Explicit jsonb support for custom pg clients (#5201)

Co-authored-by: Igor Savin <iselwin@gmail.com>
This commit is contained in:
Hasnae 2022-09-01 05:16:17 +10:00 committed by GitHub
parent 1cc1df9c35
commit 97fccdff7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 0 deletions

View File

@ -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';

View File

@ -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'
);
});
});
});
});

1
types/index.d.ts vendored
View File

@ -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;