abelosorio / sequelize-views-support Goto Github PK
View Code? Open in Web Editor NEWAdds VIEWS support to Sequelize
Home Page: https://www.npmjs.com/package/sequelize-views-support
License: MIT License
Adds VIEWS support to Sequelize
Home Page: https://www.npmjs.com/package/sequelize-views-support
License: MIT License
View creation works as expected but when I try to issue a model.findAll
on the view I get a UnhandledPromiseRejectionWarning: SequelizeDatabaseError: relation "my_view" does not exist
.
Am I using the package in a way that was not intended?
Thanks!
The situation is that i have a already defined schema so I cannot do force sync. On normal table the soft sync does work. You even can add a view on a already existent schema. But when trying to do a soft sync when you have already, the error is thrown: Table 'myView' already exists
.
import Sequelize from 'sequelize-views-support';
^^^^^^
SyntaxError: Unexpected token import
$ node -v
v8.2.0
In some specific cases you may need sync the model individually MyModel.sync
. For some reasons you disabled this capability for views.
https://github.com/abelosorio/sequelize-views-support/blob/master/src/model-views-support.js#L15s
Is there a reason for that?
My specific situation is related to my other issue #4.
After seeing that I cannot do soft sync, I thought I can sync the view individually and catch that exception and ignore it.
When I installed this package, I got this dependency tree:
info All dependencies
├─ @types/[email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
└─ [email protected]
However in the package.json of this package sequelize@^6.0.0 is in the dependencies. And Sequelize 6 is not even out yet. Can someone explain this discrepancy?
I am currently using Sequelize 5 in my project. Is this package only compatible with Sequelize 4?
"dependencies": {
"pg": "^8.5.1",
"sequelize": "^6.5.0"
},
If I upgrade to the latest version of pg and sequelize, queryInterface becomes camelCase.
static drop(options) {
const method = this.options.treatAsView ? 'dropView' : 'dropTable';
return this.queryInterface[method](
this.getTableName(options), options
);
}
static syncView(options) {
return this.queryInterface.createView(
this.getTableName(options),
this.getViewDefinition(),
options
);
}
Is there any reason why you are using the pg@7 package. That package has known issues with Sequelize. Would you be willing to set your package.json file to ^6.1.2
Inside query-interface-views-support.js, on line 4, you have
const sql = DROP VIEW IF EXISTS "${viewName}"${options.cascade && ' CASCADE'}
;
That creates "DROP VIEW IF EXISTS someViewundefined"
It should be
const sql = DROP VIEW IF EXISTS "${viewName}" ${options.cascade ? 'CASCADE': ''}
;
I couldn't create a view. Below is my code.
Model.js
module.exports = (sequelize, DataTypes) => {
const VwBackscattering = sequelize.define('vw_backscattering', {
capture_datetime: DataTypes.DATE,
bb_470nm:DataTypes.DOUBLE,
bb_532nm:DataTypes.DOUBLE,
bb_650nm: DataTypes.DOUBLE,
boat_datetime: DataTypes.DATE,
rainfall: DataTypes.DOUBLE,
temperature: DataTypes.DOUBLE,
latitude: DataTypes.DOUBLE,
longitude: DataTypes.DOUBLE
},
{
treatAsView: true,
viewDefinition: `
CREATE VIEW "vw_backscattering" AS
'SELECT t1.*, t2.*,
'ST_SetSRID(ST_MakePoint(t2.longitude, t2.latitude), 4326) as point_geom
'FROM backscatterings t1 INNER JOIN
' ancillary_data t2 ON t1.capture_datetime = t2.boat_datetime;`
});
return VwBackscattering;
};
index.js
const Sequelize = require('sequelize-views-support');
const view = require('./models/VwBackscattering');
const VwBackscattering = view(db, Sequelize.DataTypes)
VwBackscattering.sync().then(() => {
console.log('VwBackscattering table created');
});
module.exports = VwBackscattering;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.