diesel-json-derive
NOTE: This is under active development. No guarantees for stability or usability. You probably want diesel_json instead. Please also note that this currently expects postgres. Pull requests to support other backends are welcome.
diesel_json_derive
What's this? This is a procedural macro that automatically derives ToSql and FromSql for Diesel's Jsonb type.
Consider a table like
(
id TEXT PRIMARY KEY,
bar JSONB NOT NULL
);
which is in Rust can be represented as as (does not compile!):
In order to make Bar be represented as a jsonb blob you will need to implement the diesel::deserialize::FromSql and diesel::deserialize::FromSql traits, e.g. like this:
This gets tedious quickly so this create does it for you. So with this crate you can write:
use Jsonb;
use ;
use DieselJsonb;
use ;
diesel_json_derive vs ## diesel_json
The diesel_json crate solves the same problem but uses a wrapper type for it. This has the disadvantage that this type needs to be used when matching for example. This crate does not have this disadvantage.
License: MIT