Giter Club home page Giter Club logo

Comments (2)

valtlfelipe avatar valtlfelipe commented on July 22, 2024

I think this is a sequelize specific question, but maybe this helps you:

Use .getDb() to get the sequelize instance.

db.getModel(sequelizeModel).findAll({
     $and: [
          sequelize.where(sequelize.col('attachment_types'), '@>', sequelize.literal('[{id:2}]::jsonb'));
    ]
});

Also check the docs http://docs.sequelizejs.com/manual/tutorial/querying.html#jsonb.

The upgrade is currently stopped, haven't much time to work on it 😞 .

from hapi-sequelizejs.

jberall avatar jberall commented on July 22, 2024

Thanks for the help.
I thought you might want to add notes to the readme.
I found the solution. The critical point is to use the db.sequelize from hapi-sequelizejs, otherwise it doesn't work.
Also the Operators (http://docs.sequelizejs.com/manual/tutorial/querying.html#operators) don't seem to be accessable so we have to just include them directly.

                db.getModel(model).findAll({
                    where: {
                        attachment_types: { '@>': db.sequelize.literal('\'[{"id":3}]\'::jsonb') }
                    }
                })
                    .then((qry) => {
                        return reply(qry);
                    })
                    .catch((err) => {
                        return reply({ err });
                    });

So to use raw queries it is
db.sequelize
.query('select * ...')
.spread((results, metadata) => {
// Results will be an empty array and metadata will contain the number of affected rows.
console.log(results);
console.log(metadata);
});

Best Regards,
Jonathan

from hapi-sequelizejs.

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.