-
Notifications
You must be signed in to change notification settings - Fork 540
Remove default ColumnAdapters for non-SQLite dialects #2056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think this is a great idea. I would love to have helpful adapters for things like datetime libraries exposed in different artifacts and I think this concept fits nicely with that. Like you could imagine different artifacts for adapters
or whatever. The boolean one in particular would be rough for existing sqlite users so I'm inclined to keep just that one or think of a migration strategy but I really like the core idea |
I really like the concept of having multiple Gradle dependencies for adapters. It's been a couple of years since I've used SQLDelight for SQLite, so do you mind expanding on why it would be rough for SQLite users to specify the boolean adapter? Granted it would break their builds, but the fix is fairly trivial. |
i guess thats true. I was thinking it would be a bunch of boilerplate that would have to get added in but thats probably okay, and its a compile time thing so its not like we'd be introducing weird errors |
I've been having a look how to implement this and it seems like there would be an issue with the following test as we could no longer guarantee that the same boolean Essentially what would happen in the above test is what the following test tests for: I can't think of a great solution to this though, but it feels like such a regression might annoy users. The only thing I can think of is having a very stripped down version of PostgreSQL's domain types for dialects that don't have such a feature. Then you can reuse the same "domain type", and we'd know that it has the same shared Very rough idea of the syntax: typealias Day = java.time.LocalDateTime
CREATE TABLE person(
birthday TEXT AS Day NOT NULL,
best_day TEXT AS Day NOT NULL
) Then you'd just need to pass the single |
The SQLDelight SQLite documentation showcases the usage of (what is essentially) preinstalled
ColumnAdapter
's. For example, the following (user-specified column adapters are not required/allowed):This makes sense for SQLite, where there isn't a
SMALLINT
that would automatically map tokotlin.Short
, orBOOLEAN
that would automatically map tokotlin.Boolean
. With dialects that do support these types (either through pseudo or actual types), I don't think it makes sense to have these preinstalled adapters for these dialects as it promotes the abuse of using the wrong underlying SQL type (e.g., usingINT AS Boolean
instead ofBOOLEAN
in PostgreSQL).I'm a bit hesitant of this proposal, purely because of its implementation. As sqldelight/sql-psi#155 advocates for having dialect specific things in their own sql-psi module and making SQLDelight dialect agnostic, it's not obvious where the specification of preinstalled
ColumnAdapter
's only for SQLite should go:ColumnAdapter
s are an SQLDelight construct, and doesn't really relate semantically to what sql-psi is trying to solve.Personally, I'd do away with default column adapters, and have the user explicitly hook the adapter up with the database like they do for their own custom
ColumnAdapter
's. SQLDelight could provide a set of commonly usedColumnAdapter
's (e.g.,IntColumnAdapter
,BooleanColumnAdapter
). This idea would mean that non-SQLite dialects would have access to this suite ofColumnAdapter
's, but the adapters could ultimately be put into a separate module with a strong suggestion in its description to only use them if the dialect the user is using doesn't have an SQL type that would otherwise return the same Java type they desire. As was said, this wouldn't address the initial issue 100%, but would make doing the wrong thing by accident a bit harder.Here's a (temporary) backwards compatible prototype of what I was discussing (branch). The final form would look like this (branch). I can make a PR for either one of these if there's interest.
WDYT?
The text was updated successfully, but these errors were encountered: