pub struct CatalogResource<T> { /* private fields */ }Expand description
A selected subtree. Names are unescaped identifiers. Apply replaces the whole definition; it is not a patch. Mutations never retry automatically.
An interrupted or malformed mutation response reports
catalog_commit_outcome_unknown. Read the current state before deciding
whether to retry. Typed definitions reject unsupported fields; Self::raw
preserves them, including arbitrary-precision JSON numbers.
Implementations§
Source§impl<T> CatalogResource<T>
impl<T> CatalogResource<T>
pub fn raw(&self) -> CatalogResource<Value>
Source§impl<T: Serialize + DeserializeOwned> CatalogResource<T>
impl<T: Serialize + DeserializeOwned> CatalogResource<T>
Sourcepub async fn get(&self) -> Result<CatalogSnapshot<T>, Error>
pub async fn get(&self) -> Result<CatalogSnapshot<T>, Error>
Reads the complete definition and its ETag.
Examples found in repository?
18async fn main() -> Result<(), Box<dyn std::error::Error>> {
19 let client = common::client()?;
20 let table_name = std::env::var("SCOPEDB_TABLE").unwrap_or_else(|_| "events".to_string());
21 let table = client
22 .table(table_name)
23 .with_database(common::database())
24 .with_schema(common::schema());
25
26 println!("identifier: {}", table.identifier());
27
28 let description = table.catalog().get().await?.definition;
29 for column in description.columns {
30 println!("{}: {:?}", column.name, column.data_type);
31 }
32
33 Ok(())
34}More examples
18async fn main() -> Result<(), Box<dyn std::error::Error>> {
19 let client = common::client()?;
20 let database = common::database();
21 let schema = common::schema();
22
23 let catalog = client.catalog().get().await?;
24 for item in catalog.definition.databases {
25 println!(
26 "database {}: {}",
27 item.name,
28 item.comment.unwrap_or_default()
29 );
30 }
31 let snapshot = client.catalog().schema(&database, &schema).get().await?;
32 println!("schema ETag: {}", snapshot.etag);
33 for table in snapshot.definition.tables {
34 println!("table {}: {:?}", table.name, table.columns);
35 }
36 Ok(())
37}Sourcepub async fn apply(
&self,
definition: &T,
options: CatalogOptions,
) -> Result<CatalogResult<T>, Error>
pub async fn apply( &self, definition: &T, options: CatalogOptions, ) -> Result<CatalogResult<T>, Error>
Replaces the selected definition, including its children. Omitted fields are cleared. Start from a snapshot to retain fields you are not changing.
Preview with dry_run and use if_match to reject concurrent changes.
Set allow_destructive only after reviewing the potential data loss.
use scopedb_client::CatalogOptions;
let resource = client.table("events").catalog();
let snapshot = resource.get().await?;
let mut definition = snapshot.definition;
definition.comment = Some("Application events".to_string());
let preview = resource
.apply(
&definition,
CatalogOptions {
dry_run: true,
if_match: Some(snapshot.etag),
..Default::default()
},
)
.await?;
println!("destructive = {}", preview.destructive);
resource
.apply(
&definition,
CatalogOptions {
if_match: Some(preview.etag),
..Default::default()
},
)
.await?;Sourcepub async fn delete(
&self,
options: CatalogOptions,
) -> Result<CatalogResult<T>, Error>
pub async fn delete( &self, options: CatalogOptions, ) -> Result<CatalogResult<T>, Error>
Deletes the selected resource. Use dry_run to preview the change and
if_match to require the ETag from a prior read or preview.