misk icon indicating copy to clipboard operation
misk copied to clipboard

Add SQLDelight support

Open JGulbronson opened this issue 5 years ago • 9 comments

@AlecStrong and I have been adding MySQL support to SQLDelight over the past week, and I think it's just about at the point there's enough functionality to look at getting it in to Misk.

The way I'm picturing this would be to pull the JDBC stuff out in to it's own module, (misk-jdbc?). This would make support config like misk-hibernate does today, and provide a DataSourceService which SQLDelight could use for connections.

Wanted to open this issue to see if a) there's interest in getting this merged. @swankjesse feels like you're the person to ask b) if there is interest, talk next steps for implementing, so there's no surprises in a future PR

JGulbronson avatar Jun 06 '20 00:06 JGulbronson

High level it'd be good to know if there's more blockers to getting this in misk. We've worked on compatibility with faire's setup and it looks good to go. Schemas can be built from flyway-compatible migration files instead of needing to redeclare anything which I think was the biggest blocker.

The only dependency we need from misk is a DataSource, which we can get from hikari and the existing jdbc setup. It's tied to hibernate but I don't really know if thats an issue.

AlecKazakova avatar Jun 06 '20 00:06 AlecKazakova

Actually there is one potential issue, I think Misk currently doesn't support non .SQL extensions for migrations. And I think it might have some issues but having them in resources, but I could be wrong on that.

JGulbronson avatar Jun 06 '20 00:06 JGulbronson

that should still be fine, the sqldelight task can output .sql files for misk

AlecKazakova avatar Jun 06 '20 00:06 AlecKazakova

We've talked about decoupling the jdbc and hibernate stuff internally before to support sqlc and sqldelight. I think people are interested but no one has done the work yet. +1 on separating misk-jdbc and misk-hibernate and I think that's a good first step

jjestrel avatar Jul 09 '20 23:07 jjestrel

The way I'm picturing this would be to pull the JDBC stuff out in to it's own module, (misk-jdbc?). This would make support config like misk-hibernate does today, and provide a DataSourceService which SQLDelight could use for connections.

+1 to extracting JDBC related things

One other point: the Transacter is a really nice abstraction. Unfortunately, if we're talking about code organization, the interface itself includes Hibernate types like Session. Whether we can actually implement that interface or need to write a second one inspired by it, it would be great to preserve some of its ideas, most importantly: demarcating DB transactions with blocks and hiding transaction begin/commit/rollback.

zcross avatar Aug 06 '20 13:08 zcross

I think the JDBC module should be an implementation detail of actual consumer modules. Really people should only be using something higher level like misk-hibernate which would still have Transacter, or if it's SQLDelight there's a similar Transaction interface for blocking together code in a transaction/providing commit & rollback APIs.

AlecKazakova avatar Aug 06 '20 13:08 AlecKazakova

I started working on extracting the pure JDBC parts from Hibernate to separate it into a DataSourceModule (which sets up the Hikari pool and exposes a DataSource) and HibernateModule (which requires a DataSource and exposes a Transacter and a SessionFactory). It's pretty hard because things are quite entangled but I got about half way through. It's been on our agenda for a little while but I don't have time to work on this now. I'd imagine that's the first part of adding non-Hibernate persistence frameworks to misk.

tirsen avatar Aug 06 '20 14:08 tirsen

@JGulbronson I'd be happy to review and merge any such PRs though. But start off splitting up the HibernateModule since I know almost nothing about SQLDelight except that it's obviously super awesome. :-)

tirsen avatar Aug 06 '20 15:08 tirsen

DataSourceModule which exposes a DataSource would be peeeerfect for SQLDelight, DataSource is the only JDBC dependency needed to initialize everything

AlecKazakova avatar Aug 06 '20 15:08 AlecKazakova