Skip to content
This repository has been archived by the owner on Nov 9, 2021. It is now read-only.

Use a normal SQL string #376

Open
basickarl opened this issue Jan 30, 2019 · 2 comments
Open

Use a normal SQL string #376

basickarl opened this issue Jan 30, 2019 · 2 comments

Comments

@basickarl
Copy link

basickarl commented Jan 30, 2019

I have functions which require a squel object. I have however written the SQL string myself without using this library.

Is there a way to insert the raw SQL string statement into a squel object?

@basickarl basickarl reopened this Jan 30, 2019
@thomashamlin
Copy link

There isn't; squel is simply an SQL string builder.

To execute raw SQL, send it directly to your DB connection. E.g. if you're using https://github.com/mysqljs/mysql, something like this works:

const mysql = require('mysql')
const connection = mysql.createConnection({ ... }).connect()
connection.query('SELECT * FROM tbl', (error, results, fields) => {
  ...
})

If your function expect squel objects, you could try to reverse engineer the method(s) they end up calling and pass an object that implements those. Perhaps simply implementing toString() (returns your SQL string) would do the trick?

@victornpb
Copy link

victornpb commented Feb 7, 2019

If it doesn't further compose your query you can fake it by doing something like this:

const fakeSquel = { toString(){ return 'SELECT * FROM table'; }};

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

No branches or pull requests

3 participants