Skip to content

Commit

Permalink
adding Roles function
Browse files Browse the repository at this point in the history
  • Loading branch information
erickpintor committed Oct 17, 2018
1 parent 5c4b89a commit 6548f76
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
2.0.1-SNAPSHHOT
* Adds CreateRole, and Role functions
* Adds CreateRole, Roles, and Role functions

2.0.0
* Adds support for @query type (user defined functions)
Expand Down
14 changes: 14 additions & 0 deletions Sources/FaunaDB/Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ public struct Functions: Fn {
}
}

/// Returns a native reference to roles. This allows for example,
/// paginate over all roles in a database.
///
/// [Reference](https://app.fauna.com/documentation/reference/queryapi#basic-forms).
public struct Roles: Fn {

var call: Fn.Call

/// - Parameter scope: the scope database.
public init(scope: Expr? = nil) {
self.call = fn("roles" => (scope ?? NullV()))
}
}

/// Returns a native reference to keys. This allows for example,
/// paginate over all keys in a database.
///
Expand Down
2 changes: 2 additions & 0 deletions Sources/FaunaDB/Value.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ public struct Native {
public static let DATABASES: RefV = RefV("databases")
public static let KEYS: RefV = RefV("keys")
public static let FUNCTIONS: RefV = RefV("functions")
public static let ROLES: RefV = RefV("roles")
public static let TOKENS: RefV = RefV("tokens")
public static let CREDENTIALS: RefV = RefV("credentials")

Expand All @@ -294,6 +295,7 @@ public struct Native {
case "databases": return DATABASES
case "keys": return KEYS
case "functions": return FUNCTIONS
case "roles": return ROLES
case "tokens": return TOKENS
case "credentials": return CREDENTIALS
default: return RefV(id)
Expand Down
1 change: 1 addition & 0 deletions Tests/FaunaDBTests/ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ class ClientTests: XCTestCase {
assert(query: Class("cls"), toReturn: RefV("cls", class: Native.CLASSES))
assert(query: Index("idx"), toReturn: RefV("idx", class: Native.INDEXES))
assert(query: Function("fn"), toReturn: RefV("fn", class: Native.FUNCTIONS))
assert(query: Role("rl"), toReturn: RefV("rl", class: Native.ROLES))
}

func testNestedClass() {
Expand Down
2 changes: 2 additions & 0 deletions Tests/FaunaDBTests/SerializationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ class SerializationTests: XCTestCase {
assert(expr: Databases(), toBecome: "{\"databases\":null}")
assert(expr: Indexes(), toBecome: "{\"indexes\":null}")
assert(expr: Functions(), toBecome: "{\"functions\":null}")
assert(expr: Roles(), toBecome: "{\"roles\":null}")
assert(expr: Keys(), toBecome: "{\"keys\":null}")
assert(expr: Tokens(), toBecome: "{\"tokens\":null}")
assert(expr: Credentials(), toBecome: "{\"credentials\":null}")
Expand All @@ -806,6 +807,7 @@ class SerializationTests: XCTestCase {
assert(expr: Databases(scope: Database("scope")), toBecome: "{\"databases\":{\"database\":\"scope\"}}")
assert(expr: Indexes(scope: Database("scope")), toBecome: "{\"indexes\":{\"database\":\"scope\"}}")
assert(expr: Functions(scope: Database("scope")), toBecome: "{\"functions\":{\"database\":\"scope\"}}")
assert(expr: Roles(scope: Database("scope")), toBecome: "{\"roles\":{\"database\":\"scope\"}}")
assert(expr: Keys(scope: Database("scope")), toBecome: "{\"keys\":{\"database\":\"scope\"}}")
assert(expr: Tokens(scope: Database("scope")), toBecome: "{\"tokens\":{\"database\":\"scope\"}}")
assert(expr: Credentials(scope: Database("scope")), toBecome: "{\"credentials\":{\"database\":\"scope\"}}")
Expand Down

0 comments on commit 6548f76

Please sign in to comment.