Bookshelfjs ORM How to get or see SQL statement its building
See original GitHub issueWhen building ORM query, I want to see what the actual (raw) query is that is executed.
For example in Rails we can do like this:
User.where(name: 'Oscar').to_sql
# => SELECT "users".* FROM "users" WHERE "users"."name" = 'Oscar'
This feature present in Bookshelfjs? or any other way to get this?
Issue Analytics
- State:
- Created 7 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Bookshelfjs ORM How to get or see SQL statement its building
Looks like there is no direct way to get SQL statement like Rails produce.. You can use .query() .toSQL() or .query() .toString().
Read more >Bookshelf.js | Home
Bookshelf is a JavaScript ORM for Node.js, built on the Knex SQL query builder. It features both Promise-based and traditional callback interfaces, transaction ......
Read more >Learn Bookshelf JS - A NodeJS ORM with Knex Query Builder
Bookshelf is a JavaScript ORM for Node. js, built on the Knex SQL query builder. It can work with PostgreSQL, MySQL, and SQLite3....
Read more >Bookshelf.js: A Node.js ORM - Stack Abuse
js ORM packages. It stems from the Knex.js, which is a flexible query builder that works with PostgreSQL, MySQL and SQLite3. Bookshelf.js builds ......
Read more >Getting Started with Bookshelf.js - SitePoint
There are many ORM libraries that exist for Node.js, the popular ones being ... We need knex query builder because bookshelf depends on...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @raj-optisol
You can use
.query()
.toSQL()
or.query()
.toString()
. But achieving exact result as in Rails is a bit more complicated as queries may be not complete. The cause is that many statements get applied just before performing the query in Bookshelf. For example Bookshelf relations behave so. Also many plugins use events to apply query statements. If you want to debug the queries then I would suggest you to use Knex#debug instead. For exampleIt prints the debug info in the console.
If you run with
DEBUG=knex:query
it will print queries but it will be something like:If you need to see more - you can patch current code and add custom logging:
Output will be: