snowflake.core.database.DatabaseCollection | Snowflake Documentation (original) (raw)

class snowflake.core.database.DatabaseCollection(root: Root)

Bases: AccountObjectCollectionParent[DatabaseResource]

Represents the collection operations on the Snowflake Database resource.

With this collection, you can create, iterate through, and search for Databases that you have access to in the current context.

Examples

Creating a database instance:

databases = root.databases new_database = Database( ... name="my_new_database", ... comment="this is my new database to prototype a new feature in", ... ) databases.create(new_database)

Attributes

root

The Root object this collection belongs to.

Methods

create(database: DatabaseModel, *, clone: str | Clone | None = None, from_share: str | None = None, mode: CreateMode = CreateMode.error_if_exists) → DatabaseResource

Create a database in Snowflake.

Parameters:

create_async(database: DatabaseModel, *, clone: str | Clone | None = None, from_share: str | None = None, mode: CreateMode = CreateMode.error_if_exists) → PollingOperation[DatabaseResource]

An asynchronous version of create().

Refer to PollingOperation for more information on asynchronous execution and the return type.

items() → ItemsView[str, T]

iter(*, like: str | None = None, starts_with: str | None = None, limit: int | None = None, from_name: str | None = None) → Iterator[DatabaseModel]

Iterate through Database objects from Snowflake, filtering on any optional ‘like’ pattern.

Parameters:

Examples

Showing all databases that you have access to see:

databases = root.databases.iter()

Showing information of the exact database you want to see:

databases = root.databases.iter(like="your-database-name")

Showing databases starting with ‘your-database-name-‘:

databases = root.databases.iter(like="your-database-name-%")

Using a for loop to retrieve information from iterator:

for database in databases: print(database.name, database.query)

iter_async(*, like: str | None = None, starts_with: str | None = None, limit: int | None = None, from_name: str | None = None) → PollingOperation[Iterator[DatabaseModel]]

An asynchronous version of iter().

Refer to PollingOperation for more information on asynchronous execution and the return type.

keys() → KeysView[str]

values() → ValuesView[T]