#json-text #diesel #sql #json

macro diesel-sqlite-struct-json-text

This proc macro attribute will allow you to store the target struct as json in TEXT field in diesel sqlite

3 releases

Uses new Rust 2024

0.1.2 Jun 9, 2025
0.1.1 Jun 6, 2025
0.1.0 Jun 6, 2025

#1030 in Procedural macros

Download history

87 downloads per month

MIT license

4KB

Your cargo.toml

[dependencies]
diesel = { version="*", features= ["sqlite"]}
serde = {version = "*", features = ["derive"]}
serde_json = "*"

The target struct

#[diesel_sqlite_struct_json_text]
pub struct MyJson {
    pub my_item: String,
    pub my_item_2: i32
}

The database entity

#[diesel(table_name = crate::schema::my_entity)]
#[derive(Debug, Queryable, Selectable, Identifiable, Associations, PartialEq, Insertable)]
pub struct MyEntity {
    pub id: i32,
    pub my_json: MyJson
}

The schema

diesel::table! {
    my_entity (id) {
        id -> Integer,
        my_json -> Text
    }
}

Dependencies

~145–550KB
~13K SLoC