Giter Site home page Giter Site logo

abelosorio / sequelize-views-support Goto Github PK

View Code? Open in Web Editor NEW
28.0 4.0 10.0 157 KB

Adds VIEWS support to Sequelize

Home Page: https://www.npmjs.com/package/sequelize-views-support

License: MIT License

JavaScript 100.00%
sequelize views postgresql nodejs

sequelize-views-support's People

Contributors

abelosorio avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sequelize-views-support's Issues

SequelizeDatabaseError: relation "my_view" does not exist

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!

"Table 'myView' already exists" on soft sync

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.

Use latest version of Sequelize

When I installed this package, I got this dependency tree:

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?

upgrade to pg v8 and sequelize v6

"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
    );
  }

[email protected] support

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

DROP VIEW failing

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': ''};

View couldn't be created

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;

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.