Skip to main content

CatalogResource

Struct CatalogResource 

Source
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>

Source

pub fn raw(&self) -> CatalogResource<Value>

Source§

impl<T: Serialize + DeserializeOwned> CatalogResource<T>

Source

pub async fn get(&self) -> Result<CatalogSnapshot<T>, Error>

Reads the complete definition and its ETag.

Examples found in repository?
examples/table.rs (line 28)
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
Hide additional examples
examples/catalog.rs (line 31)
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}
Source

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?;
Source

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.

Trait Implementations§

Source§

impl<T: Clone> Clone for CatalogResource<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for CatalogResource<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for CatalogResource<T>

§

impl<T> !RefUnwindSafe for CatalogResource<T>

§

impl<T> !UnwindSafe for CatalogResource<T>

§

impl<T> Send for CatalogResource<T>
where PhantomData<T>: Send,

§

impl<T> Sync for CatalogResource<T>
where PhantomData<T>: Sync,

§

impl<T> Unpin for CatalogResource<T>
where PhantomData<T>: Unpin,

§

impl<T> UnsafeUnpin for CatalogResource<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

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

fn in_current_span(self) -> Instrumented<Self> ⓘ

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

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

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

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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