Skip to content
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

ActiveRecord Column DSL: Support ActiveRecord::Type::Json and ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb #2023

Open
marknuzz opened this issue Sep 22, 2024 · 3 comments
Labels
help-wanted Extra attention is needed rubyconf-hackday

Comments

@marknuzz
Copy link
Contributor

marknuzz commented Sep 22, 2024

I was surprised to see that both json and jsonb columns in postgres are mapped as T.untyped despite having popular usage. I couldn't find any discussions about this when searching the issues.

json => ActiveRecord::Type::Json
jsonb => ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb

Question for maintainers: Are there any known gotchas for implementing this in a straightforward way compared to other types? I have some concerns here because it seems like if it isn't implemented there was a good reason for that, but I couldn't find a mention of that anywhere.

@KaanOzkan
Copy link
Contributor

I don't think using ActiveRecord::Type:: in a signature makes sense for setters and getters. Playing around a little bit I think we could do T::Hash[T.untyped, T.untyped] instead for json columns, it seems to be automatically serialized/deserialized. I assume it's similar for Postgres.

@marknuzz
Copy link
Contributor Author

Yeah sorry it wasn't clear. ActiveRecord::Type::Json is the type used internally by ActiveRecord and the type that the compiler would be implementing. The signature output would be a form of T::Hash.

@KaanOzkan KaanOzkan added the help-wanted Extra attention is needed label Sep 26, 2024
@alex-tan
Copy link
Contributor

alex-tan commented Oct 8, 2024

JSON/JSONB columns also can contain arrays, strings, and floats as I understand it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help-wanted Extra attention is needed rubyconf-hackday
Projects
None yet
Development

No branches or pull requests

4 participants