From f6380de6ad3a001c95621649f392b7ef5eec2969 Mon Sep 17 00:00:00 2001 From: Muhammad Aaqil Date: Sat, 4 Nov 2023 19:04:41 +0500 Subject: [PATCH] fix: add generated property to model properties Signed-off-by: Muhammad Aaqil --- lib/discovery.js | 9 +++++++++ test/schema.sql | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/discovery.js b/lib/discovery.js index 47b8d851..e30aeb8b 100644 --- a/lib/discovery.js +++ b/lib/discovery.js @@ -135,6 +135,13 @@ function mixinDiscovery(PostgreSQL) { cb(err, results); } else { results.map(function(r) { + // PostgreSQL returns ALWAYS in case the property is generated, + // otherwise it returns NEVER + if (r.generated === 'ALWAYS') { + r.generated = true; + } else { + r.generated = false; + } // PostgreSQL accepts float(1) to float(24) as selecting the `real` type, // while float(25) to float(53) select `double precision` // https://www.postgresql.org/docs/9.4/static/datatype-numeric.html @@ -166,6 +173,7 @@ function mixinDiscovery(PostgreSQL) { if (owner) { sql = this.paginateSQL('SELECT table_schema AS "owner", table_name AS "tableName", column_name AS "columnName",' + 'data_type AS "dataType", character_maximum_length AS "dataLength", numeric_precision AS "dataPrecision",' + + ' is_generated AS "generated",' + ' numeric_scale AS "dataScale", is_nullable AS "nullable"' + ' FROM information_schema.columns' + ' WHERE table_schema=\'' + owner + '\'' @@ -175,6 +183,7 @@ function mixinDiscovery(PostgreSQL) { sql = this.paginateSQL('SELECT current_schema() AS "owner", table_name AS "tableName",' + ' column_name AS "columnName",' + ' data_type AS "dataType", character_maximum_length AS "dataLength", numeric_precision AS "dataPrecision",' + + ' is_generated AS "generated",' + ' numeric_scale AS "dataScale", is_nullable AS "nullable"' + ' FROM information_schema.columns' + (table ? ' WHERE table_name=\'' + table + '\'' : ''), diff --git a/test/schema.sql b/test/schema.sql index 7020812c..fdbdacd4 100644 --- a/test/schema.sql +++ b/test/schema.sql @@ -319,7 +319,8 @@ CREATE TABLE inventory ( product_id character varying(20), location_id character varying(20), available integer, - total integer + total integer, + token integer GENERATED ALWAYS AS (total * 1000) STORED );