Giter Site home page Giter Site logo

Comments (10)

steveschmitt avatar steveschmitt commented on May 7, 2024 5

Added -v or --views option in release 0.6.7

from sequelize-auto.

atulhm avatar atulhm commented on May 7, 2024 2

i'm using mysql and the views generate models.

from sequelize-auto.

schleumer avatar schleumer commented on May 7, 2024 2

Same, views from Postgres are ignored 😢

from sequelize-auto.

xorbis avatar xorbis commented on May 7, 2024 1

Seems you are wrong.
https://www.postgresql.org/docs/9.2/static/sql-createview.html

If I can SELECT it, it can be a model, no?

from sequelize-auto.

eriendel avatar eriendel commented on May 7, 2024

In postgres there are no models for views generated

from sequelize-auto.

lpatoyst avatar lpatoyst commented on May 7, 2024

In postgresql views seem to be ignored...

from sequelize-auto.

xcxooxl avatar xcxooxl commented on May 7, 2024

apply this with patch-package:
should allow you to use views.

diff --git a/node_modules/sequelize-auto/lib/index.js b/node_modules/sequelize-auto/lib/index.js
index 182763b..f128330 100644
--- a/node_modules/sequelize-auto/lib/index.js
+++ b/node_modules/sequelize-auto/lib/index.js
@@ -69,15 +69,22 @@ AutoSequelize.prototype.build = function(callback) {
     }, _callback);
   }
 
-  if (this.dialect.showTablesQuery) {
-    const showTablesSql = this.dialect.showTablesQuery(self.options.schema);
-    self.sequelize.query(showTablesSql, {
-      raw: true,
-      type: self.sequelize.QueryTypes.SELECT
-    }).then(processTables, callback);
-  } else {
-    this.queryInterface.showAllTables().then(processTables, callback);
-  }
+  this.queryInterface.showAllSchemas().then(schemas => {
+    let tablesAndViews = [];
+    schemas.forEach(async schema => {
+      const showAllTablesAndViewsQuery =
+          'SELECT table_name FROM ' +
+          'information_schema.tables WHERE' +
+          ' (table_type LIKE \'%TABLE\' or table_type LIKE \'%VIEW\')\n' + 'AND table_name != \'spatial_ref_sys\' and table_schema = ' + schema
+
+      tablesAndViews =  [...await self.sequelize.query(showTablesSql, {
+        raw: true,
+        type: self.sequelize.QueryTypes.SELECT
+      }),...tablesAndViews]
+    });
+    return tablesAndViews;
+  }).then(processTables,callback)
+
 
   function processTables(tables) {
     function compareFn(a, b) {

from sequelize-auto.

steveschmitt avatar steveschmitt commented on May 7, 2024

Some people want models generated from views, and some don't.
I'm going to add a command-line flag to control whether views are generated.

from sequelize-auto.

polarspark avatar polarspark commented on May 7, 2024

Please add this for mssql as well. I make heavy use of MSSQL views that I need to pull data from.

from sequelize-auto.

BibbyChung avatar BibbyChung commented on May 7, 2024

i change file and test it in postgre. it's working. maybe it's useful for you.

# node_modules/sequelize-auto/lib/dialects/index.js

function showTablesGeneric(schemaName) {
  return `SELECT table_name, table_schema
            FROM information_schema.tables
           WHERE (table_type = 'BASE TABLE'
                 ${makeCondition("table_schema", schemaName)})
                 OR (table_type = 'VIEW' AND table_schema = 'public')`;
}

from sequelize-auto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.