snowflake.core.database.DatabaseResource¶
- class snowflake.core.database.DatabaseResource(name: str, collection: DatabaseCollection)¶
- Bases: - ObjectReferenceMixin[- DatabaseCollection]- Represents a reference to a Snowflake database. - With this database reference, you can create, update, and fetch information about databases, as well as perform certain unique actions on them. - Attributes - database_roles¶
- The DatabaseRoleCollection of all database roles contained in this database. - Examples - Getting all database roles in - my_db:- >>> root.databases["my_db"].database_roles 
 - root¶
- The Root object this reference belongs to. 
 - schemas¶
- The SchemaCollection of all schemas contained in this database. - Examples - Getting all schemas in - my_db:- >>> root.databases["my_db"].schemas 
 - Methods - create_or_alter(database: DatabaseModel) None¶
- Create or alter a database in Snowflake. 
 - create_or_alter_async(database: DatabaseModel) PollingOperation[None]¶
- An asynchronous version of - create_or_alter().- Refer to - PollingOperationfor more information on asynchronous execution and the return type.
 - create_or_update(database: DatabaseModel) None¶
- The - create_or_update()method is deprecated; use- create_or_alter()instead.- Create or update an existing database. - Create a database from a reference: - >>> root.databases["my_new_db"].create_or_update(Database("my_new_db")) 
 - delete(if_exists: bool | None = None) None¶
- The - delete()method is deprecated; use- drop()instead.- Delete this database. - if_exists: bool, optional
- Check the existence of this database before dropping it. The default is - None, which is equivalent to- False.
 - Deleting a database using its reference: - >>> root.databases["to_be_deleted"].delete() 
 - disable_failover(accounts: list[str] | None = None) None¶
- Disables failover for this primary databases. - Which means that no replica of this database (i.e. secondary database) can be promoted to serve as the primary database. - Optionally provide a comma-separated list of accounts in your organization to disable failover for this database only in the specified accounts. - Parameters:
- accounts (list of str, optional) – Array of unique account identifiers for which to enable failover. 
 - Examples - Disabling failover to some account using a database reference: - >>> root.databases["my_db"].enable_failover(accounts=["old_failover_acc"]) 
 - disable_failover_async(accounts: list[str] | None = None) PollingOperation[None]¶
- An asynchronous version of - disable_failover().- Refer to - PollingOperationfor more information on asynchronous execution and the return type.
 - disable_replication(accounts: list[str] | None = None) None¶
- Disables replication for this primary database. - Which means that no replica of this database (i.e. secondary database) in another account can be refreshed. Any secondary databases remain linked to the primary database, but requests to refresh a secondary database are denied. - Note that disabling replication for a primary database does not prevent it from being replicated to the same account; therefore, the database continues to be listed in the SHOW REPLICATION DATABASES output. - Optionally provide a comma-separated list of accounts in your organization to disable replication for this database only in the specified accounts. - Parameters:
- accounts (list of str, optional) – Array of unique account identifiers for which to disable replication. 
 - Examples - Disabling all replication of “my_db” database using its reference: - >>> root.databases["my_db"].disable_replication() 
 - disable_replication_async(accounts: list[str] | None = None) PollingOperation[None]¶
- An asynchronous version of - disable_replication().- Refer to - PollingOperationfor more information on asynchronous execution and the return type.
 - drop(if_exists: bool | None = None) None¶
- Drop this database. - Parameters:
- if_exists (bool, optional) – Check the existence of this database before dropping it. The default is - None, which is equivalent to- False.
 - Examples - Using a database reference to drop a database, erroring if it does not exist: - >>> root.databases["to_be_dropped"].drop() - Using a database reference to drop a database, if it exists: - >>> root.databases["to_be_dropped"].drop(if_exists=True) 
 - drop_async(if_exists: bool | None = None) PollingOperation[None]¶
- An asynchronous version of - drop().- Refer to - PollingOperationfor more information on asynchronous execution and the return type.
 - enable_failover(accounts: list[str]) None¶
- Enable a list of replicas of this database that can be promoted to primary. - Parameters:
- accounts (list of str) – Array of unique account identifiers for which to enable failover. 
 - Examples - Enabling failover to an account using a database reference: - >>> root.databases["my_db"].enable_failover(accounts=["my_failover_acc"]) 
 - enable_failover_async(accounts: list[str]) PollingOperation[None]¶
- An asynchronous version of - enable_failover().- Refer to - PollingOperationfor more information on asynchronous execution and the return type.
 - enable_replication(accounts: list[str], ignore_edition_check: bool = False) None¶
- Promotes a local database to serve as a primary database for replication. - A primary database can be replicated in one or more accounts, allowing users in those accounts to query objects in each secondary (i.e. replica) database. - Alternatively, modify an existing primary database to add to or remove from the list of accounts that can store a replica of the database. - Provide a list of accounts in your organization that can store a replica of this database. - Parameters:
- accounts (list of str) – Array of unique account identifiers for which to enable replication. 
- ignore_edition_check (bool, optional) – - Whether to allow replicating data to accounts on lower editions. - Default is - True.
 
 - Examples - Enabling replication of “my_db” database on 2 other accounts using its reference: - >>> root.databases["my_db"].enable_replication( ... accounts=["accountName1", "accountName2"], ignore_edition_check=True ... ) 
 - enable_replication_async(accounts: list[str], ignore_edition_check: bool = False) PollingOperation[None]¶
- An asynchronous version of - enable_replication().- Refer to - PollingOperationfor more information on asynchronous execution and the return type.
 - fetch() DatabaseModel¶
- Fetch the details of a database. - Examples - Fetching a reference to a database to print whether it’s the currently used database: - >>> my_database = root.databases["my_db"].fetch() >>> print(my_database.is_current) 
 - fetch_async() PollingOperation[DatabaseModel]¶
- An asynchronous version of - fetch().- Refer to - PollingOperationfor more information on asynchronous execution and the return type.
 - promote_to_primary_failover() None¶
- Promotes the specified secondary (replica) database to serve as the primary. - When promoted, the database becomes writeable. At the same time, the previous primary database becomes a read-only secondary database. - Examples - Promoting a - my_dbfailover database to be the primary using its reference:- >>> root.databases["my_db"].promote_to_primary_failover() 
 - promote_to_primary_failover_async() PollingOperation[None]¶
- An asynchronous version of - promote_to_primary_failover().- Refer to - PollingOperationfor more information on asynchronous execution and the return type.
 - refresh_replication() None¶
- Refresh a secondary database from its primary database. - A snapshot includes changes to the objects and data. - Examples - Refreshing a database replication using its reference: - >>> root.databases["db_replication"].refresh_replication() 
 - refresh_replication_async() PollingOperation[None]¶
- An asynchronous version of - refresh_replication().- Refer to - PollingOperationfor more information on asynchronous execution and the return type.
 - undrop() None¶
- Undrop this database. - Examples - Undropping a database using its reference: - >>> root.databases["to_be_undropped"].undrop() 
 - undrop_async() PollingOperation[None]¶
- An asynchronous version of - undrop().- Refer to - PollingOperationfor more information on asynchronous execution and the return type.