Skip to content

Commit 272dc38

Browse files
authored
Merge pull request #69 from xuwei-k/Iterable
prepare Scala 2.13
2 parents c7cd0c4 + df88a6b commit 272dc38

File tree

9 files changed

+395
-189
lines changed

9 files changed

+395
-189
lines changed

core/src/main/scala/scalikejdbc/async/AsyncDBSession.scala

Lines changed: 251 additions & 79 deletions
Large diffs are not rendered by default.

core/src/main/scala/scalikejdbc/async/AsyncRelationalSQLs.scala

Lines changed: 72 additions & 72 deletions
Large diffs are not rendered by default.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2013 Kazuhiro Sera
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13+
* either express or implied. See the License for the specific language
14+
* governing permissions and limitations under the License.
15+
*/
16+
package scalikejdbc.async
17+
18+
import scalikejdbc._
19+
20+
/**
21+
* AsyncResultSet Iterator
22+
*/
23+
class AsyncResultSetIterator(var rs: AsyncResultSet) extends Iterator[WrappedResultSet] {
24+
25+
override def hasNext: Boolean = rs.next()
26+
27+
override def next: WrappedResultSet = {
28+
val value = rs
29+
rs = rs.tail()
30+
value
31+
}
32+
33+
}

core/src/main/scala/scalikejdbc/async/AsyncResultSetTraversable.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import scalikejdbc._
2020
/**
2121
* AsyncResultSet Traversable
2222
*/
23+
@deprecated("will be removed. use AsyncResultSetIterator", "0.12.0")
2324
class AsyncResultSetTraversable(var rs: AsyncResultSet) extends Traversable[WrappedResultSet] {
2425

2526
def foreach[U](f: (WrappedResultSet) => U): Unit = while (rs.next()) {

core/src/main/scala/scalikejdbc/async/AsyncSQLs.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ trait AsyncSQLToOption[A] extends Any {
5353
}
5454
class AsyncSQLToOptionImpl[A](val underlying: SQLToOption[A, HasExtractor]) extends AnyVal with AsyncSQLToOption[A]
5555

56-
trait AsyncSQLToTraversable[A] extends Any {
57-
def underlying: SQLToTraversable[A, HasExtractor]
58-
def future()(implicit session: AsyncDBSession, cxt: EC = ECGlobal): Future[Traversable[A]] = {
59-
session.traversable(underlying.statement, underlying.rawParameters: _*)(underlying.extractor)
56+
trait AsyncSQLToIterable[A] extends Any {
57+
def underlying: SQLToIterable[A, HasExtractor]
58+
def future()(implicit session: AsyncDBSession, cxt: EC = ECGlobal): Future[Iterable[A]] = {
59+
session.iterable(underlying.statement, underlying.rawParameters: _*)(underlying.extractor)
6060
}
6161
}
62-
class AsyncSQLToTraversableImpl[A](val underlying: SQLToTraversable[A, HasExtractor]) extends AnyVal with AsyncSQLToTraversable[A]
62+
class AsyncSQLToIterableImpl[A](val underlying: SQLToIterable[A, HasExtractor]) extends AnyVal with AsyncSQLToIterable[A]
6363

6464
trait AsyncSQLToList[A] extends Any {
6565
def underlying: SQLToList[A, HasExtractor]

core/src/main/scala/scalikejdbc/async/FutureImplicits.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import scalikejdbc.async.ShortenedNames._
2222
*/
2323
object FutureImplicits {
2424

25-
implicit def fromSQLToTraversableFuture[A](sql: SQL[A, HasExtractor])(
25+
implicit def fromSQLToIterableFuture[A](sql: SQL[A, HasExtractor])(
2626
implicit
27-
session: AsyncDBSession, cxt: EC = EC.Implicits.global): Future[Traversable[A]] = sql.traversable.future
27+
session: AsyncDBSession, cxt: EC = EC.Implicits.global): Future[Iterable[A]] = sql.iterable.future
2828

2929
implicit def fromSQLToListFuture[A](sql: SQL[A, HasExtractor])(
3030
implicit

core/src/main/scala/scalikejdbc/async/package.scala

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,44 +70,44 @@ package object async {
7070
}
7171

7272
// --------------
73-
// one-to-x -> Traversable
73+
// one-to-x -> Iterable
7474
// --------------
7575

76-
implicit def makeSQLToTraversableAsync[A, B1, B2, B3, B4, B5, Z](sql: SQLToTraversable[A, HasExtractor]): AsyncSQLToTraversable[A] = {
77-
new AsyncSQLToTraversableImpl[A](sql)
76+
implicit def makeSQLToIterableAsync[A, B1, B2, B3, B4, B5, Z](sql: SQLToIterable[A, HasExtractor]): AsyncSQLToIterable[A] = {
77+
new AsyncSQLToIterableImpl[A](sql)
7878
}
79-
implicit def makeSQLToTraversableAsync[A, B1, B2, B3, B4, B5, Z](sql: SQLToTraversableImpl[A, HasExtractor]): AsyncSQLToTraversable[A] = {
80-
new AsyncSQLToTraversableImpl[A](sql)
79+
implicit def makeSQLToIterableAsync[A, B1, B2, B3, B4, B5, Z](sql: SQLToIterableImpl[A, HasExtractor]): AsyncSQLToIterable[A] = {
80+
new AsyncSQLToIterableImpl[A](sql)
8181
}
82-
implicit def makeOneToOneSQLToTraversableAsync[A, B, Z](sql: OneToOneSQLToTraversable[A, B, HasExtractor, Z]): AsyncOneToOneSQLToTraversable[A, B, Z] = {
83-
new AsyncOneToOneSQLToTraversable[A, B, Z](sql)
82+
implicit def makeOneToOneSQLToIterableAsync[A, B, Z](sql: OneToOneSQLToIterable[A, B, HasExtractor, Z]): AsyncOneToOneSQLToIterable[A, B, Z] = {
83+
new AsyncOneToOneSQLToIterable[A, B, Z](sql)
8484
}
85-
implicit def makeOneToManySQLToTraversableAsync[A, B, Z](sql: OneToManySQLToTraversable[A, B, HasExtractor, Z]): AsyncOneToManySQLToTraversable[A, B, Z] = {
86-
new AsyncOneToManySQLToTraversable[A, B, Z](sql)
85+
implicit def makeOneToManySQLToIterableAsync[A, B, Z](sql: OneToManySQLToIterable[A, B, HasExtractor, Z]): AsyncOneToManySQLToIterable[A, B, Z] = {
86+
new AsyncOneToManySQLToIterable[A, B, Z](sql)
8787
}
88-
implicit def makeOneToManies2SQLToTraversableAsync[A, B1, B2, Z](sql: OneToManies2SQLToTraversable[A, B1, B2, HasExtractor, Z]): AsyncOneToManies2SQLToTraversable[A, B1, B2, Z] = {
89-
new AsyncOneToManies2SQLToTraversable[A, B1, B2, Z](sql)
88+
implicit def makeOneToManies2SQLToIterableAsync[A, B1, B2, Z](sql: OneToManies2SQLToIterable[A, B1, B2, HasExtractor, Z]): AsyncOneToManies2SQLToIterable[A, B1, B2, Z] = {
89+
new AsyncOneToManies2SQLToIterable[A, B1, B2, Z](sql)
9090
}
91-
implicit def makeOneToManies3SQLToTraversableAsync[A, B1, B2, B3, Z](sql: OneToManies3SQLToTraversable[A, B1, B2, B3, HasExtractor, Z]): AsyncOneToManies3SQLToTraversable[A, B1, B2, B3, Z] = {
92-
new AsyncOneToManies3SQLToTraversable[A, B1, B2, B3, Z](sql)
91+
implicit def makeOneToManies3SQLToIterableAsync[A, B1, B2, B3, Z](sql: OneToManies3SQLToIterable[A, B1, B2, B3, HasExtractor, Z]): AsyncOneToManies3SQLToIterable[A, B1, B2, B3, Z] = {
92+
new AsyncOneToManies3SQLToIterable[A, B1, B2, B3, Z](sql)
9393
}
94-
implicit def makeOneToManies4SQLToTraversableAsync[A, B1, B2, B3, B4, Z](sql: OneToManies4SQLToTraversable[A, B1, B2, B3, B4, HasExtractor, Z]): AsyncOneToManies4SQLToTraversable[A, B1, B2, B3, B4, Z] = {
95-
new AsyncOneToManies4SQLToTraversable[A, B1, B2, B3, B4, Z](sql)
94+
implicit def makeOneToManies4SQLToIterableAsync[A, B1, B2, B3, B4, Z](sql: OneToManies4SQLToIterable[A, B1, B2, B3, B4, HasExtractor, Z]): AsyncOneToManies4SQLToIterable[A, B1, B2, B3, B4, Z] = {
95+
new AsyncOneToManies4SQLToIterable[A, B1, B2, B3, B4, Z](sql)
9696
}
97-
implicit def makeOneToManies5SQLToTraversableAsync[A, B1, B2, B3, B4, B5, Z](sql: OneToManies5SQLToTraversable[A, B1, B2, B3, B4, B5, HasExtractor, Z]): AsyncOneToManies5SQLToTraversable[A, B1, B2, B3, B4, B5, Z] = {
98-
new AsyncOneToManies5SQLToTraversable[A, B1, B2, B3, B4, B5, Z](sql)
97+
implicit def makeOneToManies5SQLToIterableAsync[A, B1, B2, B3, B4, B5, Z](sql: OneToManies5SQLToIterable[A, B1, B2, B3, B4, B5, HasExtractor, Z]): AsyncOneToManies5SQLToIterable[A, B1, B2, B3, B4, B5, Z] = {
98+
new AsyncOneToManies5SQLToIterable[A, B1, B2, B3, B4, B5, Z](sql)
9999
}
100-
implicit def makeOneToManies6SQLToTraversableAsync[A, B1, B2, B3, B4, B5, B6, Z](sql: OneToManies6SQLToTraversable[A, B1, B2, B3, B4, B5, B6, HasExtractor, Z]): AsyncOneToManies6SQLToTraversable[A, B1, B2, B3, B4, B5, B6, Z] = {
101-
new AsyncOneToManies6SQLToTraversable[A, B1, B2, B3, B4, B5, B6, Z](sql)
100+
implicit def makeOneToManies6SQLToIterableAsync[A, B1, B2, B3, B4, B5, B6, Z](sql: OneToManies6SQLToIterable[A, B1, B2, B3, B4, B5, B6, HasExtractor, Z]): AsyncOneToManies6SQLToIterable[A, B1, B2, B3, B4, B5, B6, Z] = {
101+
new AsyncOneToManies6SQLToIterable[A, B1, B2, B3, B4, B5, B6, Z](sql)
102102
}
103-
implicit def makeOneToManies7SQLToTraversableAsync[A, B1, B2, B3, B4, B5, B6, B7, Z](sql: OneToManies7SQLToTraversable[A, B1, B2, B3, B4, B5, B6, B7, HasExtractor, Z]): AsyncOneToManies7SQLToTraversable[A, B1, B2, B3, B4, B5, B6, B7, Z] = {
104-
new AsyncOneToManies7SQLToTraversable[A, B1, B2, B3, B4, B5, B6, B7, Z](sql)
103+
implicit def makeOneToManies7SQLToIterableAsync[A, B1, B2, B3, B4, B5, B6, B7, Z](sql: OneToManies7SQLToIterable[A, B1, B2, B3, B4, B5, B6, B7, HasExtractor, Z]): AsyncOneToManies7SQLToIterable[A, B1, B2, B3, B4, B5, B6, B7, Z] = {
104+
new AsyncOneToManies7SQLToIterable[A, B1, B2, B3, B4, B5, B6, B7, Z](sql)
105105
}
106-
implicit def makeOneToManies8SQLToTraversableAsync[A, B1, B2, B3, B4, B5, B6, B7, B8, Z](sql: OneToManies8SQLToTraversable[A, B1, B2, B3, B4, B5, B6, B7, B8, HasExtractor, Z]): AsyncOneToManies8SQLToTraversable[A, B1, B2, B3, B4, B5, B6, B7, B8, Z] = {
107-
new AsyncOneToManies8SQLToTraversable[A, B1, B2, B3, B4, B5, B6, B7, B8, Z](sql)
106+
implicit def makeOneToManies8SQLToIterableAsync[A, B1, B2, B3, B4, B5, B6, B7, B8, Z](sql: OneToManies8SQLToIterable[A, B1, B2, B3, B4, B5, B6, B7, B8, HasExtractor, Z]): AsyncOneToManies8SQLToIterable[A, B1, B2, B3, B4, B5, B6, B7, B8, Z] = {
107+
new AsyncOneToManies8SQLToIterable[A, B1, B2, B3, B4, B5, B6, B7, B8, Z](sql)
108108
}
109-
implicit def makeOneToManies9SQLToTraversableAsync[A, B1, B2, B3, B4, B5, B6, B7, B8, B9, Z](sql: OneToManies9SQLToTraversable[A, B1, B2, B3, B4, B5, B6, B7, B8, B9, HasExtractor, Z]): AsyncOneToManies9SQLToTraversable[A, B1, B2, B3, B4, B5, B6, B7, B8, B9, Z] = {
110-
new AsyncOneToManies9SQLToTraversable[A, B1, B2, B3, B4, B5, B6, B7, B8, B9, Z](sql)
109+
implicit def makeOneToManies9SQLToIterableAsync[A, B1, B2, B3, B4, B5, B6, B7, B8, B9, Z](sql: OneToManies9SQLToIterable[A, B1, B2, B3, B4, B5, B6, B7, B8, B9, HasExtractor, Z]): AsyncOneToManies9SQLToIterable[A, B1, B2, B3, B4, B5, B6, B7, B8, B9, Z] = {
110+
new AsyncOneToManies9SQLToIterable[A, B1, B2, B3, B4, B5, B6, B7, B8, B9, Z](sql)
111111
}
112112

113113
// --------------

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
3131
result.isDefined should be(true)
3232
}
3333

34-
it should "select values as a Traversable" in {
35-
val resultsFuture: Future[Traversable[AsyncLover]] = NamedAsyncDB('mysql).withPool { implicit s =>
34+
it should "select values as a Iterable" in {
35+
val resultsFuture: Future[Iterable[AsyncLover]] = NamedAsyncDB('mysql).withPool { implicit s =>
3636
withSQL {
3737
select.from(AsyncLover as al)
3838
.where.isNotNull(al.birthday) // mysql-async 0.2.4 cannot parse nullable date value.
3939
.limit(2)
40-
}.map(AsyncLover(al)).traversable.future()
40+
}.map(AsyncLover(al)).iterable.future()
4141
}
4242
val results = Await.result(resultsFuture, 5.seconds)
4343
results.size should equal(2)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class PostgreSQLSampleSpec extends FlatSpec with Matchers with DBSettings with L
3030
result.isDefined should be(true)
3131
}
3232

33-
it should "select values as a Traversable" in {
34-
val resultsFuture: Future[Traversable[AsyncLover]] = AsyncDB.withPool { implicit s =>
35-
withSQL { select.from(AsyncLover as al).limit(2) }.map(AsyncLover(al)).traversable.future()
33+
it should "select values as a Iterable" in {
34+
val resultsFuture: Future[Iterable[AsyncLover]] = AsyncDB.withPool { implicit s =>
35+
withSQL { select.from(AsyncLover as al).limit(2) }.map(AsyncLover(al)).iterable.future()
3636
}
3737
Await.result(resultsFuture, 5.seconds)
3838
val results = resultsFuture.value.get.get

0 commit comments

Comments
 (0)