snowflake.core.database_role.DatabaseRoleCollectionΒΆ

class snowflake.core.database_role.DatabaseRoleCollection(database: DatabaseResource, root: Root)ΒΆ

Bases: ObjectCollection[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"
... ))
Copy

Attributes

databaseΒΆ

The DatabaseResource this database role belongs to.

rootΒΆ

The Root object this database role belongs to.

Methods

create(database_role: DatabaseRole, *, mode: CreateMode = CreateMode.error_if_exists) β†’ DatabaseRoleResourceΒΆ

Create a database role in Snowflake.

Parameters:
  • database_role (DatabaseRole) – The DatabaseRole object, together with the DatabaseRole’s properties: name ; comment is optional

  • mode (CreateMode, optional) –

    One of the following enum values.

    CreateMode.error_if_exists: Throw an snowflake.core.exceptions.ConflictError if the database role already exists in Snowflake. Equivalent to SQL create database role <name> ....

    CreateMode.or_replace: Replace if the database role already exists in Snowflake. Equivalent to SQL create or replace database role <name> ....

    CreateMode.if_not_exists: Do nothing if the database role already exists in Snowflake. Equivalent to SQL create database role <name> if not exists...

    Default is CreateMode.error_if_exists.

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)
Copy
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:
  • show_limit (int, optional) – Limit of the maximum number of rows returned by iter(). The default is None, which behaves equivalently to show_limit=10000. This value must be between 1 and 10000.

  • from_name (str, optional) – Fetch rows only following the first row whose object name matches the specified string. This is case-sensitive and does not have to be the full name.

Examples

Showing all database roles that you have access to see:

>>> database_roles = database_role_collection.iter()
Copy

Showing roles from β€˜your-role-name-β€˜:

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

Using a for loop to retrieve information from iterator:

>>> for database_role in database_roles:
...    print(database_role.name, database_role.comment)
Copy
keys() β†’ KeysView[str]ΒΆ
values() β†’ ValuesView[T]ΒΆ