ergokv_macro

Derive Macro Store

Source
#[derive(Store)]
{
    // Attributes available to this derive:
    #[store]
    #[key]
    #[index]
    #[unique_index]
    #[migrate_from]
    #[model_name]
}
Expand description

Derives the Store trait for a struct, generating methods for CRUD operations in TiKV.

This macro will generate the following methods:

  • load: Loads an instance from TiKV.
  • save: Saves the instance to TiKV.
  • delete: Deletes the instance from TiKV.
  • by_<field>: For each indexed field, generates a method to find an instance by that field.
  • set_<field>: For each field, generates a method to update that field.

§Attributes

  • #[key]: Marks a field as the primary key. Required on exactly one field.
  • #[index]: Marks a field as indexed, allowing efficient lookups.

§Example

use ergokv::Store;
use serde::{Serialize, Deserialize};
use uuid::Uuid;

#[derive(Store, Serialize, Deserialize)]
struct User {
    #[key]
    id: Uuid,
    #[index]
    username: String,
    email: String,
}