-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDeleteBuilderSpec.scala
94 lines (75 loc) · 2.35 KB
/
DeleteBuilderSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package spinoco.fs2.cassandra.builder
import spinoco.fs2.cassandra.{Comparison, KeySpace}
import spinoco.fs2.cassandra.sample.{OptionalTableRow, SimpleTableRow}
import spinoco.fs2.cassandra.support.Fs2CassandraSpec
/**
* Created by pach on 11/06/16.
*/
class DeleteBuilderSpec extends Fs2CassandraSpec {
val ks = new KeySpace("test_ks")
"DELETE statement" - {
val simpleTable =
ks.table[SimpleTableRow]
.partition('intColumn)
.cluster('longColumn)
.build("test_table")
val optionalTable =
ks.table[OptionalTableRow]
.partition('intColumn)
.cluster('longColumn)
.build("optional_table")
"will delete whole row" in {
simpleTable.delete
.row
.build.cqlStatement shouldBe
"DELETE FROM test_ks.test_table" +
" WHERE intColumn = :intColumn "
}
"will delete cluster from the row" in {
simpleTable.delete
.row
.cluster('longColumn)
.build.cqlStatement shouldBe
"DELETE FROM test_ks.test_table" +
" WHERE intColumn = :intColumn AND longColumn = :longColumn "
}
"will delete single column from the row" in {
optionalTable.delete
.column('stringColumn)
.primary
.build.cqlStatement shouldBe
"DELETE stringColumn FROM test_ks.optional_table" +
" WHERE intColumn = :intColumn AND longColumn = :longColumn "
}
"will delete if exists" in {
simpleTable.delete
.row
.onlyIfExists
.build.cqlStatement shouldBe
"DELETE FROM test_ks.test_table " +
"WHERE intColumn = :intColumn IF EXISTS"
}
"will delete if cond" in {
simpleTable.delete
.row
.primary
.onlyIf('stringColumn, "as_string", Comparison.EQ)
.build.cqlStatement shouldBe
"DELETE FROM test_ks.test_table" +
" WHERE intColumn = :intColumn AND longColumn = :longColumn" +
" IF stringColumn = :as_string"
}
"will fill cqlFor" in {
simpleTable.delete
.row
.primary
.onlyIf('stringColumn, "as_string", Comparison.EQ)
.build
.fromHList
.fromTuple[(String, Int, Long)].cqlFor(("Hello", 1, 2l)) shouldBe
"DELETE FROM test_ks.test_table" +
" WHERE intColumn = 1 AND longColumn = 2" +
" IF stringColumn = 'Hello'"
}
}
}