Crates.io | spanner-rs |
lib.rs | spanner-rs |
version | 0.3.0 |
source | src |
created_at | 2021-09-29 01:47:05.853795 |
updated_at | 2022-09-27 03:33:28.285641 |
description | Cloud Spanner Rust Client |
homepage | |
repository | https://github.com/plaflamme/spanner-rs/ |
max_upload_size | |
id | 457846 |
size | 132,329 |
An asynchronous Rust client for Cloud Spanner.
The client uses gRPC to interface with Cloud Spanner. As such, this crate uses tonic
and related crates (i.e.: prost
, tower
and tokio
).
The client also uses bb8
to maintain a pool of Cloud Spanner sessions (conceptually similar to a connection pool in other databases).
The implementation is heavily inspired by the excellent postgres
and related crates.
Spanner is a complex database and this client does not implement all available features. The current focus is on getting idiomatic SQL support for both reads and writes.
It's not recommended to use this in production for any serious workload.
ToSpanner
and FromSpanner
for struct
suse spanner_rs::{Client, Error, ReadContext, TransactionContext};
#[tokio::main]
async fn main() -> Result<(), Error> {
let mut client = Client::configure()
.project("my-gcp-project")
.instance("my-instance")
.database("my-database")
.connect()
.await?;
// assuming the following table:
// person(id INT64, name STRING(MAX), data BYTES(MAX))
client
.read_write()
.run(|tx| {
tx.execute_update(
"INSERT INTO person(id, name, data) VALUES(@id, @name, NULL)",
&[("id", &42), ("name", &"ferris")],
)
})
.await?;
let result_set = client
.read_only()
.execute_query("SELECT * FROM person", &[])
.await?;
for row in result_set.iter() {
let id: u32 = row.get("id")?;
let name: &str = row.get("name")?;
let data: Option<&[u8]> = row.get("data")?;
println!("found person: {} {} {:?}", id, name, data);
}
Ok(())
}