Skip to content

Commit

Permalink
bindings-macro: add note re. autoinc (#59)
Browse files Browse the repository at this point in the history
* bindings-macro: add note re. autoinc

* Update crates/bindings-macro/src/lib.rs

Co-authored-by: Kim Altintop <kim@eagain.io>
Signed-off-by: Mazdak Farrokhzad <twingoow@gmail.com>

* spacetimedb_tabletype: minor docs tweaks

* address pheobe's review

---------

Signed-off-by: Mazdak Farrokhzad <twingoow@gmail.com>
Co-authored-by: Kim Altintop <kim@eagain.io>
  • Loading branch information
2 people authored and cloutiertyler committed Aug 1, 2023
1 parent 187f70b commit 0cdfae2
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions crates/bindings-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ mod sym {
/// | reducer [, repeat = Duration]
/// | index(btree | hash [, name = string] [, field_name:ident]*)
/// ```
///
/// For description of the field attributes on `#[spacetimedb(table)]` structs,
/// see [`TableType`](spacetimedb_tabletype).
#[proc_macro_attribute]
pub fn spacetimedb(macro_args: proc_macro::TokenStream, item: proc_macro::TokenStream) -> proc_macro::TokenStream {
let item: TokenStream = item.into();
Expand Down Expand Up @@ -463,6 +466,31 @@ fn spacetimedb_table(item: TokenStream) -> syn::Result<TokenStream> {
})
}

/// Generates code for treating this type as a table.
///
/// Among other things, this derives `Serialize`, `Deserialize`,
/// `SpacetimeType`, and `TableType` for our type.
///
/// A table type must be a `struct`, whose fields may be annotated with the following attributes:
///
/// * `#[autoinc]`
///
/// Creates a database sequence.
///
/// When a row is inserted with the annotated field set to `0` (zero),
/// the sequence is incremented, and this value is used instead.
/// Can only be used on numeric types and may be combined with indexes.
///
/// Note that using `#[autoinc]` on a field does not also imply `#[primarykey]` or `#[unique]`.
/// If those semantics are desired, those attributes should also be used.
///
/// * `#[unique]`
///
/// Creates an index and unique constraint for the annotated field.
///
/// * `#[primarykey]`
///
/// Similar to `#[unique]`, but generates additional CRUD methods.
#[proc_macro_derive(TableType, attributes(sats, unique, autoinc, primarykey))]
pub fn spacetimedb_tabletype(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
let item = syn::parse_macro_input!(item as syn::DeriveInput);
Expand Down

0 comments on commit 0cdfae2

Please sign in to comment.