Skip to main content

Databases

Struct Databases 

Source
pub struct Databases { /* private fields */ }
Expand description

The Databases service allows you to create structured collections of documents, query and filter lists of documents

Implementations§

Source§

impl Databases

Source

pub fn new(client: &Client) -> Self

Source

pub fn client(&self) -> &Client

Source

pub async fn list( &self, queries: Option<Vec<String>>, search: Option<&str>, total: Option<bool>, ) -> Result<DatabaseList>

Get a list of all databases from the current Appwrite project. You can use the search parameter to filter your results.

Source

pub async fn create( &self, database_id: impl Into<String>, name: impl Into<String>, enabled: Option<bool>, ) -> Result<Database>

Create a new Database.

Source

pub async fn list_transactions( &self, queries: Option<Vec<String>>, ) -> Result<TransactionList>

List transactions across all databases.

Source

pub async fn create_transaction(&self, ttl: Option<i64>) -> Result<Transaction>

Create a new transaction.

Source

pub async fn get_transaction( &self, transaction_id: impl Into<String>, ) -> Result<Transaction>

Get a transaction by its unique ID.

Source

pub async fn update_transaction( &self, transaction_id: impl Into<String>, commit: Option<bool>, rollback: Option<bool>, ) -> Result<Transaction>

Update a transaction, to either commit or roll back its operations.

Source

pub async fn delete_transaction( &self, transaction_id: impl Into<String>, ) -> Result<()>

Delete a transaction by its unique ID.

Source

pub async fn create_operations( &self, transaction_id: impl Into<String>, operations: Option<Vec<Value>>, ) -> Result<Transaction>

Create multiple operations in a single transaction.

Source

pub async fn get(&self, database_id: impl Into<String>) -> Result<Database>

Get a database by its unique ID. This endpoint response returns a JSON object with the database metadata.

Source

pub async fn update( &self, database_id: impl Into<String>, name: Option<&str>, enabled: Option<bool>, ) -> Result<Database>

Update a database by its unique ID.

Source

pub async fn delete(&self, database_id: impl Into<String>) -> Result<()>

Delete a database by its unique ID. Only API keys with with databases.write scope can delete a database.

Source

pub async fn list_collections( &self, database_id: impl Into<String>, queries: Option<Vec<String>>, search: Option<&str>, total: Option<bool>, ) -> Result<CollectionList>

Get a list of all collections that belong to the provided databaseId. You can use the search parameter to filter your results.

Source

pub async fn create_collection( &self, database_id: impl Into<String>, collection_id: impl Into<String>, name: impl Into<String>, permissions: Option<Vec<String>>, document_security: Option<bool>, enabled: Option<bool>, attributes: Option<Vec<Value>>, indexes: Option<Vec<Value>>, ) -> Result<Collection>

Create a new Collection. Before using this route, you should create a new database resource using either a server integration API or directly from your database console.

Source

pub async fn get_collection( &self, database_id: impl Into<String>, collection_id: impl Into<String>, ) -> Result<Collection>

Get a collection by its unique ID. This endpoint response returns a JSON object with the collection metadata.

Source

pub async fn update_collection( &self, database_id: impl Into<String>, collection_id: impl Into<String>, name: Option<&str>, permissions: Option<Vec<String>>, document_security: Option<bool>, enabled: Option<bool>, purge: Option<bool>, ) -> Result<Collection>

Update a collection by its unique ID.

Source

pub async fn delete_collection( &self, database_id: impl Into<String>, collection_id: impl Into<String>, ) -> Result<()>

Delete a collection by its unique ID. Only users with write permissions have access to delete this resource.

Source

pub async fn list_attributes( &self, database_id: impl Into<String>, collection_id: impl Into<String>, queries: Option<Vec<String>>, total: Option<bool>, ) -> Result<AttributeList>

List attributes in the collection.

Source

pub async fn create_boolean_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<bool>, array: Option<bool>, ) -> Result<AttributeBoolean>

Create a boolean attribute.

Source

pub async fn update_boolean_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<bool>, new_key: Option<&str>, ) -> Result<AttributeBoolean>

Update a boolean attribute. Changing the default value will not update already existing documents.

Source

pub async fn create_datetime_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<&str>, array: Option<bool>, ) -> Result<AttributeDatetime>

Create a date time attribute according to the ISO 8601 standard.

Source

pub async fn update_datetime_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<&str>, new_key: Option<&str>, ) -> Result<AttributeDatetime>

Update a date time attribute. Changing the default value will not update already existing documents.

Source

pub async fn create_email_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<&str>, array: Option<bool>, ) -> Result<AttributeEmail>

Create an email attribute.

Source

pub async fn update_email_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<&str>, new_key: Option<&str>, ) -> Result<AttributeEmail>

Update an email attribute. Changing the default value will not update already existing documents.

Source

pub async fn create_enum_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, elements: impl IntoIterator<Item = impl Into<String>>, required: bool, default: Option<&str>, array: Option<bool>, ) -> Result<AttributeEnum>

Create an enum attribute. The elements param acts as a white-list of accepted values for this attribute.

