snowflake.core.role.RoleCollectionΒΆ
- class snowflake.core.role.RoleCollection(root: Root)ΒΆ
Bases:
AccountObjectCollectionParent
[RoleResource
]Represents the collection operations on the Snowflake Role resource.
With this collection, you can create, iterate through, and search for roles that you have access to in the current context.
Examples
Creating a role instance:
>>> role_collection = root.roles >>> role_collection.create(Role( ... name="test-role", ... comment="samplecomment" ... ))
Attributes
- rootΒΆ
Methods
- create(role: RoleModel, *, mode: CreateMode = CreateMode.error_if_exists) RoleResource ΒΆ
Create a role in Snowflake.
- Parameters:
role (Role) β The
Role
object, together with theRole
β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 role already exists in Snowflake. Equivalent to SQLcreate role <name> ...
.CreateMode.or_replace
: Replace if the role already exists in Snowflake. Equivalent to SQLcreate or replace role <name> ...
.CreateMode.if_not_exists
: Do nothing if the role already exists in Snowflake. Equivalent to SQLcreate role <name> if not exists...
Default is
CreateMode.error_if_exists
.
Examples
Creating a role, replacing any existing role with the same name:
>>> role = Role( ... name="test-role", ... comment="samplecomment" ... ) >>> role_ref = root.roles.create(role, mode=CreateMode.or_replace)
- items() ItemsView[str, T] ΒΆ
- iter(*, like: str | None = None, limit: int | None = None, starts_with: str | None = None, from_name: str | None = None) Iterator[RoleModel] ΒΆ
Iterate through
Role
objects from Snowflake, filtering on any optional βlikeβ pattern.- Parameters:
like (str, optional) β A case-insensitive string functioning as a filter, with support for SQL wildcard characters (% and _).
starts_with (str, optional) β String used to filter the command output based on the string of characters that appear at the beginning of the object name. Uses case-sensitive pattern matching.
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 roles that you have access to see:
>>> roles = role_collection.iter()
Showing information of the exact role you want to see:
>>> roles = role_collection.iter(like="your-role-name")
Showing roles starting with βyour-role-name-β:
>>> roles = role_collection.iter(like="your-role-name-%") >>> roles = role_collection.iter(starts_with="your-role-name")
Using a for loop to retrieve information from iterator:
>>> for role in roles: ... print(role.name, role.comment)
- keys() KeysView[str] ΒΆ
- values() ValuesView[T] ΒΆ