sql

Mark Wardle 2024-09-24T13:22:29.316619Z

Hi all. I need to turn some legacy SQL into honey sql data structures. Is there a tool somewhere to do essentially the reverse of what honey sql does? I need to eventually make the query much more dynamic and flexible as otherwise I’d just keep as-is and use hugsql instead.

p-himik 2024-09-24T13:53:15.357879Z

I'm not aware of such a tool but you can use both libraries side by side and even together.

👍 1
lukasz 2024-09-24T14:58:04.197779Z

I used ChatGPT for this in the past, it was 80% there, I can only guess that it's even better now

👍 1
Mark Wardle 2024-09-24T18:05:03.179729Z

Thanks both. Parsing SQL isn’t easy so I hadn’t expected much, but even if I can get over halfway, it will be better than nothing!

ts1503 2024-09-24T16:46:56.913079Z

Hello guys. I have a question about next.jdbc I read docs multiple times but can’t find a way how to set the session variable on the connection I’m using Postgres driver to access the CockroachDB (which should be compatible) And I need to set a session variable multiple_active_portals_enabled=true I tried to add this as a key into db spec like

{:dbtype   "postgresql",
   :host     "...",
   :port     "26257",
   :user     "...",
   :password "...",
   :dbname   "..."
   :multiple_active_portals_enabled true}
but it doesn’t work .

seancorfield 2024-09-24T16:48:47.689319Z

The db-spec elements become query parameters on the connection URL used to build the datasource and/or connection, i.e., not session variables.

ts1503 2024-09-24T16:50:08.685099Z

is there a way to set session variable? maybe some special key?

seancorfield 2024-09-24T16:50:35.668559Z

I don't understand what you mean by "session variables". How would you specify this in raw SQL?

ts1503 2024-09-24T16:51:12.984609Z

in the raw SQL it looks like SET multiple_active_portals_enabled=true;

seancorfield 2024-09-24T16:51:24.574519Z

JDBC has no concept of "session variables" exposed.

ts1503 2024-09-24T16:51:55.378919Z

I saw some examples like this jdbc_connection_string => “jdbc:

seancorfield 2024-09-24T16:52:52.290809Z

That's DB specific, but would be {:dbtype "postgresql" ... :sessionVariables "multiple_active_portals_enabled=true"} assuming the PG driver supports that.

ts1503 2024-09-24T16:53:30.907739Z

I tried that but it doesn’t work. Maybe Postgres doesn’t support that

ts1503 2024-09-24T17:03:40.039209Z

Interesting. Seems it will work like this {:options "-c multiple_active_portals_enabled=true"}

seancorfield 2024-09-24T17:12:29.741859Z

Yeah, you're kind of dependent on whatever DB-specific stuff works since that's all outside the scope of JDBC itself (and next.jdbc only knows about JDBC).

ts1503 2024-09-24T20:39:19.590379Z

thank you

Colin P. Hill 2024-09-24T19:58:03.156459Z

In Migratus, there is a distinction made between migrations and the "init script", with the latter standing alone outside the migration numbering. It doesn't really explain the purpose of this feature. What is the benefit of having a separate init script, rather than doing your initialization with normal migrations?

p-himik 2024-09-24T20:00:36.218879Z

The init script can be created by any command that dumps your whole DB into an SQL file. A migration file must be specially formatted. It also makes the squashing process very obvious and easy. And it's a descriptive name. init is much better than 19700101000001-init.

Colin P. Hill 2024-09-24T21:22:52.254509Z

> A migration file must be specially formatted. Ahhh right, that's a key detail I missed.

Colin P. Hill 2024-09-24T21:22:53.758959Z

Thank you!

👍 1