Skip to content

Commit 20839c2

Browse files
committed
DOPE-180: rename ScopeCollection
1 parent 8cda66b commit 20839c2

6 files changed

Lines changed: 32 additions & 19 deletions

File tree

core/src/main/kotlin/ch/ergon/dope/resolvable/bucket/Bucket.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,28 @@ sealed interface Bucket : Fromable, Joinable, Nestable, Deletable, Updatable, Si
1414
val scope: BucketScope?
1515
}
1616

17+
data class BucketScope(val name: String, val collection: ScopeCollection? = null) {
18+
fun withCollection(collectionName: String) = copy(collection = ScopeCollection(collectionName))
19+
20+
fun withCollection(collection: ScopeCollection) = copy(collection = collection)
21+
}
22+
23+
data class ScopeCollection(val name: String)
24+
1725
data class UnaliasedBucket(
1826
override val name: String,
1927
override val scope: BucketScope? = null,
2028
) : Bucket {
29+
2130
fun alias(alias: String) = AliasedBucket(name, alias, scope)
2231

2332
fun withScope(scopeName: String) = copy(scope = BucketScope(scopeName))
2433

2534
fun withScope(scope: BucketScope) = copy(scope = scope)
26-
27-
fun withScopeAndCollection(scopeName: String, collectionName: String) = copy(
28-
scope = BucketScope(scopeName, BucketCollection(collectionName)),
29-
)
30-
}
31-
32-
data class BucketScope(val name: String, val collection: BucketCollection? = null) {
33-
fun withCollection(collectionName: String) = copy(collection = BucketCollection(collectionName))
35+
fun withScopeAndCollection(scopeName: String, collectionName: String) =
36+
copy(scope = BucketScope(scopeName, ScopeCollection(collectionName)))
3437
}
3538