Source

pub async fn update_enum_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, elements: impl IntoIterator<Item = impl Into<String>>, required: bool, default: Option<&str>, new_key: Option<&str>, ) -> Result<AttributeEnum>

Update an enum attribute. Changing the default value will not update already existing documents.

Source

pub async fn create_float_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, min: Option<f64>, max: Option<f64>, default: Option<f64>, array: Option<bool>, ) -> Result<AttributeFloat>

Create a float attribute. Optionally, minimum and maximum values can be provided.

Source

pub async fn update_float_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<f64>, min: Option<f64>, max: Option<f64>, new_key: Option<&str>, ) -> Result<AttributeFloat>

Update a float attribute. Changing the default value will not update already existing documents.

Source

pub async fn create_integer_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, min: Option<i64>, max: Option<i64>, default: Option<i64>, array: Option<bool>, ) -> Result<AttributeInteger>

Create an integer attribute. Optionally, minimum and maximum values can be provided.

Source

pub async fn update_integer_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<i64>, min: Option<i64>, max: Option<i64>, new_key: Option<&str>, ) -> Result<AttributeInteger>

Update an integer attribute. Changing the default value will not update already existing documents.

Source

pub async fn create_ip_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<&str>, array: Option<bool>, ) -> Result<AttributeIp>

Create IP address attribute.

Source

pub async fn update_ip_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<&str>, new_key: Option<&str>, ) -> Result<AttributeIp>

Update an ip attribute. Changing the default value will not update already existing documents.

Source

pub async fn create_line_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<Vec<String>>, ) -> Result<AttributeLine>

Create a geometric line attribute.

Source

pub async fn update_line_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<Vec<String>>, new_key: Option<&str>, ) -> Result<AttributeLine>

Update a line attribute. Changing the default value will not update already existing documents.

Source

pub async fn create_longtext_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<&str>, array: Option<bool>, encrypt: Option<bool>, ) -> Result<AttributeLongtext>

Create a longtext attribute.

Source

pub async fn update_longtext_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<&str>, new_key: Option<&str>, ) -> Result<AttributeLongtext>

Update a longtext attribute. Changing the default value will not update already existing documents.

Source

pub async fn create_mediumtext_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<&str>, array: Option<bool>, encrypt: Option<bool>, ) -> Result<AttributeMediumtext>

Create a mediumtext attribute.

Source

pub async fn update_mediumtext_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<&str>, new_key: Option<&str>, ) -> Result<AttributeMediumtext>

Update a mediumtext attribute. Changing the default value will not update already existing documents.

Source

pub async fn create_point_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<Vec<String>>, ) -> Result<AttributePoint>

Create a geometric point attribute.

Source

pub async fn update_point_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<Vec<String>>, new_key: Option<&str>, ) -> Result<AttributePoint>

Update a point attribute. Changing the default value will not update already existing documents.

Source

pub async fn create_polygon_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<Vec<String>>, ) -> Result<AttributePolygon>

Create a geometric polygon attribute.

Source

pub async fn update_polygon_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<Vec<String>>, new_key: Option<&str>, ) -> Result<AttributePolygon>

Update a polygon attribute. Changing the default value will not update already existing documents.

Source

pub async fn create_relationship_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, related_collection_id: impl Into<String>, type: RelationshipType, two_way: Option<bool>, key: Option<&str>, two_way_key: Option<&str>, on_delete: Option<RelationMutate>, ) -> Result<AttributeRelationship>

Create relationship attribute. Learn more about relationship attributes.

Source

pub async fn update_relationship_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, on_delete: Option<RelationMutate>, new_key: Option<&str>, ) -> Result<AttributeRelationship>

Update relationship attribute. Learn more about relationship attributes.

Source

pub async fn create_string_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, size: i64, required: bool, default: Option<&str>, array: Option<bool>, encrypt: Option<bool>, ) -> Result<AttributeString>

Create a string attribute.

Source

pub async fn update_string_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<&str>, size: Option<i64>, new_key: Option<&str>, ) -> Result<AttributeString>

Update a string attribute. Changing the default value will not update already existing documents.

Source

pub async fn create_text_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<&str>, array: Option<bool>, encrypt: Option<bool>, ) -> Result<AttributeText>

Create a text attribute.

Source

pub async fn update_text_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<&str>, new_key: Option<&str>, ) -> Result<AttributeText>

Update a text attribute. Changing the default value will not update already existing documents.

Source

pub async fn create_url_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<&str>, array: Option<bool>, ) -> Result<AttributeUrl>

Create a URL attribute.

Source

pub async fn update_url_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<&str>, new_key: Option<&str>, ) -> Result<AttributeUrl>

Update an url attribute. Changing the default value will not update already existing documents.

Source

pub async fn create_varchar_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, size: i64, required: bool, default: Option<&str>, array: Option<bool>, encrypt: Option<bool>, ) -> Result<AttributeVarchar>

Create a varchar attribute.

Source

pub async fn update_varchar_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, required: bool, default: Option<&str>, size: Option<i64>, new_key: Option<&str>, ) -> Result<AttributeVarchar>

