Closed joematthews closed 8 months ago
There isn't an option for that, but this can easily be done using initSql: 'SET SESSION TRANSACTION READ ONLY'
, like in
const conn = await mariadb.createConnection({
host: 'mydb.com',
user: 'myUser',
password: 'myPwd',
initSql: 'SET SESSION TRANSACTION READ ONLY'
});
Is there a need for a specific option for that, i don't know, there isn't in all other mysql connectors (for any languages)
Awesome. That's simple enough. I think it will fill the need. I'll go ahead and close this. Thank you.
I could not find a previous issue/request on this topic.
Would it be convenient (and safer) to offer a
--read-only
argument for the mariadb CLI and areadOnly
property for the config object for mariadb-connector-nodejs connections? This would make it so much easier, to use an environment variable likeDB_READ_ONLY=true
to easily disable writes.The basic idea is that a read-only property could provide a more clear and succinct way to connect to any database 'in read-only mode' without using scary, SQL-in-args that flush privileges and without creating a universal, read-only user that everyone shares.
I feel like this feature would be especially helpful to prevent accidental writes when reproducing issues and debugging using live prod data (not best practice, obviously, but it's common).
My inspiration comes from DataGrip's and DBeaver's read-only option in the connection settings allowing the same read privileges as my user but prevents writes (with zero configuration) -- and personally, I keep read-only on by default for all my production connections in these editors.
I am not a DBA, and I suspect this may end up being a bad idea in some scenarios or environments...but on the surface it sounds very helpful?