Skip to content

Commit

Permalink
fix: add generated property to model properties
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammad Aaqil <[email protected]>
  • Loading branch information
aaqilniz authored and dhmlau committed Nov 13, 2023
1 parent f5d93d7 commit 293dc83
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 + '\''
Expand All @@ -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 + '\'' : ''),
Expand Down
3 changes: 2 additions & 1 deletion test/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
);


Expand Down

0 comments on commit 293dc83

Please sign in to comment.