Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.raw() should allow specifying different queries for different engines #6037

Open
KernelDeimos opened this issue Mar 17, 2024 · 0 comments
Open

Comments

@KernelDeimos
Copy link

I built this in my own code outside of knex:

  _wrap_knex (db, engine) {
      let syntax = engine;
      if ( syntax === 'mysql2' ) syntax = 'mysql';
      db.case = function (choices) {
          console.log('RAW? ', syntax, choices[syntax])
          return this.raw(choices[syntax]);
      };
      return db;
  }

I didn't check out how to get client directly from knex itself but that's pretty well the only thing missing. After adding this .case() method that can be used in place of .raw(), knex gains every feature of every database without much hassle from the user of the library, and it becomes possible to migrate even the trickiest of queries. I'm a little surprised this wasn't already in here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant