@@ -15,7 +15,7 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
15
15
val al = AsyncLover .syntax(" al" )
16
16
17
17
it should " select a single value" in {
18
- val id = NamedDB (' mysql ).autoCommit { implicit s =>
18
+ val id = NamedDB (" mysql" ).autoCommit { implicit s =>
19
19
withSQL {
20
20
insert.into(AsyncLover ).namedValues(
21
21
column.name -> " Eric" ,
@@ -24,15 +24,15 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
24
24
column.createdAt -> createdTime)
25
25
}.updateAndReturnGeneratedKey.apply()
26
26
}
27
- val resultFuture : Future [Option [AsyncLover ]] = NamedAsyncDB (' mysql ).withPool { implicit s =>
27
+ val resultFuture : Future [Option [AsyncLover ]] = NamedAsyncDB (" mysql" ).withPool { implicit s =>
28
28
withSQL { select.from(AsyncLover as al ).where.eq(al.id, id) }.map(AsyncLover (al)).single.future()
29
29
}
30
30
val result = Await .result(resultFuture, 5 .seconds)
31
31
result.isDefined should be(true )
32
32
}
33
33
34
34
it should " select values as a Iterable" in {
35
- val resultsFuture : Future [Iterable [AsyncLover ]] = NamedAsyncDB (' mysql ).withPool { implicit s =>
35
+ val resultsFuture : Future [Iterable [AsyncLover ]] = NamedAsyncDB (" mysql" ).withPool { implicit s =>
36
36
withSQL {
37
37
select.from(AsyncLover as al )
38
38
.where.isNotNull(al.birthday) // mysql-async 0.2.4 cannot parse nullable date value.
@@ -44,7 +44,7 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
44
44
}
45
45
46
46
it should " select values as a List" in {
47
- val resultsFuture : Future [List [AsyncLover ]] = NamedAsyncDB (' mysql ).withPool { implicit s =>
47
+ val resultsFuture : Future [List [AsyncLover ]] = NamedAsyncDB (" mysql" ).withPool { implicit s =>
48
48
withSQL {
49
49
select.from(AsyncLover as al )
50
50
.where.isNotNull(al.birthday) // mysql-async 0.2.4 cannot parse nullable date value.
@@ -56,7 +56,7 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
56
56
}
57
57
58
58
it should " read values with convenience methods" in {
59
- val generatedIdFuture : Future [Long ] = NamedAsyncDB (' mysql ).withPool { implicit s =>
59
+ val generatedIdFuture : Future [Long ] = NamedAsyncDB (" mysql" ).withPool { implicit s =>
60
60
withSQL {
61
61
insert.into(AsyncLover ).namedValues(
62
62
column.name -> " Eric" ,
@@ -67,7 +67,7 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
67
67
}
68
68
// in AsyncLover#apply we are using get with typebinders, specialized getters should work
69
69
val generatedId = Await .result(generatedIdFuture, 5 .seconds)
70
- val created = NamedDB (' mysql ).readOnly { implicit s =>
70
+ val created = NamedDB (" mysql" ).readOnly { implicit s =>
71
71
withSQL { select.from(AsyncLover as al ).where.eq(al.id, generatedId) }.map((rs : WrappedResultSet ) => {
72
72
AsyncLover (
73
73
id = rs.get[Long ](al.resultName.id),
@@ -87,7 +87,7 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
87
87
}
88
88
89
89
it should " return generated key" in {
90
- val generatedIdFuture : Future [Long ] = NamedAsyncDB (' mysql ).withPool { implicit s =>
90
+ val generatedIdFuture : Future [Long ] = NamedAsyncDB (" mysql" ).withPool { implicit s =>
91
91
withSQL {
92
92
insert.into(AsyncLover ).namedValues(
93
93
column.name -> " Eric" ,
@@ -99,7 +99,7 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
99
99
}
100
100
// the generated key should be found
101
101
val generatedId = Await .result(generatedIdFuture, 5 .seconds)
102
- val created = NamedDB (' mysql ).readOnly { implicit s =>
102
+ val created = NamedDB (" mysql" ).readOnly { implicit s =>
103
103
withSQL { select.from(AsyncLover as al ).where.eq(al.id, generatedId) }.map(AsyncLover (al)).single.apply()
104
104
}.get
105
105
created.id should equal(generatedId)
@@ -111,7 +111,7 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
111
111
112
112
it should " update" in {
113
113
// updating queries should be successful
114
- NamedDB (' mysql ) autoCommit { implicit s =>
114
+ NamedDB (" mysql" ) autoCommit { implicit s =>
115
115
withSQL { delete.from(AsyncLover ).where.eq(column.id, 1004 ) }.update.apply()
116
116
withSQL {
117
117
insert.into(AsyncLover ).namedValues(
@@ -122,21 +122,21 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
122
122
column.createdAt -> createdTime)
123
123
}.update.apply()
124
124
}
125
- val deletion : Future [Int ] = NamedAsyncDB (' mysql ).withPool { implicit s =>
125
+ val deletion : Future [Int ] = NamedAsyncDB (" mysql" ).withPool { implicit s =>
126
126
withSQL { delete.from(AsyncLover ).where.eq(column.id, 1004 ) }.update.future()
127
127
}
128
128
Await .result(deletion, 5 .seconds)
129
129
130
130
// should be committed
131
- val deleted = NamedDB (' mysql ).readOnly { implicit s =>
131
+ val deleted = NamedDB (" mysql" ).readOnly { implicit s =>
132
132
withSQL { select.from(AsyncLover as al ).where.eq(al.id, 1004 ) }.map(AsyncLover (al)).single.apply()
133
133
}
134
134
deleted.isDefined should be(false )
135
135
}
136
136
137
137
it should " execute" in {
138
138
// execution should be successful
139
- val id = NamedDB (' mysql ).autoCommit { implicit s =>
139
+ val id = NamedDB (" mysql" ).autoCommit { implicit s =>
140
140
withSQL {
141
141
insert.into(AsyncLover ).namedValues(
142
142
column.name -> " Chris" ,
@@ -145,13 +145,13 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
145
145
column.createdAt -> createdTime)
146
146
}.updateAndReturnGeneratedKey.apply()
147
147
}
148
- val deletion : Future [Boolean ] = NamedAsyncDB (' mysql ).withPool { implicit s =>
148
+ val deletion : Future [Boolean ] = NamedAsyncDB (" mysql" ).withPool { implicit s =>
149
149
withSQL { delete.from(AsyncLover ).where.eq(column.id, id) }.execute.future()
150
150
}
151
151
Await .result(deletion, 5 .seconds)
152
152
153
153
// should be committed
154
- val deleted = NamedDB (' mysql ).readOnly { implicit s =>
154
+ val deleted = NamedDB (" mysql" ).readOnly { implicit s =>
155
155
withSQL { select.from(AsyncLover as al ).where.eq(al.id, id) }.map(AsyncLover (al)).single.apply()
156
156
}
157
157
deleted.isDefined should be(false )
@@ -160,7 +160,7 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
160
160
it should " update in a local transaction" in {
161
161
(1 to 10 ).foreach { _ =>
162
162
163
- val generatedIdFuture : Future [Long ] = NamedAsyncDB (' mysql ).localTx { implicit tx =>
163
+ val generatedIdFuture : Future [Long ] = NamedAsyncDB (" mysql" ).localTx { implicit tx =>
164
164
withSQL(insert.into(AsyncLover ).namedValues(
165
165
column.name -> " Patric" ,
166
166
column.rating -> 2 ,
@@ -169,7 +169,7 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
169
169
).updateAndReturnGeneratedKey.future
170
170
}
171
171
val generatedId = Await .result(generatedIdFuture, 5 .seconds)
172
- val created = NamedDB (' mysql ).readOnly { implicit s =>
172
+ val created = NamedDB (" mysql" ).readOnly { implicit s =>
173
173
withSQL { select.from(AsyncLover as al ).where.eq(al.id, generatedId) }.map(AsyncLover (al)).single.apply()
174
174
}.get
175
175
created.id should equal(generatedId)
@@ -183,10 +183,10 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
183
183
it should " rollback in a local transaction" in {
184
184
(1 to 10 ).foreach { _ =>
185
185
186
- NamedDB (' mysql ).autoCommit { implicit s =>
186
+ NamedDB (" mysql" ).autoCommit { implicit s =>
187
187
withSQL { delete.from(AsyncLover ).where.eq(column.id, 1003 ) }.update.apply()
188
188
}
189
- val failureFuture : Future [Unit ] = NamedAsyncDB (' mysql ).localTx { implicit tx =>
189
+ val failureFuture : Future [Unit ] = NamedAsyncDB (" mysql" ).localTx { implicit tx =>
190
190
import FutureImplicits ._
191
191
for {
192
192
_ <- insert.into(AsyncLover ).namedValues(
@@ -208,7 +208,7 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
208
208
failureFuture.value.get.isFailure should be(true )
209
209
210
210
// should be rolled back
211
- val notCreated = NamedDB (' mysql ).readOnly { implicit s =>
211
+ val notCreated = NamedDB (" mysql" ).readOnly { implicit s =>
212
212
withSQL { select.from(AsyncLover as al ).where.eq(al.id, 1003 ) }.map(AsyncLover (al)).single.apply()
213
213
}
214
214
notCreated.isDefined should be(false )
@@ -218,7 +218,7 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
218
218
it should " provide transaction by AsyncTx.withSQLBuilders" in {
219
219
(1 to 10 ).foreach { _ =>
220
220
221
- val deletionAndCreation : Future [Seq [AsyncQueryResult ]] = NamedAsyncDB (' mysql ).withPool { implicit s =>
221
+ val deletionAndCreation : Future [Seq [AsyncQueryResult ]] = NamedAsyncDB (" mysql" ).withPool { implicit s =>
222
222
AsyncTx .withSQLBuilders(
223
223
delete.from(AsyncLover ).where.eq(column.id, 997 ),
224
224
insert.into(AsyncLover ).namedValues(
@@ -233,7 +233,7 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
233
233
deletionAndCreation.value.get.get.size should be(2 )
234
234
235
235
// should be found
236
- val created = NamedDB (' mysql ).readOnly { implicit s =>
236
+ val created = NamedDB (" mysql" ).readOnly { implicit s =>
237
237
withSQL { select.from(AsyncLover as al ).where.eq(al.id, 997 ) }.map(AsyncLover (al)).single.apply()
238
238
}.get
239
239
created.id should equal(997 )
@@ -247,10 +247,10 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
247
247
it should " provide transactional deletion by AsyncTx.withSQLBuilders" in {
248
248
(1 to 10 ).foreach { _ =>
249
249
250
- NamedDB (' mysql ).autoCommit { implicit s =>
250
+ NamedDB (" mysql" ).autoCommit { implicit s =>
251
251
withSQL { delete.from(AsyncLover ).where.eq(column.id, 998 ) }.update.apply()
252
252
}
253
- val creationAndDeletion : Future [Seq [AsyncQueryResult ]] = NamedAsyncDB (' mysql ).withPool { implicit s =>
253
+ val creationAndDeletion : Future [Seq [AsyncQueryResult ]] = NamedAsyncDB (" mysql" ).withPool { implicit s =>
254
254
AsyncTx .withSQLBuilders(
255
255
insert.into(AsyncLover ).namedValues(
256
256
column.id -> 998 ,
@@ -265,7 +265,7 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
265
265
creationAndDeletion.value.get.get.size should be(2 )
266
266
267
267
// should be committed
268
- val deleted = NamedDB (' mysql ).readOnly { implicit s =>
268
+ val deleted = NamedDB (" mysql" ).readOnly { implicit s =>
269
269
withSQL { select.from(AsyncLover as al ).where.eq(al.id, 998 ) }.map(AsyncLover (al)).single.apply()
270
270
}
271
271
deleted.isDefined should be(false )
@@ -275,7 +275,7 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
275
275
it should " rollback in a transaction when using AsyncTx.withSQLs" in {
276
276
(1 to 10 ).foreach { _ =>
277
277
278
- val failure : Future [Seq [AsyncQueryResult ]] = NamedAsyncDB (' mysql ).withPool { implicit s =>
278
+ val failure : Future [Seq [AsyncQueryResult ]] = NamedAsyncDB (" mysql" ).withPool { implicit s =>
279
279
AsyncTx .withSQLs(
280
280
insert.into(AsyncLover ).namedValues(
281
281
column.id -> 999 ,
@@ -294,7 +294,7 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
294
294
}
295
295
failure.value.get.isSuccess should be(false )
296
296
297
- val notFound = NamedDB (' mysql ).readOnly { implicit s =>
297
+ val notFound = NamedDB (" mysql" ).readOnly { implicit s =>
298
298
withSQL { select.from(AsyncLover as al ).where.eq(al.id, 999 ) }.map(AsyncLover (al)).single.apply()
299
299
}
300
300
notFound.isDefined should be(false )
0 commit comments