Skip to main content

proto_enum

Function proto_enum 

Source
pub fn proto_enum(proto_type_fqn: impl Into<String>) -> Type
Expand description

Returns a Type representing ENUM (GoogleSQL) with the given fully qualified proto type name.

Spanner stores protobuf enum values as integers corresponding to their tag numbers in the proto definition. When binding enum parameters, provide the integer value and specify the fully qualified enum type name.

ยงExample

use google_cloud_spanner::statement::Statement;
use google_cloud_spanner::types::proto_enum;

// Enum value corresponding to the protobuf tag number (e.g. `OrderStatus::Shipped as i32 as i64`)
const STATUS_SHIPPED: i64 = 2;

let statement = Statement::builder("SELECT OrderId FROM Orders WHERE Status = @status")
    .add_typed_param(
        "status",
        STATUS_SHIPPED,
        proto_enum("examples.shipping.OrderStatus"),
    )
    .build();