nene
is a command-line tool to generate Rust code for Google Cloud Spanner.
nene
uses database schema to generate code by using Information Schema. nene
runs SQL queries against tables in INFORMATION_SCHEMA to fetch metadata for a database, and applies the metadata to Go templates to generate code/models to acccess Cloud Spanner.
cargo install nene
```bash export RUSTLOG=info export SPANNERDSN=projects/local-project/instances/test-instance/databases/local-database
export SPANNEREMULATORHOST=localhost:9010 mkdir ./gen nene -o ./gen -j -d ```
-i
-o
./gen
-j
serde::Serialize
and serde::Deserialize
-d
Default
traitDefault template generates the files for google-cloud-spanner.
```rust // DON'T EDIT. this code is generated by nene. use googlecloudgoogleapis::spanner::v1::Mutation; use googlecloudspanner::client::{Error}; use googlecloudspanner::key::Key; use googlecloudspanner::mutation::{ delete, insertorupdatestruct, insertstruct, replacestruct, updatestruct, }; use googlecloudspanner::reader::AsyncIterator; use googlecloudspanner::row::{Error as RowError, Row}; use googlecloudspanner::statement::Statement; use googlecloudspanner::transaction::Transaction; use googlecloudspanner::transaction::CallOptions; use googlecloudspanner_derive::Table; use std::convert::TryFrom;
pub const TABLENAME: &str = "User"; pub const COLUMNUSERID: &str = "UserId"; pub const COLUMNNOTNULLINT64: &str = "NotNullINT64"; pub const COLUMNNULLABLEINT64: &str = "NullableINT64"; pub const COLUMNNOTNULLFLOAT64: &str = "NotNullFloat64"; pub const COLUMNNULLABLEFLOAT64: &str = "NullableFloat64"; pub const COLUMNNOTNULLBOOL: &str = "NotNullBool"; pub const COLUMNNULLABLEBOOL: &str = "NullableBool"; pub const COLUMNNOTNULLBYTEARRAY: &str = "NotNullByteArray"; pub const COLUMNNULLABLEBYTEARRAY: &str = "NullableByteArray"; pub const COLUMNNOTNULLNUMERIC: &str = "NotNullNumeric"; pub const COLUMNNULLABLENUMERIC: &str = "NullableNumeric"; pub const COLUMNNOTNULLTIMESTAMP: &str = "NotNullTimestamp"; pub const COLUMNNULLABLETIMESTAMP: &str = "NullableTimestamp"; pub const COLUMNNOTNULLDATE: &str = "NotNullDate"; pub const COLUMNNULLABLEDATE: &str = "NullableDate"; pub const COLUMNNOTNULLARRAY: &str = "NotNullArray"; pub const COLUMNNULLABLEARRAY: &str = "NullableArray"; pub const COLUMNNULLABLESTRING: &str = "NullableString"; pub const COLUMNUPDATED_AT: &str = "UpdatedAt";
pub struct User {
#[spanner(name = "UserId")]
pub userid: String,
#[spanner(name = "NotNullINT64")]
pub notnullint64: i64,
#[spanner(name = "NullableINT64")]
pub nullableint64: Option
impl Default for User { fn default() -> Self { Self { userid: Default::default(), notnullint64: Default::default(), nullableint64: Default::default(), notnullfloat64: Default::default(), nullablefloat64: Default::default(), notnullbool: Default::default(), nullablebool: Default::default(), notnullbytearray: Default::default(), nullablebytearray: Default::default(), notnullnumeric: Default::default(), nullablenumeric: Default::default(), notnulltimestamp: time::OffsetDateTime::nowutc(), nullabletimestamp: Default::default(), notnulldate: time::OffsetDateTime::nowutc().date(), nullabledate: Default::default(), notnullarray: Default::default(), nullablearray: Default::default(), nullablestring: Default::default(), updatedat: time::OffsetDateTime::nowutc(), } } } impl User { pub fn insert(&self) -> Mutation { insertstruct(TABLENAME, &self) }
pub fn update(&self) -> Mutation { updatestruct(TABLENAME, &self) }
pub fn replace(&self) -> Mutation { replacestruct(TABLENAME, &self) }
pub fn insertorupdate(&self) -> Mutation { insertorupdatestruct(TABLENAME, &self) }
pub fn delete(&self) -> Mutation { delete(TABLENAME, Key::new(&self.userid)) }
pub async fn findbypk(
tx: &mut Transaction, userid: &str, options: Option
async fn readbystatement
```