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: add generated property to model properties #622

Merged
merged 1 commit into from
Nov 13, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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