snowflake.core.database_role.DatabaseRoleCollection | Snowflake Documentation (original) (raw)

Bases: DatabaseObjectCollectionParent[DatabaseRoleResource]

Represents the collection operations on the Snowflake DatabaseRole resource.

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

Examples

Creating a database role instance:

database_role_collection = root.databases["my_db"].database_roles database_role_collection.create(DatabaseRole( ... name="test-role", ... comment="samplecomment" ... ))

Attributes

database

The DatabaseResource this collection belongs to.

root

The Root object this collection belongs to.

Methods

create(database_role: DatabaseRole, *, mode: CreateMode = CreateMode.error_if_exists) → DatabaseRoleResource

Create a database role in Snowflake.

Parameters:

Examples

Creating a database role, replacing any existing database role with the same name:

database_role = DatabaseRole( ... name="test-role", ... comment="samplecomment" ... ) database_role_ref = root.databases["my_db"].database_roles.create(database_role, mode=CreateMode.or_replace)

create_async(database_role: DatabaseRole, *, mode: CreateMode = CreateMode.error_if_exists) → PollingOperation[DatabaseRoleResource]

An asynchronous version of create().

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

items() → ItemsView[str, T]

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

Iterate through DatabaseRole objects from Snowflake, filtering on any optional ‘from_name’ pattern.

Parameters:

Examples

Showing all database roles that you have access to see:

database_roles = database_role_collection.iter()

Showing roles from ‘your-role-name-‘:

database_roles = database_role_collection.iter(from_name="your-role-name-")

Using a for loop to retrieve information from iterator:

for database_role in database_roles: ... print(database_role.name, database_role.comment)

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

An asynchronous version of iter().

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

keys() → KeysView[str]

values() → ValuesView[T]