| Crates.io | shema |
| lib.rs | shema |
| version | 0.1.2 |
| created_at | 2025-11-19 07:38:22.189386+00 |
| updated_at | 2025-11-21 14:40:40.412464+00 |
| description | Schema generation macros |
| homepage | |
| repository | https://github.com/DoumanAsh/shema |
| max_upload_size | |
| id | 1939577 |
| size | 65,189 |
Derive macro to generate database schema code from Rust struct
All parameters are specified via shema
firehose_schema - Enables firehose schema generationfirehose_partition_code - Enables code generation to access partition informationfirehose_parquet_schema - Enables parquet schema generation similar to AWS Glue's oneparquet_code - Specifies to generate parquet code to write struct per schema. This requires parquet and serde_json crates to be added as dependenciesjson - Specifies that field is to be encoded as json object (automatically derived for std's collections)enumeration - Specifies that field is to be encoded as enumeration (Depending on database, it will be encoded as string or object)index - Specifies that field is to be indexed by underlying database engine (e.g. to be declared a partition key in AWS glue schema)firehose_date_index - Specifies field to be used as timestamp within firehose schema which will produce year, month and day fields. Requires to be of timestamp type. E.g. time::OffsetDateTimerename - Tells to use different name for the field. Argument MUST be string specified as rename = "new_name"If specified firehose output will expect RFC3339 encoded string as output during serialization
You should configure HIVE json deserializer with possible RFC3339 formats.
Terraform Reference: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kinesis_firehose_delivery_stream#timestamp_formats-1
SHEMA_TABLE_NAME - table name in lower caseSHEMA_FIREHOSE_SCHEMA - Firehose glue table schema. If enabled.SHEMA_FIREHOSE_PARQUET_SCHEMA - Partquet schema compatible with firehose data stream. If enabled.firehose_partition_keys_ref - Returns tuple with references to partition keysfirehose_partition_keys - Returns tuple with owned values of partition keysfirehose_s3_path_prefix - Returns fmt::Display type that writes full path prefix for S3 destination objectis_firehose_s3_path_prefix_valid - Returns true if firehose_s3_path_prefix is valid or not (i.e. no string is empty among partitions)Firehose schema expects flat structure, so any complex struct or array must be serialized as strings
mod prost_wkt_types {
pub struct Struct;
}
use std::fs;
use shema::Shema;
#[derive(Shema)]
#[shema(firehose_schema, firehose_parquet_schema, firehose_partition_code)]
pub(crate) struct Analytics<'a> {
#[shema(index, firehose_date_index)]
///Special field that will be transformed in firehose as year,month,day
r#client_time: time::OffsetDateTime,
r#server_time: time::OffsetDateTime,
r#user_id: Option<String>,
#[shema(index)]
///Index key will go into firehose's partition_keys
r#client_id: String,
#[shema(index)]
r#session_id: String,
#[shema(json)]
r#extras: Option<prost_wkt_types::Struct>,
#[shema(json)]
r#props: prost_wkt_types::Struct,
r#name: String,
byte: i8,
short: i16,
int: i32,
long: i64,
ptr: isize,
float: f32,
double: f64,
boolean: bool,
#[shema(rename = "stroka")]
strka: &'a str,
array: Vec<String>,
}
assert_eq!(Analytics::SHEMA_TABLE_NAME, "analytics");