sql

grav 2025-02-10T08:54:40.142869Z

next.jdbc: I'm trying to get a read-only connection to a MySQL db, and it's a bit confusing. Seems the :read-only keyword is not having any effect.

seancorfield 2025-02-11T17:14:34.537939Z

@grav I didn't see it, but did you create a GH issue about this?

grav 2025-02-11T22:35:29.036609Z

Nope, looked through the code, and it seems like next.jdbc is adhering to :read-only, so I'm still thinking it's an error on my side

grav 2025-02-11T22:37:25.359139Z

Unless make-connection is never getting called, I can't see why it shouldn't work. I'll try again and see if I can repo. Maybe check out the source and step-debug

seancorfield 2025-02-11T22:38:25.003599Z

Thanks @grav -- I look forward to hearing what you figure out!

grav 2025-02-10T08:57:25.381169Z

Here's a snippet:

(let [c (jdbc/get-connection (assoc db-conn {:read-only true}))]
    #_(jdbc/execute! c ["SET SESSION TRANSACTION READ ONLY;"])
    (jdbc/execute! c
                   ["drop database if exists mydb"])
    (jdbc/execute! c
                   ["create database mydb"]))
This unexpectedly works. If I comment in the SET SESSION TRANACTION READ ONLY part, it starts failing, as expected.

grav 2025-02-10T08:57:57.988259Z

Reading https://github.com/seancorfield/next-jdbc/blob/develop/doc/all-the-options.md#datasources-and-connections, it seems :read-only should work?

grav 2025-02-10T08:59:35.710459Z

Oh, and adding in (.setReadOnly c true) also works

seancorfield 2025-02-10T10:48:23.465289Z

I'm flying so feel free to create a GH issue and I'll look when I land.