From 3cf452e2dd8ea8451d14a01691568e9cdb2b09ed Mon Sep 17 00:00:00 2001 From: rrindels Date: Tue, 30 Apr 2024 14:05:31 -0500 Subject: [PATCH 1/3] Update SQL.js to fix head operations for pg engine. Postgres requires the "length" function vs "len" function as some SQL engines us, this patch would add the correct wrapping in the getBlobSizefn --- engines/SQL.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/engines/SQL.js b/engines/SQL.js index 74d5e2e..4ec2459 100644 --- a/engines/SQL.js +++ b/engines/SQL.js @@ -85,7 +85,22 @@ module.exports = class SQLEngine extends Component { // some column name aliases to adjust to default DB case let CREATED = 'created' let UPDATED = 'updated' - + + /*Postgres requires "length" instead of len for bytea fields. Noticed failures during head operations. + The other option would be to create a postgres function called len() on setup create which wraps the length() operation. + CREATE OR REPLACE FUNCTION len(byteafield bytea) + RETURNS int AS + $$ + BEGIN + RETURN length(byteafield); + END; + $$ + LANGUAGE plpgsql IMMUTABLE; + */ + if (this.client === 'pg'){ + this.getBlobSizefn = "length(\"V\")" + } + if (this.client === 'mssql') { this.getBlobSizeFn = 'len(V)' this.mergeStmt = ` From d71a3ffa1350d3539a0f3e70ea1a67c84b61b20c Mon Sep 17 00:00:00 2001 From: rrindels Date: Wed, 1 May 2024 00:44:20 -0500 Subject: [PATCH 2/3] Update SQL.js to quote "V" field in getBlobSizefn for pg --- engines/SQL.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/engines/SQL.js b/engines/SQL.js index 4ec2459..f16f45e 100644 --- a/engines/SQL.js +++ b/engines/SQL.js @@ -86,19 +86,10 @@ module.exports = class SQLEngine extends Component { let CREATED = 'created' let UPDATED = 'updated' - /*Postgres requires "length" instead of len for bytea fields. Noticed failures during head operations. - The other option would be to create a postgres function called len() on setup create which wraps the length() operation. - CREATE OR REPLACE FUNCTION len(byteafield bytea) - RETURNS int AS - $$ - BEGIN - RETURN length(byteafield); - END; - $$ - LANGUAGE plpgsql IMMUTABLE; - */ + // Postgres requires quoted "V" field since the schema was created with the quoted "V" field. + T if (this.client === 'pg'){ - this.getBlobSizefn = "length(\"V\")" + this.getBlobSizefn = 'length("V")' } if (this.client === 'mssql') { From 841636cb991bf48ade9402f661e5f2a4f07455f6 Mon Sep 17 00:00:00 2001 From: rrindels Date: Wed, 1 May 2024 00:46:10 -0500 Subject: [PATCH 3/3] Update SQL.js --- engines/SQL.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/SQL.js b/engines/SQL.js index f16f45e..5ca8fec 100644 --- a/engines/SQL.js +++ b/engines/SQL.js @@ -87,7 +87,7 @@ module.exports = class SQLEngine extends Component { let UPDATED = 'updated' // Postgres requires quoted "V" field since the schema was created with the quoted "V" field. - T + if (this.client === 'pg'){ this.getBlobSizefn = 'length("V")' }