Skip to content

Commit

Permalink
Merge pull request #2 from shabalindn/convert_json
Browse files Browse the repository at this point in the history
fix: convert json
  • Loading branch information
shabalindn committed Apr 19, 2024
2 parents 21590d5 + 09617aa commit 5545c2d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/helpers/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const configs: TConverterConfig = {
quote: true,
},
json: {
process: (value) => JSON.stringify(value),
quote: true,
process: (value) => `'${JSON.stringify(value)}'::jsonb`,
quote: false,
},
date: {
process: (value) => value?.toISOString(),
Expand Down
14 changes: 14 additions & 0 deletions tests/upsert.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ describe('upsert', () => {
}).toThrow();
});

it('JSONB', () => {
const sql = upsert({
table: { name: 'table', pk: 'table_id' },
params: {
table_id: ['id', 'string'],
list: [['asd', 'fgh'], 'json'],
object: [{ "a": 1, "b": 'string' }, 'json'],
},
});

console.log(sql)
expect(sql).toContain(`'["asd","fgh"]'::jsonb, '{"a":1,"b":"string"}'::jsonb`);
});

it('Array', () => {
const sql = upsert({
table: { name: 'table', pk: 'table_id' },
Expand Down

0 comments on commit 5545c2d

Please sign in to comment.