Crates.io | scylla_orm_table_to_struct |
lib.rs | scylla_orm_table_to_struct |
version | 0.1.2 |
source | src |
created_at | 2021-11-11 11:06:25.32502 |
updated_at | 2022-01-12 16:56:07.450629 |
description | Table mapper for the ORM for Scylla, fully compatible with Apache Cassandraâ„¢ |
homepage | |
repository | https://github.com/Jasperav/scylla_orm |
max_upload_size | |
id | 480124 |
size | 60,982 |
This library contains several crates with the following features:
struct
s: scylla_orm_table_to_struct. See Usage.
See the generated dir for the generated code.scylla_orm_macro::query
). See Usage.scylla_orm_macro::mirror
)text
, you can implement the
Transformer
trait and map it to a type that implements serde::Serialize
and serde::Deserialize
Not all types are supported yet due to https://github.com/scylladb/scylla-rust-driver/issues/104
Depending on a query, a certain query type can be derived. These can be found here. These are the commonly used query types:
SelectMultiple
: Can be used as an iterator to iterate over the rowsSelectUnique
: Selects an optional unique row by full primary keySelectUniqueExpect
: Same as SelectUnique
, but fails if the row doesn't existSelectUniqueExpect
with Count
as entity type: has the special select_count
method for queries like "select count(*) from ..."There are also struct
s for CRUD operations.
You can see an example on how to generate Rust struct
s in the example dir.
Transformer
trait is implemented and used for json mappingstruct
sHow to implement it yourself (step-by-step guide how to mimic the example
crate):
scylla_orm_table_to_struct = "0.1"
Tranformer
trait (or use DefaultTransformer
)scylla_orm_table_to_struct::generate
An example of the structure of the generated code for table 'child' is:
struct
with owned values. Can be converted to ChildRef, PrimaryKey and PrimaryKeyRefstruct
where the values are all borrowed. This struct
can perform insertions. Can be converted to Child, PrimaryKey and PrimaryKeyRefstruct
which holds the owned values of the primary key fields of Child. Can be converted to PrimaryKeyRef.struct
where the values are all borrowed. This struct
can perform updates, deletions and selects. Can be converted to PrimaryKeyenum
which holds the enum variants with owned values of columns that can be updated. Can be converted to UpdatableColumnRef.enum
where the values are all borrowed. This is used by PrimaryKeyRef for updates. Can be converted to UpdatableColumn.Crate scylla_orm_macro
holds several macros that can be used to ensure compile/type checked queries.
Examples on how this can be used can be found in lib.rs, method qmd
.
How to implement it yourself:
scylla_orm_macro = "0.1"
query
macro returns the correct query type for the given queryquery_base_table
macro transforms a select
query to the materialized view table, to a select
query of the base tablemirror
and primary_key
can be used for other derive macros