Sails: Make native query in standalone Waterline

Created on 13 Apr 2018  路  13Comments  路  Source: balderdashy/sails

Waterline version: 0.13.3
Node version: 8.11.1
NPM version: 5.8.0
Operating system: Ubuntu 17.10



Hello!

When I trying to use Waterline in standalone mode, I could not find the correct method to perform native queries. With Sails.JS the sendNativeQuery method is used which I could not find in the instances of the models. Does anyone know how I can perform these queries?

Thank you!
`Waterline.start(waterlineConfig, function(err, orm) {
if (err) {
return console.error(err);
}

        Waterline.getModel('User', orm).sendNativeQuery(sql);

        console.log(orm);

    });`
helpful info or workaround orm proposal

Most helpful comment

+1

All 13 comments

Hi @Dragons0458! It looks like you missed a step or two when you created your issue. Please edit your comment (use the pencil icon at the top-right corner of the comment box) and fix the following:

  • Verify "I am experiencing a concrete technical issue with Waterline (ideas and feature proposals should follow the guide for proposing features and enhancements (http://bit.ly/sails-feature-guide), which involves making a pull request). If you're not 100% certain whether it's a bug or not, that's okay--you may continue. The worst that can happen is that the issue will be closed and we'll point you in the right direction."
  • Verify "I am not asking a question about how to use Waterline or about whether or not Waterline has a certain feature (please refer to the documentation(http://sailsjs.org), or post on http://stackoverflow.com, our Google Group (http://bit.ly/sails-google-group) or our live chat (https://gitter.im/balderdashy/sails)."
  • Verify "I have already searched for related issues, and found none open (if you found a related _closed_ issue, please link to it in your post)."
  • Verify "My issue title is concise, on-topic and polite."
  • Verify "I can provide steps to reproduce this issue that others can follow."

As soon as those items are rectified, post a new comment (e.g. “Ok, fixed!”) below and we'll take a look. Thanks!

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected]

Ok, fixed!

@Dragons0458 Thanks for posting, we'll take a look as soon as possible.


For help with questions about Sails, click here. If you’re interested in hiring @sailsbot and her minions in Austin, click here.

+1

+1

Still not exist?

Having the same problem one solution I found to get around immediately was, a rather ugly solution.:

await new Promise(async (acp, rjt) => {
        await Banks._adapter.mongodb(config.database.host, async (err, db) => {
          if (err) {
            rjt();
          }
          let data = await db.collection("accounts").aggregate(where);
          acp(await data.toArray());
        });
      });

Ok, fixed!

Can you please post solution?

@macpatel, they were replying to sailsbot, as in they fixed their github issue format. Unfortunately no response from sails folks yet.

@tswayne @macpatel @tharyckgusmao @ImTheDeveloper @Dragons0458 - Hey everyone, we're currently moving all the Waterline issues to Sails (balderdashy/sails) for greater exposure and status monitoring. We appreciate all the efforts on this proposal so far. I apologize this one hasn't had a response from us yet and will be sure to bring it up to the team and get back to everyone. Thanks.

@tswayne @macpatel @tharyckgusmao @ImTheDeveloper @Dragons0458

Alright, I brought this up with the team and came to the conclusion that this can eventually change to become easier in a future release when we pull sails-hook-orm鈥檚 datastore methods into the Waterline core.

Currently, to send a native query using Waterline standalone, you鈥檙e responsible for getting and maintaining your own connection, using sendNativeQuery() provided on the .driver and releasing the connection when you鈥檙e finished.

The solution for the foreseeable future is to use the .driver method. If it's feasible, you can also try out Sails' built-in Waterline at the moment.

@johnabrams7 Very cool is the initiative and the return to the class.

As I moved away from the project that worked, I can not give you feedback.
But anyway thank you very much.

Having the same problem one solution I found to get around immediately was, a rather ugly solution.:

await new Promise(async (acp, rjt) => {
        await Banks._adapter.mongodb(config.database.host, async (err, db) => {
          if (err) {
            rjt();
          }
          let data = await db.collection("accounts").aggregate(where);
          acp(await data.toArray());
        });
      });

thanks it works for me

Was this page helpful?
0 / 5 - 0 ratings