-
Notifications
You must be signed in to change notification settings - Fork 78
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
Read Array(Int) without considering database type #150
Comments
Actual datatypes arr determined by the db/driver in the The workaorund is to map/transform the data after the read operation. |
@bcardiff could you provide with an example of the workaround? Because it seems to me it doesn't solve the issue. |
@bcardiff I'm assuming that I don't know which integer type (smallint, int or bigint) is defined in DB schema and want to read its array. The issue is that neither |
🏓 |
I wonder whether some types should be automatically casted if there is no precision loss. That means if you do I don't think this is trivial to implement because we'd have to hardcode all these cases, but I'm pretty sure it'll be very useful to users. When writing it should be the other way around: passing Now, thinking about these two cases, it might a bit weird that you can read |
This isn't a language problem - this is a problem in the design of crystal-db. |
Reading values directly from result sets is a pretty low level interface. Specifying the type as returned from the database might just be the best solution. Btw: Casting values to a specific type doesn't need to happen in Crystal application code, it could just be implemented in the SQL query as well. So in the end, it's just a matter of defining an interface between SQL and Crystal DB, while both sides could actually use different types internally. |
This works, but if database schema defines
int[]
instead ofsmallint[]
, would return[0_i16, 4_i16]
. Okay, not good. Let's try to fix it:Or maybe:
Still no luck. What I want is to read an array of any integers and convert it to
Int32
without taking care of what integer type is in DB schema. Is that possible?Also
rs.read(Int16 | Int32 | Int64 | Nil)
works for any integer column type, so I think it should stay consistent.The text was updated successfully, but these errors were encountered: