Improvement: show full SQL on error in REPL


#1

Hello,

I think it would be a good idea to include SQL in REPL when there is an error. It can be helpful when tracking down what is wrong in the query/model.

Right now it shows:

Error: ER_BAD_FIELD_ERROR: Unknown column ‘user_id’ in ‘where clause’

But from this it is hard to locate how the SQL actually looks like.


#2

Put this into your start/events.js and it’ll spit out all queries.

Alternatively you could probably do similar in an error handler, but the easiest, quickest option is to output sql on every query…

const Database = use('Database')

Database.on('query', async (query) => console.log(query.sql))

#3

You can do this by setting DB_DEBUG to true in your .env file also.

It will console log all the queries


#4

That’s handy. Is it documented somewhere? I haven’t run across that in the docs, buy maybe I missed it…


#5

Uf, sorry… I was using logic from one of my projects :smiley:

It’s not like that… But can be!

https://adonisjs.com/docs/4.0/database#_debugging

So, in my project i added inside config/database.js

sqlite: {
    client: 'sqlite3',
    connection: {
        filename: Helpers.databasePath(`${Env.get('DB_DATABASE', 'development')}.sqlite`)
    },
    useNullAsDefault: true,
    debug: Env.get('DB_DEBUG', false)
},

So this line is why DB_DEBUG in env file works :slight_smile:
debug: Env.get(‘DB_DEBUG’, false)