Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Postgres Malformed array literal 2.4.0 Regression #5439

Merged
merged 2 commits into from Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/client.js
Expand Up @@ -216,11 +216,11 @@ class Client extends EventEmitter {
const DEFAULT_ACQUIRE_TIMEOUT = 60000;
const timeouts = [
this.config.acquireConnectionTimeout,
poolConfig.acquireTimeoutMillis
poolConfig.acquireTimeoutMillis,
].filter((timeout) => timeout !== undefined);

if (!timeouts.length) {
timeouts.push(DEFAULT_ACQUIRE_TIMEOUT)
timeouts.push(DEFAULT_ACQUIRE_TIMEOUT);
}

// acquire connection timeout can be set on config or config.pool
Expand Down Expand Up @@ -401,7 +401,7 @@ class Client extends EventEmitter {
if (i > 0) str += ', ';
let value = values[i];
// json columns can have object in values.
if (isPlainObject(value) || Array.isArray(value)) {
if (isPlainObject(value)) {
value = JSON.stringify(value);
}
str += this.parameter(
Expand Down
35 changes: 34 additions & 1 deletion test/integration2/query/insert/inserts.spec.js
Expand Up @@ -1982,7 +1982,7 @@ describe('Inserts', function () {
expect(row3 && row3.name).to.equal('AFTER');
});

it('update values on conflit with "where" condition and partial unique index #4590', async function () {
it('update values on conflict with "where" condition and partial unique index #4590', async function () {
if (!isPostgreSQL(knex) && !isSQLite(knex)) {
return this.skip();
}
Expand Down Expand Up @@ -2100,6 +2100,39 @@ describe('Inserts', function () {
});
});
});

it('should insert arrays into postgres array columns #5365', async function () {
if (!isPostgreSQL(knex)) {
return this.skip();
}

await knex.schema.dropTableIfExists('redirect_array');
await knex.schema.createTable('redirect_array', (table) => {
table.increments();
table.string('name');
table.specificType('redirect_urls', 'text ARRAY');
});

await knex('redirect_array')
.insert(
{
name: 'knex',
redirect_urls: [
'https://knexjs.org/',
'https://knexjs.org/guide/',
],
},
'id'
)
.testSql(function (tester) {
tester(
'pg',
'insert into "redirect_array" ("name", "redirect_urls") values (?, ?) returning "id"',
['knex', ['https://knexjs.org/', 'https://knexjs.org/guide/']],
[{ id: 1 }]
);
});
});
});
});
});