#google-cloud #spanner #gcp

google-cloud-spanner

Google Cloud Platform spanner client library

38 releases (25 breaking)

new 0.26.0 Apr 18, 2024
0.25.0 Dec 28, 2023
0.24.0 Oct 15, 2023
0.23.0 Jul 21, 2023
0.2.0 Nov 28, 2021

#1 in #spanner

Download history 28/week @ 2023-12-22 60/week @ 2023-12-29 89/week @ 2024-01-05 93/week @ 2024-01-12 147/week @ 2024-01-19 2727/week @ 2024-01-26 5780/week @ 2024-02-02 5231/week @ 2024-02-09 5238/week @ 2024-02-16 6099/week @ 2024-02-23 6626/week @ 2024-03-01 6665/week @ 2024-03-08 4036/week @ 2024-03-15 1034/week @ 2024-03-22 992/week @ 2024-03-29 1138/week @ 2024-04-05

8,073 downloads per month
Used in 2 crates

MIT license

2MB
28K SLoC

google-cloud-spanner

Google Cloud Platform spanner library.

crates.io

Installation

[dependencies]
google-cloud-spanner = "version"

Quickstart

Create Client and call transaction API same as Google Cloud Go.

 use google_cloud_spanner::client::Client;
 use google_cloud_spanner::mutation::insert;
 use google_cloud_spanner::statement::Statement;
 use google_cloud_spanner::value::CommitTimestamp;
 use google_cloud_spanner::client::Error;

 #[tokio::main]
 async fn main() -> Result<(), Error> {

     const DATABASE: &str = "projects/local-project/instances/test-instance/databases/local-database";

     // Create spanner client
     let config = ClientConfig::default().with_auth().await.unwrap();
     let mut client = Client::new(DATABASE, config).await.unwrap();

     // Insert
     let mutation = insert("Guild", &["GuildId", "OwnerUserID", "UpdatedAt"], &[&"guildId", &"ownerId", &CommitTimestamp::new()]);
     let commit_timestamp = client.apply(vec![mutation]).await?;

     // Read with query
     let mut stmt = Statement::new("SELECT GuildId FROM Guild WHERE OwnerUserID = @OwnerUserID");
     stmt.add_param("OwnerUserID",&"ownerId");
     let mut tx = client.single().await?;
     let mut iter = tx.query(stmt).await?;
     while let Some(row) = iter.next().await? {
         let guild_id = row.column_by_name::<String>("GuildId");
     }

     // Remove all the sessions.
     client.close().await;
     Ok(())
 }

Performance

Result of the 24 hours Load Test.

Metrics This library Google Cloud Go
RPS 438.4 443.4
Used vCPU 0.37 ~ 0.42 0.65 ~ 0.70

Test condition

  • 2.0 vCPU GKE Autopilot Pod
  • 1 Node spanner database server
  • 100 Users
  • Here is the application for Load Test.

Dependencies

~15–32MB
~569K SLoC