pub struct Key { /* private fields */ }
Expand description

A Key can be either a Cloud Spanner row’s primary key or a secondary index key. A Key can be used as:

  • A primary key which uniquely identifies a Cloud Spanner row.
  • A secondary index key which maps to a set of Cloud Spanner rows indexed under it.
  • An endpoint of primary key/secondary index ranges; see the KeyRange type.

Rows that are identified by the Key type are outputs of read operation or targets of delete operation in a mutation. Note that for insert/update/insert_or_update/delete mutation types, although they don’t require a primary key explicitly, the column list provided must contain enough columns that can comprise a primary key.

Keys are easy to construct. For example, suppose you have a table with a primary key of username and product ID. To make a key for this table:

use google_cloud_spanner::key::Key;

let key = Key::composite(&[&"john", &16]);

See the description of Row and Mutation types for how Go types are mapped to Cloud Spanner types. For convenience, Key type supports a range of Rust types:

  • i64 and Option are mapped to Cloud Spanner’s INT64 type.
  • f64 and Option are mapped to Cloud Spanner’s FLOAT64 type.
  • bool and Option are mapped to Cloud Spanner’s BOOL type.
  • Vec, &u8, Option<Vec> and Option<&u8> is mapped to Cloud Spanner’s BYTES type.
  • String, &str, Option, Option<&str> are mapped to Cloud Spanner’s STRING type.
  • chrono::NaiveDateTime and Optionchrono::NaiveDateTime are mapped to Cloud Spanner’s TIMESTAMP type.
  • chrono::DateTime and Optionchrono::DateTime are mapped to Cloud Spanner’s DATE type.
  • google_cloud_spanner::value::CommitTimestamp and Option<google_cloud_spanner::value::CommitTimestamp> are mapped to Cloud Spanner’s TIMESTAMP type.

Implementations

one creates new Key

Examples
   use google_cloud_spanner::key::Key;
   use google_cloud_spanner::statement::ToKind;
   let key1 = Key::key(&"a");
   let key2 = Key::key(&1);

one creates new Key

Examples
   use google_cloud_spanner::key::Key;
   use google_cloud_spanner::statement::ToKind;
   let multi_key = Key::composite(&[&"a", &1]);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Wrap the input message T in a tonic::Request

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more