-
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
Add support for extensions like citext
#250
base: master
Are you sure you want to change the base?
Conversation
This commit also adds support for registering extensions that prepare connections for using thos extensions. In this case that preparation involves registering a decoder on the connection, since extensions in different Postgres databases will most likely have different oids.
src/pg/extensions/citext.cr
Outdated
|
||
struct CIText | ||
def initialize(text : String) | ||
@text = text.downcase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This downcase
might be leftover from an earlier version of this code and may not be necessary. If we don’t need to downcase, that’ll save us a heap allocation.
I haven't looked into the implementation of the extension mechanism and compared it to #89. But I noticed some issues with text representation in
|
Ah, right, that's why I had the
I considered the differences in collation, but I've never seen anyone specify a non-default collation in 13 years of using Postgres. I assume that anyone using them understands they introduce weird inconsistencies between DB and application code in addition to complicating queries. For everyone else, it should work as expected. If collations got more usage, I'd fully agree with you that not matching the behavior exactly would likely be too misleading. I don't really have a strong opinion either way on the |
Hey, just ran in to possibly needing this... I'm wanting to use a |
This PR actually adds a few different things:
citext
as one of those extensions, including a decoder for it and aPG::CIText
Crystal typeThe
CIText
type could just return a string, but I thought it might be confusing to get a case-insensitive string out of the database only for it to do case-sensitive checking later. This type offers the case-insensitive equality checks in Crystal code and also allows you to get the raw string out.After working on this, I discovered #89 which is quite similar to this PR, but is 5 years old and likely significantly out of date by this point. This is just a draft because it’s still unpolished, but I’m using a monkeypatched version in one of my apps (email addresses are stored as
citext
) and it seems to work.