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 ```
-i
-o
./gen
Default template generates the files for google-cloud-spanner.
```rust // DON'T EDIT. this code is generated by nene. use googlecloudgoogleapis::spanner::v1::Mutation; use googlecloudgax::grpc::Status; use googlecloudspanner::client::{RunInTxError, TxError}; use googlecloudspanner::key::Key; use googlecloudspanner::mutation::{ delete, insertorupdatestruct, insertstruct, replacestruct, updatestruct, }; use googlecloudspanner::reader::AsyncIterator; use googlecloudspanner::row::{Error as RowError, Row, Struct, TryFromStruct}; use googlecloudspanner::statement::{Kinds, Statement, ToKind, ToStruct, Types}; use googlecloudspanner::transaction::Transaction; use googlecloudspanner::transaction::CallOptions; use googlecloudspanner::value::CommitTimestamp; use std::convert::TryFrom;
pub const TABLENAME: &str = "User"; pub const COLUMNUSERID: &str = "UserId"; pub const COLUMNPREMIUM: &str = "Premium"; pub const COLUMNUPDATEDAT: &str = "UpdatedAt";
pub struct User {
pub userid: String,
pub premium: bool,
pub updatedat: chrono::DateTime
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::key(&self.userid)) }
pub async fn findbypk(
tx: &mut Transaction, userid: &String, options: Option
pub async fn readbystatement(
tx: &mut Transaction,
stmt: Statement,
options: Option
impl ToStruct for User { fn tokinds(&self) -> Kinds { vec![ (COLUMNUSERID, self.userid.tokind()), (COLUMNPREMIUM, self.premium.tokind()), (COLUMNUPDATEDAT, CommitTimestamp::new().tokind()), ] }
fn gettypes() -> Types { vec![ (COLUMNUSERID, String::gettype()), (COLUMNPREMIUM, bool::gettype()), (COLUMNUPDATEDAT, CommitTimestamp::get_type()), ] } }
impl TryFromStruct for User {
fn tryfromstruct(s: Struct<'>) -> Result
impl TryFrom