diesel-rs / diesel

A safe, extensible ORM and Query Builder for Rust
https://diesel.rs
Apache License 2.0
12.75k stars 1.07k forks source link

Add support for currently unsupported postgres json/jsonb functions #4216

Open weiznich opened 2 months ago

weiznich commented 2 months ago

Diesel currently supports the postgres array types. We do not provide built-in support for various methods available for these types. This is a tracking issue for adding support for these methods.

The general strategy for adding support for new methods is as following:

  1. Define the operator via define_sql_function!(). These operators can be defined here. See the linked definition of array_append for an example. If there is already an existing definition, this step could be skipped. This function should have a short documentation snippet with an example (See the linked postgres documentation for examples for all of the function, please also add variants with null values, etc). If there is a json and a jsonb variant, please implement both in a single PR.
  2. If the function is generic, add a helper type definition here. Again see the linked definition for an example for the array_append function.
  3. Add a test for #[auto_type] support for the newly added function here
  4. Submit a PR with the change

Method list:

For items marked with * the instructions above can be followed as written down

For items marked with ** we want try to use the sql_type::Record type as input type, although I'm not 100% sure if that will work.

For items marked with *** its unclear how to express them with the current tools provided by diesel. We do not want to implement them yet, they are just listed to have a complete list (mostly missing set + variadics support)

Items marked with **** need additional non-straighforward handling for the returned record type as outlined in the postgres documentation (we would need to find a way to generate the cast)

In addition diesel does currently not support the expression IS [ NOT ] JSON [ { VALUE | SCALAR | ARRAY | OBJECT } ] [ { WITH | WITHOUT } UNIQUE [ KEYS ] ] operator variants. For this we need

We want variants for:

Please add a comment to this issue if you plan to work on a specific method.

If there is anything unclear about how to add a support for a specific method just ask and we will try to answer your questions.

aznszn commented 2 months ago

doing to_json

valkrypton commented 2 months ago

i'll work on json_object

wowinter13 commented 2 months ago

Will work on to_jsonb

gushul commented 2 months ago

I'll work on array_to_json

zaira-bibi commented 1 month ago

Working on json_array_length.

anna-ahmed19 commented 1 month ago

Working on json_typeof and jsonb_typeof

anna-ahmed19 commented 1 month ago

Working on jsonb_pretty

zaira-bibi commented 1 month ago

Working on json_strip_nulls.

valkrypton commented 1 month ago

ill work on jsonb_object next

aznszn commented 1 month ago

working on jsonb_insert

valkrypton commented 1 month ago

i'll work on jsonb_path_exists

PratikFandade commented 1 month ago

I'll work on row_to_json

meeshal commented 3 weeks ago

I'll work on expression IS JSON and expression IS NOT JSON

PratikFandade commented 1 week ago

I'll work on json_populate_record & jsonb_populate_record

meeshal commented 1 week ago

I'll work on is_json_object, is_not_json_object, is_json_array, is_not_json_array, is_json_scalar, is_not_json_scalar expression methods