Skip to content

Commit d444f8b

Browse files
committed
test convenience getters
1 parent 483dd00 commit d444f8b

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

core/src/test/scala/sample/AsyncLover.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ object AsyncLover extends SQLSyntaxSupport[AsyncLover] {
2222
def apply(c: SyntaxProvider[AsyncLover])(rs: WrappedResultSet): AsyncLover = apply(c.resultName)(rs)
2323

2424
def apply(c: ResultName[AsyncLover])(rs: WrappedResultSet): AsyncLover = new AsyncLover(
25-
id = rs.long(c.id),
26-
//name = rs.string(c.name),
25+
id = rs.get[Long](c.id),
2726
name = rs.get[Option[String]](c.name).get,
2827
rating = rs.get[Int](c.rating),
2928
isReactive = rs.get[Boolean](c.isReactive),

core/src/test/scala/sample/MySQLSampleSpec.scala

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,37 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
5353
results.size should equal(2)
5454
}
5555

56+
it should "read values with convenience methods" in {
57+
val generatedIdFuture: Future[Long] = AsyncDB.withPool { implicit s =>
58+
withSQL {
59+
insert.into(AsyncLover).namedValues(
60+
column.name -> "Eric",
61+
column.rating -> 2,
62+
column.isReactive -> false,
63+
column.createdAt -> createdTime).returningId
64+
}.updateAndReturnGeneratedKey.future()
65+
}
66+
// in AsyncLover#apply we are using get with typebinders, specialized getters should work
67+
val generatedId = Await.result(generatedIdFuture, 5.seconds)
68+
val created = DB.readOnly { implicit s =>
69+
withSQL { select.from(AsyncLover as al).where.eq(al.id, generatedId) }.map((rs: WrappedResultSet) => {
70+
AsyncLover(
71+
id = rs.long(al.resultName.id),
72+
name = rs.stringOpt(al.resultName.name).get,
73+
rating = rs.int(al.resultName.rating),
74+
isReactive = rs.boolean(al.resultName.isReactive),
75+
lunchtime = rs.timeOpt(al.resultName.lunchtime),
76+
birthday = rs.jodaDateTimeOpt(al.resultName.lunchtime),
77+
createdAt = rs.jodaDateTime(al.resultName.createdAt))
78+
}).single.apply()
79+
}.get
80+
created.id should equal(generatedId)
81+
created.name should equal("Eric")
82+
created.rating should equal(2)
83+
created.isReactive should be(false)
84+
created.createdAt should equal(createdTime)
85+
}
86+
5687
it should "return generated key" in {
5788
val generatedIdFuture: Future[Long] = NamedAsyncDB('mysql).withPool { implicit s =>
5889
withSQL {

core/src/test/scala/sample/PostgreSQLSampleSpec.scala

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,37 @@ class PostgreSQLSampleSpec extends FlatSpec with Matchers with DBSettings with L
4646
results.size should equal(2)
4747
}
4848

49+
it should "read values with convenience methods" in {
50+
val generatedIdFuture: Future[Long] = AsyncDB.withPool { implicit s =>
51+
withSQL {
52+
insert.into(AsyncLover).namedValues(
53+
column.name -> "Eric",
54+
column.rating -> 2,
55+
column.isReactive -> false,
56+
column.createdAt -> createdTime).returningId
57+
}.updateAndReturnGeneratedKey.future()
58+
}
59+
// in AsyncLover#apply we are using get with typebinders, specialized getters should work
60+
val generatedId = Await.result(generatedIdFuture, 5.seconds)
61+
val created = DB.readOnly { implicit s =>
62+
withSQL { select.from(AsyncLover as al).where.eq(al.id, generatedId) }.map((rs: WrappedResultSet) => {
63+
AsyncLover(
64+
id = rs.long(al.resultName.id),
65+
name = rs.stringOpt(al.resultName.name).get,
66+
rating = rs.int(al.resultName.rating),
67+
isReactive = rs.boolean(al.resultName.isReactive),
68+
lunchtime = rs.timeOpt(al.resultName.lunchtime),
69+
birthday = rs.jodaDateTimeOpt(al.resultName.lunchtime),
70+
createdAt = rs.jodaDateTime(al.resultName.createdAt))
71+
}).single.apply()
72+
}.get
73+
created.id should equal(generatedId)
74+
created.name should equal("Eric")
75+
created.rating should equal(2)
76+
created.isReactive should be(false)
77+
created.createdAt should equal(createdTime)
78+
}
79+
4980
it should "return generated key" in {
5081
val generatedIdFuture: Future[Long] = AsyncDB.withPool { implicit s =>
5182
withSQL {

0 commit comments

Comments
 (0)