Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upHstore data type #970
Comments
This comment has been minimized.
|
While I'm happy to provide assistance for anyone looking to implement this, it's not a type that I want to support in the main Diesel crate. Diesel's design is meant to allow for third party crates to add extension types such as this one. Feel free to comment on this issue with questions or discussion of implementation, but I'm going to close it as it's not a feature that I'd like to add to the main crate. |
sgrif
closed this
Jul 4, 2017
This comment has been minimized.
|
I started. It's not in any working state yet though. https://github.com/dbrgn/diesel-hstore-rs |
This comment has been minimized.
lholden
commented
Oct 13, 2017
|
Figured I'd leave a comment here in case people go looking to use hstore with diesel. I've created a create that successfully serializes to/from hstore. Right now it's using a wrapper type due to not being able to impl AsExpression for HashMap. Sgrif had an idea for how this could be gotten around... so once I've explored that idea I'll get the crate published and share a link here so that others can use it. It does not currently support any of the hstore operators however. Would love to end up doing this eventually. |
dbrgn commentedJun 27, 2017
Since there wasn't a tracking issue yet, I'll create one.
While the
jsonbdata type is partially supported,hstoreisn't at all.https://www.postgresql.org/docs/current/static/hstore.html
I'm dealing with string-typed key-value data. In theory I could just store my data into a jsonb field, but then I always have to explicitly validate whether the value is a
Value::Object, then iterate over all the values of the map and ensure that the object only has values of typeString.For basic support:
HashMap<String, String>Operators that would have to be added for full support:
hstore -> textoperator (returnsOption<String>)hstore -> text[]operator (returnsOption<Vec<String>>)hstore || hstoreoperator (returnsHashMap<String, String>)hstore ? textoperator (returnsbool)hstore ?& text[]operator (returnsbool)hstore ?| text[]operator (returnsbool)hstore @> hstoreoperator (returnsbool)hstore <@ hstoreoperator (returnsbool)hstore - textoperator (returnsHashMap<String, String>)hstore - text[]operator (returnsHashMap<String, String>)hstore - hstoreoperator (returnsHashMap<String, String>)These could probably be implemented as FromSql:
%% hstoreoperator (returnsVec<String>)%# hstoreoperator (returnsVec<(String, String)>)These are probably tricky:
record #= hstoreIn all cases, if one of the operands is nullable, then the result is nullable too.
Basic support would probably be pretty straightforward, right? If someone could tell me what would need to be done, I might be able to provide a PR.