36-
data class BucketCollection(val name: String)
37-
3839
data class AliasedBucket(
3940
override val name: String,
4041
val alias: String,

couchbase/src/integrationTest/kotlin/ch/ergon/dope/functions/ObjectFunctionsIntegrationTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import ch.ergon.dope.integrationTest.BUCKET
77
import ch.ergon.dope.integrationTest.BaseIntegrationTest
88
import ch.ergon.dope.integrationTest.TestCouchbaseDatabase.detailsField
99
import ch.ergon.dope.integrationTest.toMapValues
10-
import ch.ergon.dope.resolvable.bucket.BucketCollection
1110
import ch.ergon.dope.resolvable.bucket.BucketScope
11+
import ch.ergon.dope.resolvable.bucket.ScopeCollection
1212
import ch.ergon.dope.resolvable.bucket.UnaliasedBucket
1313
import ch.ergon.dope.resolvable.expression.type.Field
1414
import ch.ergon.dope.resolvable.expression.type.TRUE
@@ -29,7 +29,7 @@ import kotlin.test.assertEquals
2929
class ObjectFunctionsIntegrationTest : BaseIntegrationTest() {
3030
@Test
3131
fun `use nested object functions`() {
32-
val testBucket = UnaliasedBucket(BUCKET).withScope(BucketScope("_default", BucketCollection("_default")))
32+
val testBucket = UnaliasedBucket(BUCKET).withScope(BucketScope("_default", ScopeCollection("_default")))
3333
val detailsField = Field<ObjectType>(detailsField.name, testBucket)
3434
val dopeQuery = QueryBuilder
3535
.selectRaw(

couchbase/src/integrationTest/kotlin/ch/ergon/dope/integrationTest/TestCouchbaseDatabase.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import ch.ergon.dope.QueryBuilder
44
import ch.ergon.dope.couchbase.resolver.CouchbaseResolver
55
import ch.ergon.dope.integrationTest.TestCouchbaseDatabase.testBucket
66
import ch.ergon.dope.resolvable.bucket.Bucket
7-
import ch.ergon.dope.resolvable.bucket.BucketCollection
87
import ch.ergon.dope.resolvable.bucket.BucketScope
8+
import ch.ergon.dope.resolvable.bucket.ScopeCollection
99
import ch.ergon.dope.resolvable.bucket.UnaliasedBucket
1010
import ch.ergon.dope.resolvable.expression.rowscope.aggregate.countAsterisk
1111
import ch.ergon.dope.resolvable.expression.type.Field
@@ -35,7 +35,7 @@ object TestCouchbaseDatabase {
3535
)
3636
val cluster: Cluster
3737
val testBucket = UnaliasedBucket(BUCKET)
38-
val testAppOrderAuditBucket = UnaliasedBucket(BUCKET, BucketScope("app", BucketCollection("order_audit")))
38+
val testAppOrderAuditBucket = UnaliasedBucket(BUCKET, BucketScope("app", ScopeCollection("order_audit")))
3939
val idField = Field<NumberType>("id", testBucket)
4040
val typeField = Field<StringType>("type", testBucket)
4141
val nameField = Field<StringType>("name", testBucket)

couchbase/src/test/kotlin/ch/ergon/dope/helper/Builder.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package ch.ergon.dope.helper
22

33
import ch.ergon.dope.resolvable.bucket.Bucket
4-
import ch.ergon.dope.resolvable.bucket.BucketCollection
54
import ch.ergon.dope.resolvable.bucket.BucketScope
5+
import ch.ergon.dope.resolvable.bucket.ScopeCollection
66
import ch.ergon.dope.resolvable.bucket.UnaliasedBucket
77
import ch.ergon.dope.resolvable.clause.model.OrderExpression
88
import ch.ergon.dope.resolvable.clause.model.OrderType
@@ -30,7 +30,7 @@ import ch.ergon.dope.validtype.StringType
3030
import ch.ergon.dope.validtype.ValidType
3131

3232
fun someBucket(bucket: String = "someBucket", scope: String? = null, collection: String? = null) =
33-
UnaliasedBucket(bucket, scope?.let { BucketScope(it, collection?.let { BucketCollection(it) }) })
33+
UnaliasedBucket(bucket, scope?.let { BucketScope(it, collection?.let { ScopeCollection(it) }) })
3434

3535
fun someNumberField(name: String = "numberField", bucket: Bucket? = null) = Field<NumberType>(name, bucket)
3636

couchbase/src/test/kotlin/ch/ergon/dope/resolvable/bucket/BucketTest.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class BucketTest : ResolverDependentTest {
3838
val expected = CouchbaseDopeQuery(
3939
queryString = "`bucket`.`scope`.`collection`",
4040
)
41-
val underTest = UnaliasedBucket("bucket", BucketScope("scope", BucketCollection("collection")))
41+
val underTest = UnaliasedBucket("bucket", BucketScope("scope", ScopeCollection("collection")))
4242

4343
val actual = underTest.toDopeQuery(resolver)
4444

@@ -92,4 +92,16 @@ class BucketTest : ResolverDependentTest {
9292

9393
assertEquals(expected, actual)
9494
}
95+
96+
@Test
97+
fun `should support scope collection bucket function`() {
98+
val expected = CouchbaseDopeQuery(
99+
queryString = "`bucket`.`scope`.`collection`",
100+
)
101+
val underTest = UnaliasedBucket("bucket", BucketScope("scope").withCollection(ScopeCollection("collection")))
102+
103+
val actual = underTest.toDopeQuery(resolver)
104+
105+
assertEquals(expected, actual)
106+
}
95107
}

crystal-map-connector/src/main/kotlin/ch/ergon/dope/CrystalMapAdapter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package ch.ergon.dope
22

33
import ch.ergon.dope.extension.expression.type.ObjectField
44
import ch.ergon.dope.extension.expression.type.ObjectList
5-
import ch.ergon.dope.resolvable.bucket.BucketCollection
65
import ch.ergon.dope.resolvable.bucket.BucketScope
6+
import ch.ergon.dope.resolvable.bucket.ScopeCollection
77
import ch.ergon.dope.resolvable.bucket.UnaliasedBucket
88
import ch.ergon.dope.resolvable.expression.type.Field
99
import ch.ergon.dope.resolvable.expression.type.TypeExpression
@@ -134,7 +134,7 @@ private fun bucketFrom(path: String?): UnaliasedBucket? {
134134
return when (parts.size) {
135135
1 -> UnaliasedBucket(parts[0])
136136
2 -> UnaliasedBucket(parts[0], BucketScope(parts[1]))
137-
3 -> UnaliasedBucket(parts[0], BucketScope(parts[1], BucketCollection(parts[2])))
137+
3 -> UnaliasedBucket(parts[0], BucketScope(parts[1], ScopeCollection(parts[2])))
138138
else -> null
139139
}
140140
}

0 commit comments

Comments
 (0)