Skip to content

Commit 293dc83

Browse files
aaqilnizdhmlau
authored andcommitted
fix: add generated property to model properties
Signed-off-by: Muhammad Aaqil <[email protected]>
1 parent f5d93d7 commit 293dc83

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/discovery.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ function mixinDiscovery(PostgreSQL) {
135135
cb(err, results);
136136
} else {
137137
results.map(function(r) {
138+
// PostgreSQL returns ALWAYS in case the property is generated,
139+
// otherwise it returns NEVER
140+
if (r.generated === 'ALWAYS') {
141+
r.generated = true;
142+
} else {
143+
r.generated = false;
144+
}
138145
// PostgreSQL accepts float(1) to float(24) as selecting the `real` type,
139146
// while float(25) to float(53) select `double precision`
140147
// https://www.postgresql.org/docs/9.4/static/datatype-numeric.html
@@ -166,6 +173,7 @@ function mixinDiscovery(PostgreSQL) {
166173
if (owner) {
167174
sql = this.paginateSQL('SELECT table_schema AS "owner", table_name AS "tableName", column_name AS "columnName",'
168175
+ 'data_type AS "dataType", character_maximum_length AS "dataLength", numeric_precision AS "dataPrecision",'
176+
+ ' is_generated AS "generated",'
169177
+ ' numeric_scale AS "dataScale", is_nullable AS "nullable"'
170178
+ ' FROM information_schema.columns'
171179
+ ' WHERE table_schema=\'' + owner + '\''
@@ -175,6 +183,7 @@ function mixinDiscovery(PostgreSQL) {
175183
sql = this.paginateSQL('SELECT current_schema() AS "owner", table_name AS "tableName",'
176184
+ ' column_name AS "columnName",'
177185
+ ' data_type AS "dataType", character_maximum_length AS "dataLength", numeric_precision AS "dataPrecision",'
186+
+ ' is_generated AS "generated",'
178187
+ ' numeric_scale AS "dataScale", is_nullable AS "nullable"'
179188
+ ' FROM information_schema.columns'
180189
+ (table ? ' WHERE table_name=\'' + table + '\'' : ''),

test/schema.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ CREATE TABLE inventory (
319319
product_id character varying(20),
320320
location_id character varying(20),
321321
available integer,
322-
total integer
322+
total integer,
323+
token integer GENERATED ALWAYS AS (total * 1000) STORED
323324
);
324325

325326

0 commit comments

Comments
 (0)