Skip to content

prepare Scala 2.13 #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
330 changes: 251 additions & 79 deletions core/src/main/scala/scalikejdbc/async/AsyncDBSession.scala

Large diffs are not rendered by default.

144 changes: 72 additions & 72 deletions core/src/main/scala/scalikejdbc/async/AsyncRelationalSQLs.scala

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2013 Kazuhiro Sera
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package scalikejdbc.async

import scalikejdbc._

/**
* AsyncResultSet Iterator
*/
class AsyncResultSetIterator(var rs: AsyncResultSet) extends Iterator[WrappedResultSet] {

override def hasNext: Boolean = rs.next()

override def next: WrappedResultSet = {
val value = rs
rs = rs.tail()
value
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import scalikejdbc._
/**
* AsyncResultSet Traversable
*/
@deprecated("will be removed. use AsyncResultSetIterator", "0.12.0")
class AsyncResultSetTraversable(var rs: AsyncResultSet) extends Traversable[WrappedResultSet] {

def foreach[U](f: (WrappedResultSet) => U): Unit = while (rs.next()) {
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/scala/scalikejdbc/async/AsyncSQLs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ trait AsyncSQLToOption[A] extends Any {
}
class AsyncSQLToOptionImpl[A](val underlying: SQLToOption[A, HasExtractor]) extends AnyVal with AsyncSQLToOption[A]

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

trait AsyncSQLToList[A] extends Any {
def underlying: SQLToList[A, HasExtractor]
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/scalikejdbc/async/FutureImplicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import scalikejdbc.async.ShortenedNames._
*/
object FutureImplicits {

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

implicit def fromSQLToListFuture[A](sql: SQL[A, HasExtractor])(
implicit
Expand Down
50 changes: 25 additions & 25 deletions core/src/main/scala/scalikejdbc/async/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,44 +70,44 @@ package object async {
}

// --------------
// one-to-x -> Traversable
// one-to-x -> Iterable
// --------------

implicit def makeSQLToTraversableAsync[A, B1, B2, B3, B4, B5, Z](sql: SQLToTraversable[A, HasExtractor]): AsyncSQLToTraversable[A] = {
new AsyncSQLToTraversableImpl[A](sql)
implicit def makeSQLToIterableAsync[A, B1, B2, B3, B4, B5, Z](sql: SQLToIterable[A, HasExtractor]): AsyncSQLToIterable[A] = {
new AsyncSQLToIterableImpl[A](sql)
}
implicit def makeSQLToTraversableAsync[A, B1, B2, B3, B4, B5, Z](sql: SQLToTraversableImpl[A, HasExtractor]): AsyncSQLToTraversable[A] = {
new AsyncSQLToTraversableImpl[A](sql)
implicit def makeSQLToIterableAsync[A, B1, B2, B3, B4, B5, Z](sql: SQLToIterableImpl[A, HasExtractor]): AsyncSQLToIterable[A] = {
new AsyncSQLToIterableImpl[A](sql)
}
implicit def makeOneToOneSQLToTraversableAsync[A, B, Z](sql: OneToOneSQLToTraversable[A, B, HasExtractor, Z]): AsyncOneToOneSQLToTraversable[A, B, Z] = {
new AsyncOneToOneSQLToTraversable[A, B, Z](sql)
implicit def makeOneToOneSQLToIterableAsync[A, B, Z](sql: OneToOneSQLToIterable[A, B, HasExtractor, Z]): AsyncOneToOneSQLToIterable[A, B, Z] = {
new AsyncOneToOneSQLToIterable[A, B, Z](sql)
}
implicit def makeOneToManySQLToTraversableAsync[A, B, Z](sql: OneToManySQLToTraversable[A, B, HasExtractor, Z]): AsyncOneToManySQLToTraversable[A, B, Z] = {
new AsyncOneToManySQLToTraversable[A, B, Z](sql)
implicit def makeOneToManySQLToIterableAsync[A, B, Z](sql: OneToManySQLToIterable[A, B, HasExtractor, Z]): AsyncOneToManySQLToIterable[A, B, Z] = {
new AsyncOneToManySQLToIterable[A, B, Z](sql)
}
implicit def makeOneToManies2SQLToTraversableAsync[A, B1, B2, Z](sql: OneToManies2SQLToTraversable[A, B1, B2, HasExtractor, Z]): AsyncOneToManies2SQLToTraversable[A, B1, B2, Z] = {
new AsyncOneToManies2SQLToTraversable[A, B1, B2, Z](sql)
implicit def makeOneToManies2SQLToIterableAsync[A, B1, B2, Z](sql: OneToManies2SQLToIterable[A, B1, B2, HasExtractor, Z]): AsyncOneToManies2SQLToIterable[A, B1, B2, Z] = {
new AsyncOneToManies2SQLToIterable[A, B1, B2, Z](sql)
}
implicit def makeOneToManies3SQLToTraversableAsync[A, B1, B2, B3, Z](sql: OneToManies3SQLToTraversable[A, B1, B2, B3, HasExtractor, Z]): AsyncOneToManies3SQLToTraversable[A, B1, B2, B3, Z] = {
new AsyncOneToManies3SQLToTraversable[A, B1, B2, B3, Z](sql)
implicit def makeOneToManies3SQLToIterableAsync[A, B1, B2, B3, Z](sql: OneToManies3SQLToIterable[A, B1, B2, B3, HasExtractor, Z]): AsyncOneToManies3SQLToIterable[A, B1, B2, B3, Z] = {
new AsyncOneToManies3SQLToIterable[A, B1, B2, B3, Z](sql)
}
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] = {
new AsyncOneToManies4SQLToTraversable[A, B1, B2, B3, B4, Z](sql)
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] = {
new AsyncOneToManies4SQLToIterable[A, B1, B2, B3, B4, Z](sql)
}
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] = {
new AsyncOneToManies5SQLToTraversable[A, B1, B2, B3, B4, B5, Z](sql)
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] = {
new AsyncOneToManies5SQLToIterable[A, B1, B2, B3, B4, B5, Z](sql)
}
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] = {
new AsyncOneToManies6SQLToTraversable[A, B1, B2, B3, B4, B5, B6, Z](sql)
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] = {
new AsyncOneToManies6SQLToIterable[A, B1, B2, B3, B4, B5, B6, Z](sql)
}
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] = {
new AsyncOneToManies7SQLToTraversable[A, B1, B2, B3, B4, B5, B6, B7, Z](sql)
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] = {
new AsyncOneToManies7SQLToIterable[A, B1, B2, B3, B4, B5, B6, B7, Z](sql)
}
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] = {
new AsyncOneToManies8SQLToTraversable[A, B1, B2, B3, B4, B5, B6, B7, B8, Z](sql)
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] = {
new AsyncOneToManies8SQLToIterable[A, B1, B2, B3, B4, B5, B6, B7, B8, Z](sql)
}
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] = {
new AsyncOneToManies9SQLToTraversable[A, B1, B2, B3, B4, B5, B6, B7, B8, B9, Z](sql)
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] = {
new AsyncOneToManies9SQLToIterable[A, B1, B2, B3, B4, B5, B6, B7, B8, B9, Z](sql)
}

// --------------
Expand Down
6 changes: 3 additions & 3 deletions core/src/test/scala/sample/MySQLSampleSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ class MySQLSampleSpec extends FlatSpec with Matchers with DBSettings with Loggin
result.isDefined should be(true)
}

it should "select values as a Traversable" in {
val resultsFuture: Future[Traversable[AsyncLover]] = NamedAsyncDB('mysql).withPool { implicit s =>
it should "select values as a Iterable" in {
val resultsFuture: Future[Iterable[AsyncLover]] = NamedAsyncDB('mysql).withPool { implicit s =>
withSQL {
select.from(AsyncLover as al)
.where.isNotNull(al.birthday) // mysql-async 0.2.4 cannot parse nullable date value.
.limit(2)
}.map(AsyncLover(al)).traversable.future()
}.map(AsyncLover(al)).iterable.future()
}
val results = Await.result(resultsFuture, 5.seconds)
results.size should equal(2)
Expand Down
6 changes: 3 additions & 3 deletions core/src/test/scala/sample/PostgreSQLSampleSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class PostgreSQLSampleSpec extends FlatSpec with Matchers with DBSettings with L
result.isDefined should be(true)
}

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