Skip to content

Commit 927b20c

Browse files
authored
Merge pull request #55 from owainhunt/datastore-aggregation-query
Datastore aggregation query, composite filter and multiple database support
2 parents aba2423 + d968ed7 commit 927b20c

15 files changed

+654
-162
lines changed

Datastore/Sources/Data API/API/ProjectAPI.swift

Lines changed: 307 additions & 101 deletions
Large diffs are not rendered by default.
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import Core
22

33
public struct AllocateIdsRequest: GoogleCloudModel {
4-
public init(keys: [Key]? = nil) {
4+
public init(
5+
keys: [Key]? = nil,
6+
databaseId: String? = nil
7+
) {
8+
self.databaseId = databaseId
59
self.keys = keys
610
}
7-
/// A list of keys with incomppublic lete key paths for which to allocate IDs. No key may be reserved/read-only.
11+
/// The ID of the database against which to make the request.
12+
/// '(default)' is not allowed; please use empty string '' to refer the default database.
13+
public let databaseId: String?
14+
/// A list of keys with incomplete key paths for which to allocate IDs. No key may be reserved/read-only.
815
public let keys: [Key]?
916
}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import Core
22

33
public struct BeginTransactionRequest: GoogleCloudModel {
4-
public init(transactionOptions: TransactionOptions? = nil) {
4+
public init(
5+
transactionOptions: TransactionOptions? = nil,
6+
databaseId: String? = nil
7+
) {
58
self.transactionOptions = transactionOptions
9+
self.databaseId = databaseId
610
}
711
/// Options for a new transaction.
812
public let transactionOptions: TransactionOptions?
13+
/// The ID of the database against which to make the request.
14+
/// '(default)' is not allowed; please use empty string '' to refer the default database.
15+
public let databaseId: String?
916
}

Datastore/Sources/Data API/Models/Project API/Request/CommitRequest.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ import Core
22

33
public struct CommitRequest: GoogleCloudModel {
44

5-
public init(mode: Mode = .nonTransactional, mutations: [Mutation]) {
5+
public init(
6+
mode: Mode = .nonTransactional,
7+
mutations: [Mutation],
8+
databaseId: String? = nil
9+
) {
610
self.mode = mode
711
self.mutations = mutations
12+
self.databaseId = databaseId
813
}
914

1015
/// The type of commit to perform.
@@ -19,6 +24,9 @@ public struct CommitRequest: GoogleCloudModel {
1924
public let mutations: [Mutation]
2025
/// The identifier of the transaction associated with the commit.
2126
private var transaction: String?
27+
/// The ID of the database against which to make the request.
28+
/// '(default)' is not allowed; please use empty string '' to refer the default database.
29+
public let databaseId: String?
2230

2331
/// The modes available for commits.
2432
public enum Mode: GoogleCloudModel {
@@ -105,11 +113,14 @@ public struct CommitRequest: GoogleCloudModel {
105113
case mode
106114
case mutations
107115
case transaction
116+
case databaseId
108117
}
109118

110119
public func encode(to encoder: Encoder) throws {
111120
var container = encoder.container(keyedBy: CodingKeys.self)
112121
try container.encode(mutations, forKey: .mutations)
122+
try container.encodeIfPresent(databaseId, forKey: .databaseId)
123+
try container.encodeIfPresent(transaction, forKey: .transaction)
113124

114125
switch mode {
115126
case .transactional(let value):
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import Core
22

33
public struct LookupRequest: GoogleCloudModel {
4-
public init(keys: [Key]? = nil,
5-
readOptions: ReadOptions? = nil) {
4+
public init(
5+
keys: [Key]? = nil,
6+
readOptions: ReadOptions? = nil,
7+
databaseId: String? = nil
8+
) {
69
self.keys = keys
710
self.readOptions = readOptions
11+
self.databaseId = databaseId
812
}
913
/// Keys of entities to look up.
1014
public let keys: [Key]?
1115
/// The options for this lookup request.
1216
public let readOptions: ReadOptions?
17+
/// The ID of the database against which to make the request.
18+
/// '(default)' is not allowed; please use empty string '' to refer the default database.
19+
public let databaseId: String?
1320
}
1421

Datastore/Sources/Data API/Models/Project API/Request/ReserveIdsRequest.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import Core
22

33
public struct ReserveIdsRequest: GoogleCloudModel {
4-
public init(databaseId: String? = nil,
5-
keys: [Key]) {
4+
public init(
5+
databaseId: String? = nil,
6+
keys: [Key]
7+
) {
68
self.databaseId = databaseId
79
self.keys = keys
810
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import Core
22

33
public struct RollbackRequest: GoogleCloudModel {
4+
5+
public init(
6+
transaction: String,
7+
databaseId: String? = nil
8+
) {
9+
self.transaction = transaction
10+
self.databaseId = databaseId
11+
}
12+
413
/// The transaction identifier,
514
public let transaction: String
15+
/// The ID of the database against which to make the request.
16+
/// '(default)' is not allowed; please use empty string '' to refer the default database.
17+
public let databaseId: String?
618
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import Core
2+
3+
struct RunAggregationQueryRequest: GoogleCloudModel {
4+
5+
init(
6+
gqlQuery: GqlQuery,
7+
partitionId: PartitionId? = nil,
8+
readOptions: ReadOptions? = nil,
9+
databaseId: String? = nil
10+
) {
11+
self.gqlQuery = gqlQuery
12+
self.aggregationQuery = nil
13+
self.partitionId = partitionId
14+
self.readOptions = readOptions
15+
self.databaseId = databaseId
16+
}
17+
18+
init(
19+
query: Query,
20+
aggregations: [Aggregation],
21+
partitionId: PartitionId? = nil,
22+
readOptions: ReadOptions? = nil,
23+
databaseId: String? = nil
24+
) {
25+
self.aggregationQuery = AggregationQuery(aggregations: aggregations, nestedQuery: query)
26+
self.gqlQuery = nil
27+
self.partitionId = partitionId
28+
self.readOptions = readOptions
29+
self.databaseId = databaseId
30+
}
31+
32+
/// The GQL query to run.
33+
let gqlQuery: GqlQuery?
34+
/// The aggregation query to run.
35+
let aggregationQuery: AggregationQuery?
36+
/// The (optional) namespace and partition against which to run the query
37+
let partitionId: PartitionId?
38+
/// The options for this query.
39+
let readOptions: ReadOptions?
40+
/// The ID of the database against which to make the request.
41+
/// '(default)' is not allowed; please use empty string '' to refer the default database.
42+
let databaseId: String?
43+
}
44+
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import Core
22

33
public struct RunQueryRequest: GoogleCloudModel {
4-
public init(gqlQuery: GqlQuery? = nil,
5-
partitionId: PartitionId? = nil,
6-
query: Query? = nil,
7-
readOptions: ReadOptions? = nil) {
4+
5+
public init(
6+
gqlQuery: GqlQuery? = nil,
7+
partitionId: PartitionId? = nil,
8+
query: Query? = nil,
9+
readOptions: ReadOptions? = nil,
10+
databaseId: String? = nil
11+
) {
812
self.gqlQuery = gqlQuery
913
self.partitionId = partitionId
1014
self.query = query
1115
self.readOptions = readOptions
16+
self.databaseId = databaseId
1217
}
18+
1319
/// The GQL query to run.
1420
public let gqlQuery: GqlQuery?
1521
/// Entities are partitioned into subsets, identified by a partition ID. Queries are scoped to a single partition. This partition ID is normalized with the standard default context partition ID.
@@ -18,5 +24,8 @@ public struct RunQueryRequest: GoogleCloudModel {
1824
public let query: Query?
1925
/// The options for this query.
2026
public let readOptions: ReadOptions?
27+
/// The ID of the database against which to make the request.
28+
/// '(default)' is not allowed; please use empty string '' to refer the default database.
29+
public let databaseId: String?
2130
}
2231

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import Core
22

33
public struct LookupResponse: GoogleCloudModel {
4-
public init(deferred: [Key]? = nil, found: [EntityResult]? = nil, missing: [EntityResult]? = nil) {
4+
public init(
5+
deferred: [Key]? = nil,
6+
found: [EntityResult]? = nil,
7+
missing: [MissingEntityResult]? = nil
8+
) {
59
self.deferred = deferred
610
self.found = found
711
self.missing = missing
@@ -11,5 +15,16 @@ public struct LookupResponse: GoogleCloudModel {
1115
/// Entities found as ResultType.FULL entities. The order of results in this field is undefined and has no relation to the order of the keys in the input.
1216
public let found: [EntityResult]?
1317
/// Entities not found as ResultType.KEY_ONLY entities. The order of results in this field is undefined and has no relation to the order of the keys in the input.
14-
public let missing: [EntityResult]?
18+
public let missing: [MissingEntityResult]?
19+
}
20+
21+
public struct MissingEntityResult: GoogleCloudModel {
22+
/// A KEY_ONLY entity
23+
public let entity: MissingEntity
24+
/// the version of the snapshot that was used to look up the entity
25+
public let version: String
26+
27+
public struct MissingEntity: GoogleCloudModel {
28+
public let key: Key
29+
}
1530
}

0 commit comments

Comments
 (0)