Skip to content

Commit

Permalink
fix: bigint mapping for arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
aldis-ameriks committed Sep 4, 2020
1 parent ea6dded commit 69b0ec9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
7 changes: 5 additions & 2 deletions lib/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ const typeMapping = {
bigint: [],
object: ['json', 'jsonb'],
Date: ['timestamp', 'timestamptz'],
'Array<string>': ['_bpchar', '_char', '_varchar', '_text', '_uuid', '_bytea', '_inet', '_int8', '_time', '_timetz', '_interval', '_name'],
'Array<string>': ['_bpchar', '_char', '_varchar', '_text', '_uuid', '_bytea', '_inet', '_time', '_timetz', '_interval', '_name'],
'Array<number>': ['_int2', '_int4', '_float4', '_float8', '_numeric', '_money', '_oid'],
'Array<boolean>': ['_bool'],
'Array<object>': ['_json', '_jsonb'],
'Array<Date>': ['_timestamp', '_timestamptz']
'Array<Date>': ['_timestamp', '_timestamptz'],
'Array<bigint>': []
}

function getTableDefinitions (sql, schema) {
Expand Down Expand Up @@ -52,8 +53,10 @@ async function getSchemaDefinition (opts) {

if (bigint) {
typeMapping.bigint.push('int8')
typeMapping['Array<bigint>'].push('_int8')
} else {
typeMapping.string.push('int8')
typeMapping['Array<string>'].push('_int8')
}

if (dateAsString) {
Expand Down
4 changes: 2 additions & 2 deletions tap-snapshots/test-cli.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export interface TypeEntity {
avatar_rozella: Array<string>;
camelCase: boolean | null;
category_amari: number;
category_april: Array<string>;
category_april: Array<bigint>;
category_buddy: Array<string> | null;
category_clementine: number | null;
category_marcelle: Date | null;
Expand Down Expand Up @@ -352,7 +352,7 @@ export interface TypeEntity {
group_jedediah: Array<Date>;
group_shanny: Date;
group_toby: string;
group_ulices: Array<string> | null;
group_ulices: Array<bigint> | null;
id_gay: string;
id_hailee: object;
id_helen: Array<number> | null;
Expand Down
28 changes: 23 additions & 5 deletions tap-snapshots/test-postgres.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ Object {
},
],
"typeMapping": Object {
"Array<bigint>": Array [],
"Array<boolean>": Array [
"_bool",
],
Expand Down Expand Up @@ -632,11 +633,11 @@ Object {
"_uuid",
"_bytea",
"_inet",
"_int8",
"_time",
"_timetz",
"_interval",
"_name",
"_int8",
],
"bigint": Array [],
"boolean": Array [
Expand Down Expand Up @@ -1276,6 +1277,9 @@ Object {
},
],
"typeMapping": Object {
"Array<bigint>": Array [
"_int8",
],
"Array<boolean>": Array [
"_bool",
],
Expand Down Expand Up @@ -1308,11 +1312,13 @@ Object {
"_uuid",
"_bytea",
"_inet",
"_int8",
"_time",
"_timetz",
"_interval",
"_name",
"_int8",
"_int8",
"_int8",
],
"bigint": Array [
"int8",
Expand Down Expand Up @@ -1959,6 +1965,9 @@ Object {
},
],
"typeMapping": Object {
"Array<bigint>": Array [
"_int8",
],
"Array<boolean>": Array [
"_bool",
],
Expand Down Expand Up @@ -1991,11 +2000,14 @@ Object {
"_uuid",
"_bytea",
"_inet",
"_int8",
"_time",
"_timetz",
"_interval",
"_name",
"_int8",
"_int8",
"_int8",
"_int8",
"_date",
],
"bigint": Array [
Expand Down Expand Up @@ -2645,6 +2657,9 @@ Object {
},
],
"typeMapping": Object {
"Array<bigint>": Array [
"_int8",
],
"Array<boolean>": Array [
"_bool",
],
Expand Down Expand Up @@ -2676,11 +2691,12 @@ Object {
"_uuid",
"_bytea",
"_inet",
"_int8",
"_time",
"_timetz",
"_interval",
"_name",
"_int8",
"_int8",
],
"bigint": Array [
"int8",
Expand Down Expand Up @@ -3325,6 +3341,7 @@ Object {
},
],
"typeMapping": Object {
"Array<bigint>": Array [],
"Array<boolean>": Array [
"_bool",
],
Expand Down Expand Up @@ -3355,11 +3372,12 @@ Object {
"_uuid",
"_bytea",
"_inet",
"_int8",
"_time",
"_timetz",
"_interval",
"_name",
"_int8",
"_int8",
],
"bigint": Array [],
"boolean": Array [
Expand Down

0 comments on commit 69b0ec9

Please sign in to comment.