yoshidan / google-cloud-rust

Google Cloud Client Libraries for Rust.
MIT License
249 stars 95 forks source link

Spanner interleaved tables? #192

Closed gibssa closed 1 year ago

gibssa commented 1 year ago

Hi,

I noticed google_cloud_spanner supports multiple reads:

    let mut stmt = Statement::new("SELECT * , \
            ARRAY (SELECT AS STRUCT * FROM UserItem WHERE UserId = @Param1 ) AS UserItem, \
            ARRAY (SELECT AS STRUCT * FROM UserCharacter WHERE UserId = @Param1 ) AS UserCharacter  \
            FROM User \
            WHERE UserId = @Param1");

Suppose we wanted to add one more interleaved Spanner table:

CREATE TABLE UserItemHistory
(
    UserId STRING(36) NOT NULL,
    ItemId INT64 NOT NULL,
    UsedAt TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp=true)
) PRIMARY KEY(UserId, ItemId, UsedAt), INTERLEAVE IN PARENT UserItem ON DELETE CASCADE;

Is this possible with this crate?

yoshidan commented 1 year ago

Yes. Here is the example. https://github.com/yoshidan/google-cloud-rust/blob/293590f23056fd65b4aac0b7db0aae472af15323/spanner/tests/transaction_ro_test.rs#L108

yoshidan commented 1 year ago

Yes. Here is the example. https://github.com/yoshidan/google-cloud-rust/blob/293590f23056fd65b4aac0b7db0aae472af15323/spanner/tests/transaction_ro_test.rs#L108

gibssa commented 1 year ago

Thank you!