Update a varchar attribute. Changing the default value will not update already existing documents.

Source

pub async fn get_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, ) -> Result<Value>

Get attribute by ID.

Source

pub async fn delete_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, ) -> Result<()>

Deletes an attribute.

Source

pub async fn list_documents( &self, database_id: impl Into<String>, collection_id: impl Into<String>, queries: Option<Vec<String>>, transaction_id: Option<&str>, total: Option<bool>, ttl: Option<i64>, ) -> Result<DocumentList>

Get a list of all the user’s documents in a given collection. You can use the query params to filter your results.

Source

pub async fn create_document( &self, database_id: impl Into<String>, collection_id: impl Into<String>, document_id: impl Into<String>, data: Value, permissions: Option<Vec<String>>, transaction_id: Option<&str>, ) -> Result<Document>

Create a new Document. Before using this route, you should create a new collection resource using either a server integration API or directly from your database console.

Source

pub async fn create_documents( &self, database_id: impl Into<String>, collection_id: impl Into<String>, documents: Vec<Value>, transaction_id: Option<&str>, ) -> Result<DocumentList>

Create new Documents. Before using this route, you should create a new collection resource using either a server integration API or directly from your database console.

Source

pub async fn upsert_documents( &self, database_id: impl Into<String>, collection_id: impl Into<String>, documents: Vec<Value>, transaction_id: Option<&str>, ) -> Result<DocumentList>

Create or update Documents. Before using this route, you should create a new collection resource using either a server integration API or directly from your database console.

Source

pub async fn update_documents( &self, database_id: impl Into<String>, collection_id: impl Into<String>, data: Option<Value>, queries: Option<Vec<String>>, transaction_id: Option<&str>, ) -> Result<DocumentList>

Update all documents that match your queries, if no queries are submitted then all documents are updated. You can pass only specific fields to be updated.

Source

pub async fn delete_documents( &self, database_id: impl Into<String>, collection_id: impl Into<String>, queries: Option<Vec<String>>, transaction_id: Option<&str>, ) -> Result<DocumentList>

Bulk delete documents using queries, if no queries are passed then all documents are deleted.

Source

pub async fn get_document( &self, database_id: impl Into<String>, collection_id: impl Into<String>, document_id: impl Into<String>, queries: Option<Vec<String>>, transaction_id: Option<&str>, ) -> Result<Document>

Get a document by its unique ID. This endpoint response returns a JSON object with the document data.

Source

pub async fn upsert_document( &self, database_id: impl Into<String>, collection_id: impl Into<String>, document_id: impl Into<String>, data: Option<Value>, permissions: Option<Vec<String>>, transaction_id: Option<&str>, ) -> Result<Document>

Create or update a Document. Before using this route, you should create a new collection resource using either a server integration API or directly from your database console.

Source

pub async fn update_document( &self, database_id: impl Into<String>, collection_id: impl Into<String>, document_id: impl Into<String>, data: Option<Value>, permissions: Option<Vec<String>>, transaction_id: Option<&str>, ) -> Result<Document>

Update a document by its unique ID. Using the patch method you can pass only specific fields that will get updated.

Source

pub async fn delete_document( &self, database_id: impl Into<String>, collection_id: impl Into<String>, document_id: impl Into<String>, transaction_id: Option<&str>, ) -> Result<()>

Delete a document by its unique ID.

Source

pub async fn decrement_document_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, document_id: impl Into<String>, attribute: impl Into<String>, value: Option<f64>, min: Option<f64>, transaction_id: Option<&str>, ) -> Result<Document>

Decrement a specific attribute of a document by a given value.

Source

pub async fn increment_document_attribute( &self, database_id: impl Into<String>, collection_id: impl Into<String>, document_id: impl Into<String>, attribute: impl Into<String>, value: Option<f64>, max: Option<f64>, transaction_id: Option<&str>, ) -> Result<Document>

Increment a specific attribute of a document by a given value.

Source

pub async fn list_indexes( &self, database_id: impl Into<String>, collection_id: impl Into<String>, queries: Option<Vec<String>>, total: Option<bool>, ) -> Result<IndexList>

List indexes in the collection.

Source

pub async fn create_index( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, type: DatabasesIndexType, attributes: impl IntoIterator<Item = impl Into<String>>, orders: Option<Vec<OrderBy>>, lengths: Option<Vec<i64>>, ) -> Result<Index>

Creates an index on the attributes listed. Your index should include all the attributes you will query in a single request. Attributes can be key, fulltext, and unique.

Source

pub async fn get_index( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, ) -> Result<Index>

Get an index by its unique ID.

Source

pub async fn delete_index( &self, database_id: impl Into<String>, collection_id: impl Into<String>, key: impl Into<String>, ) -> Result<()>

Delete an index.

Trait Implementations§

Source§

impl Clone for Databases

Source§

fn clone(&self) -> Databases

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Databases

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Service for Databases

Source§

fn client(&self) -> &Client

Get a reference to the client

Auto Trait Implementations§

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: 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: 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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