Check out v4 of the Fauna CLI

v4 of the Fauna CLI is now in beta.

The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start.

Role.all()

Learn: Roles

Get a Set of all user-defined roles.

Signature

Role.all() => Set<Role>

Role.all(range: { from: Any } | { to: Any } | { from: Any, to: Any }) => Set<Role>

Description

Gets a Set containing all user-defined roles, represented as Role documents, for the database. To limit the returned Set, you can provide an optional range.

Role documents are FQL versions of a database’s FSL role schema. See Roles.

If this method is the last expression in a query, the first page of the Set is returned. See Pagination.

Staged schema

If a database has staged schema, this method interacts with the database’s staged schema, not the active schema.

Parameters

Parameter Type Required Description

range

{ from: Any } | { to: Any } | { from: Any, to: Any }

Specifies a range of Role documents in the form { from: start, to: end }. from and to arguments should be in the order returned by an unbounded Role.all() call. See Range examples.

The Set only includes documents in this range (inclusive). Omit from or to to run unbounded range searches.

If a range is omitted, all roles are returned.

Range parameters

Name Type Required Description

from

Any

Beginning of the range (inclusive). Must be an Role document.

to

Any

End of the range (inclusive). Must be an Role document.

Return value

Type Description

Set<Role>

Set of Role documents in the provided range. If a range is omitted, all roles are returned.

The Set is empty if:

  • The database has no roles.

  • There are no roles in the provided range.

  • The provided range’s from value is greater than to.

Examples

Range examples

  1. Get all roles for the database:

    Role.all()
    {
      data: [
        {
          name: "manager",
          coll: Role,
          ts: Time("2099-10-28T16:14:20.640Z"),
          privileges: [ ... ],
          membership: [ ... ]
        },
        {
          name: "customer",
          coll: Role,
          ts: Time("2099-10-28T16:14:20.640Z"),
          privileges: [ ... ],
          membership: [ ... ]
        }
      ]
    }
  2. Given the previous Set, get all roles starting with manager (inclusive):

    Role.all({ from: Role.byName("manager") })
    {
      data: [
        {
          name: "manager",
          coll: Role,
          ts: Time("2099-10-28T16:14:20.640Z"),
          privileges: [ ... ],
          membership: [ ... ]
        },
        {
          name: "customer",
          coll: Role,
          ts: Time("2099-10-28T16:14:20.640Z"),
          privileges: [ ... ],
          membership: [ ... ]
        }
      ]
    }
  3. Get a Set of roles from manager (inclusive) to customer (inclusive):

    Role.all({ from: Role.byName("manager"),
                to: Role.byName("customer") })
    {
      data: [
        {
          name: "manager",
          coll: Role,
          ts: Time("2099-10-28T16:14:20.640Z"),
          privileges: [ ... ],
          membership: [ ... ]
        },
        {
          name: "customer",
          coll: Role,
          ts: Time("2099-10-28T16:14:20.640Z"),
          privileges: [ ... ],
          membership: [ ... ]
        }
      ]
    }
  4. Get a Set of roles up to customer (inclusive):

    Role.all({ to: Role.byName("customer") })
    {
      data: [
        {
          name: "manager",
          coll: Role,
          ts: Time("2099-10-28T16:14:20.640Z"),
          privileges: [ ... ],
          membership: [ ... ]
        },
        {
          name: "customer",
          coll: Role,
          ts: Time("2099-10-28T16:14:20.640Z"),
          privileges: [ ... ],
          membership: [ ... ]
        }
      ]
    }

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!