diesel-rs / diesel

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

Add missing sqlite json/jsonb functions and operators #4366

Open weiznich opened 3 days ago

weiznich commented 3 days ago

Diesel currently supports the sqlite json/jsonb 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 function via define_sql_function!(). These functions can be defined here in a new functions.rs module. See the linked definition of to_json for an example from the postgres backend as an example. This function should have a short documentation snippet with an example (See the linked sqlite 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 to_json function from the postgres backend for an example.
  3. Add a test for #[auto_type] support for the newly added function here
  4. Submit a PR with the change

Method list:

There are four aggregate SQL functions:

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

Items marked with ** are variadic functions on SQL side. Rust does not support such function definitions yet, so we either need to have variants for a certain number of fixed arguments or we need to find another solution.

For items marked with *** the function definition needs to be marked with the #[aggregate] attribute.

Operators:

For operators:

These already exists for the postgres backend here. We need to look for a way to share these impls.

xuehaonan27 commented 3 days ago

I would like to take json(json) and jsonb(json)

KekmaTime commented 1 day ago

I will work on json_valid(json) & json_type(json)