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" ... ))
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 theDatabaseRole
’s properties: name; comment is optionalmode (CreateMode, optional) –
One of the following enum values.
CreateMode.error_if_exists
: Throw ansnowflake.core.exceptions.ConflictError
if the database role already exists in Snowflake. Equivalent to SQLcreate database role <name> ...
.CreateMode.or_replace
: Replace if the database role already exists in Snowflake. Equivalent to SQLcreate or replace database role <name> ...
.CreateMode.if_not_exists
: Do nothing if the database role already exists in Snowflake. Equivalent to SQLcreate 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)
- 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 between1
and10000
.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()
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)
- keys() KeysView[str] ¶
- values() ValuesView[T] ¶