Skip to content

Commit

Permalink
Merge pull request #16 from ajozwik/jasync
Browse files Browse the repository at this point in the history
Jasync
  • Loading branch information
ajozwik authored Jul 15, 2020
2 parents 176da74 + 102850b commit 22ed681
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ newlines.alwaysBeforeTopLevelStatements = true
continuationIndent.extendSite = 2
spaces.inImportCurlyBraces = true
unindentTopLevelOperators = true
rewrite.rules = [AsciiSortImports, RedundantBraces, RedundantParens]
rewrite.rules = [AsciiSortImports, RedundantBraces]
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cache:

language: scala
scala:
- 2.12.11
- 2.12.12
- 2.13.3

jdk:
Expand Down
51 changes: 13 additions & 38 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import com.sksamuel.scapegoat.sbt.ScapegoatSbtPlugin.autoImport._

val `scalaVersion_2.13` = "2.13.3"

val `scalaVersion_2.12` = "2.12.11"
val `scalaVersion_2.12` = "2.12.12"

val `only2_12` = Seq(`scalaVersion_2.12`)
ThisBuild / scalaVersion := `scalaVersion_2.13`

val targetJdk = "1.8"

Expand All @@ -21,16 +21,7 @@ ThisBuild / scapegoatVersion := {

resolvers += Resolver.sonatypeRepo("releases")

lazy val scalaVersionFromProps = sys.props.getOrElse("macro.scala.version", `scalaVersion_2.12`)

ThisBuild / scalaVersion := {
if (is213Version(scalaVersionFromProps))
`scalaVersion_2.13`
else
`scalaVersion_2.12`
}

ThisBuild / crossScalaVersions := Set(scalaVersion.value, `scalaVersion_2.12`).toSeq
ThisBuild / crossScalaVersions := Seq(`scalaVersion_2.13`, `scalaVersion_2.12`)

ThisBuild / organization := "com.github.ajozwik"

Expand Down Expand Up @@ -62,9 +53,9 @@ val `ch.qos.logback_logback-classic` = "ch.qos.logback" % "logback-classic" % "1

val `io.getquill_quill-core` = "io.getquill" %% "quill-core" % quillVersion

val `io.getquill_quill-async` = "io.getquill" %% "quill-async" % quillVersion
val `io.getquill_quill-jasync` = "io.getquill" %% "quill-jasync" % quillVersion

val `io.getquill_quill-async-mysql` = "io.getquill" %% "quill-async-mysql" % quillVersion
val `io.getquill_quill-jasync-mysql` = "io.getquill" %% "quill-jasync-mysql" % quillVersion

val `io.getquill_quill-cassandra-monix` = "io.getquill" %% "quill-cassandra-monix" % quillVersion

Expand All @@ -84,21 +75,11 @@ val `org.scalatestplus_scalacheck-1-14` = "org.scalatestplus" %% "scalacheck-1-1

val `org.cassandraunit_cassandra-unit` = "org.cassandraunit" % "cassandra-unit" % "3.11.2.0"

val `com.datastax.cassandra_cassandra-driver-extras` = "com.datastax.cassandra" % "cassandra-driver-extras" % "3.8.0"
val `com.datastax.cassandra_cassandra-driver-extras` = "com.datastax.cassandra" % "cassandra-driver-extras" % "3.9.0"

def is213Version(version: String): Boolean = version.startsWith("2.13")

def modulesFromProps: Seq[ClasspathDep[ProjectReference]] =
if (is213Version(scalaVersionFromProps))
scala213Modules
else
allModules

lazy val `quill-macro-parent` =
(project in file("."))
.settings(skip in publish := true)
.aggregate(modulesFromProps.map(_.project): _*)
.dependsOn(modulesFromProps: _*)
skip in publish := true

lazy val `macro-quill` = projectWithName("macro-quill", file("macro-quill")).settings(
libraryDependencies ++= Seq(
Expand All @@ -119,7 +100,7 @@ lazy val `quill-monix-macro` = projectWithName("quill-monix-macro", file("quill-
.settings(libraryDependencies ++= Seq(`io.getquill_quill-monix`))
.dependsOn(`macro-quill`, `macro-quill` % "test->test")

lazy val `quill-cassandra-monix-macro` = projectWithNameOnly12("quill-cassandra-monix-macro", file("quill-cassandra-monix-macro"))
lazy val `quill-cassandra-monix-macro` = projectWithName("quill-cassandra-monix-macro", file("quill-cassandra-monix-macro"))
.settings(
libraryDependencies ++= Seq(
`io.getquill_quill-cassandra-monix`,
Expand All @@ -131,7 +112,7 @@ lazy val `quill-cassandra-monix-macro` = projectWithNameOnly12("quill-cassandra-
.dependsOn(`quill-monix-macro`)
.dependsOn(Seq(`macro-quill`, `quill-monix-macro`, `quill-cassandra-macro`).map(_ % "test->test"): _*)

lazy val `quill-cassandra-macro` = projectWithNameOnly12("quill-cassandra-macro", file("quill-cassandra-macro"))
lazy val `quill-cassandra-macro` = projectWithName("quill-cassandra-macro", file("quill-cassandra-macro"))
.settings(
libraryDependencies ++= Seq(
`io.getquill_quill-cassandra`,
Expand All @@ -147,8 +128,8 @@ lazy val `quill-jdbc-macro` = projectWithName("quill-jdbc-macro", file("quill-jd
.settings(libraryDependencies ++= Seq(`io.getquill_quill-jdbc`))
.dependsOn(`macro-quill`, `macro-quill` % "test->test")

lazy val `quill-async-jdbc-macro` = projectWithNameOnly12("quill-async-jdbc-macro", file("quill-async-jdbc-macro"))
.settings(libraryDependencies ++= Seq(`io.getquill_quill-async`, `io.getquill_quill-async-mysql` % Test))
lazy val `quill-async-jdbc-macro` = projectWithName("quill-async-jdbc-macro", file("quill-async-jdbc-macro"))
.settings(libraryDependencies ++= Seq(`io.getquill_quill-jasync`, `io.getquill_quill-jasync-mysql` % Test))
.dependsOn(`macro-quill`, `macro-quill` % "test->test")

lazy val baseModules =
Expand All @@ -164,16 +145,10 @@ lazy val cassandraModules =
Seq[sbt.ClasspathDep[sbt.ProjectReference]](`quill-cassandra-macro`, `quill-cassandra-monix-macro`)

lazy val scala213Modules =
baseModules ++ dbModules
baseModules ++ dbModules ++ asyncDbModules

lazy val allModules =
scala213Modules ++ asyncDbModules ++ cassandraModules

def projectWithNameOnly12(name: String, file: File): Project =
projectWithName(name, file).settings(
crossScalaVersions := `only2_12`,
skip in publish := is213Version(scalaVersion.value)
)
scala213Modules ++ cassandraModules

def projectWithName(name: String, file: File): Project =
Project(name, file).settings(
Expand Down
2 changes: 1 addition & 1 deletion publish.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

PATH=$HOME/bin:$PATH sbt -Dquill.macro.log=false clean test publishLocal publishSigned sonatypeRelease
PATH=$HOME/bin:$PATH sbt -Dquill.macro.log=false clean +test +publishLocal publishSigned sonatypeRelease
3 changes: 0 additions & 3 deletions publish213.sh

This file was deleted.

2 changes: 1 addition & 1 deletion publishSnapshot.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

PATH=$HOME/bin:$PATH sbt clean test publishSigned
PATH=$HOME/bin:$PATH sbt -Dquill.macro.log=false clean +test +publishSigned
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
package pl.jozwik.quillgeneric.quillmacro.async

import com.github.mauricio.async.db.Connection
import com.github.jasync.sql.db.ConcreteConnection
import io.getquill.NamingStrategy
import io.getquill.context.Context
import io.getquill.context.async.AsyncContext
import io.getquill.context.jasync.JAsyncContext
import io.getquill.context.sql.idiom.SqlIdiom
import io.getquill.idiom.Idiom
import pl.jozwik.quillgeneric.quillmacro.async.AsyncJdbcRepository.AsyncJdbcContextDateQuotes
import pl.jozwik.quillgeneric.quillmacro.{ CompositeKey, WithId, WithUpdate }

object AsyncJdbcRepository {
type ContextDateQuotes[D <: Idiom, N <: NamingStrategy] = Context[D, N] with AsyncCrudWithContext[Long]
type AsyncJdbcContextDateQuotes[D <: SqlIdiom, N <: NamingStrategy, C <: Connection] = AsyncContext[D, N, C] with ContextDateQuotes[D, N]
type ContextDateQuotes[D <: Idiom, N <: NamingStrategy] = Context[D, N] with AsyncCrudWithContext[Long]
type AsyncJdbcContextDateQuotes[D <: SqlIdiom, N <: NamingStrategy, C <: ConcreteConnection] = JAsyncContext[D, N, C] with ContextDateQuotes[D, N]
}

trait AsyncJdbcRepositoryWithGeneratedId[K, T <: WithId[K], D <: SqlIdiom, N <: NamingStrategy, C <: Connection]
trait AsyncJdbcRepositoryWithGeneratedId[K, T <: WithId[K], D <: SqlIdiom, N <: NamingStrategy, C <: ConcreteConnection]
extends AsyncRepositoryWithGeneratedId[K, T]
with WithUpdate[Long]
with WithAsyncJdbcContext[D, N, C] {

protected def dynamicSchema: context.DynamicEntityQuery[T]
}

trait AsyncJdbcRepository[K, T <: WithId[K], D <: SqlIdiom, N <: NamingStrategy, C <: Connection]
trait AsyncJdbcRepository[K, T <: WithId[K], D <: SqlIdiom, N <: NamingStrategy, C <: ConcreteConnection]
extends AsyncRepository[K, T]
with WithUpdate[Long]
with WithAsyncJdbcContext[D, N, C] {
Expand All @@ -31,9 +31,9 @@ trait AsyncJdbcRepository[K, T <: WithId[K], D <: SqlIdiom, N <: NamingStrategy,

}

trait AsyncJdbcRepositoryCompositeKey[K <: CompositeKey[_, _], T <: WithId[K], D <: SqlIdiom, N <: NamingStrategy, C <: Connection]
trait AsyncJdbcRepositoryCompositeKey[K <: CompositeKey[_, _], T <: WithId[K], D <: SqlIdiom, N <: NamingStrategy, C <: ConcreteConnection]
extends AsyncJdbcRepository[K, T, D, N, C]

trait WithAsyncJdbcContext[D <: SqlIdiom, N <: NamingStrategy, C <: Connection] {
trait WithAsyncJdbcContext[D <: SqlIdiom, N <: NamingStrategy, C <: ConcreteConnection] {
protected val context: AsyncJdbcContextDateQuotes[D, N, C]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pl.jozwik.quillgeneric.async.jdbc.repository

import com.github.mauricio.async.db.Connection
import com.github.jasync.sql.db.ConcreteConnection
import io.getquill.NamingStrategy
import io.getquill.context.sql.idiom.SqlIdiom
import pl.jozwik.quillgeneric.model.{ Configuration, ConfigurationId }
Expand All @@ -9,13 +9,15 @@ import pl.jozwik.quillgeneric.quillmacro.async.AsyncJdbcRepository.AsyncJdbcCont

import scala.concurrent.{ ExecutionContext, Future }

class ConfigurationAsyncRepository[D <: SqlIdiom, N <: NamingStrategy, C <: Connection](
class ConfigurationAsyncRepository[D <: SqlIdiom, N <: NamingStrategy, C <: ConcreteConnection](
protected val context: AsyncJdbcContextDateQuotes[D, N, C],
tableName: String
) extends AsyncJdbcRepository[ConfigurationId, Configuration, D, N, C] {

protected def dynamicSchema: context.DynamicEntityQuery[Configuration] = dSchema

import context.toFuture

private implicit val dSchema: context.DynamicEntityQuery[Configuration] =
context.dynamicQuerySchema[Configuration](tableName)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pl.jozwik.quillgeneric.async.jdbc.repository

import com.github.mauricio.async.db.Connection
import com.github.jasync.sql.db.ConcreteConnection
import io.getquill.NamingStrategy
import io.getquill.context.sql.idiom.SqlIdiom
import pl.jozwik.quillgeneric.model.{ Person, PersonId }
Expand All @@ -9,11 +9,13 @@ import pl.jozwik.quillgeneric.quillmacro.async.AsyncJdbcRepositoryWithGeneratedI

import scala.concurrent.{ ExecutionContext, Future }

class PersonAsyncRepository[D <: SqlIdiom, N <: NamingStrategy, C <: Connection](
class PersonAsyncRepository[D <: SqlIdiom, N <: NamingStrategy, C <: ConcreteConnection](
protected val context: AsyncJdbcContextDateQuotes[D, N, C],
tableName: String
) extends AsyncJdbcRepositoryWithGeneratedId[PersonId, Person, D, N, C] {

import context.toFuture

protected def dynamicSchema: context.DynamicEntityQuery[Person] = dSchema

private implicit val dSchema: context.DynamicEntityQuery[Person] =
Expand All @@ -24,38 +26,34 @@ class PersonAsyncRepository[D <: SqlIdiom, N <: NamingStrategy, C <: Connection]

override def create(entity: Person, generatedId: Boolean)(implicit ex: ExecutionContext): Future[PersonId] =
context.transaction { implicit f =>
if (generatedId) {
if (generatedId)
context.createAndGenerateId[PersonId, Person](entity)(dSchema, f)
} else {
else
context.create[PersonId, Person](entity)(dSchema, f)
}
}

override def createAndRead(entity: Person, generatedId: Boolean)(implicit ex: ExecutionContext): Future[Person] =
context.transaction { implicit f =>
if (generatedId) {
if (generatedId)
context.createWithGenerateIdAndRead[PersonId, Person](entity)(dSchema, f)
} else {
else
context.createAndRead[PersonId, Person](entity)(dSchema, f)
}
}

override def createOrUpdate(entity: Person, generatedId: Boolean)(implicit ex: ExecutionContext): Future[PersonId] =
context.transaction { implicit f =>
if (generatedId) {
if (generatedId)
context.createAndGenerateIdOrUpdate[PersonId, Person](entity)(dSchema, f)
} else {
else
context.createOrUpdate[PersonId, Person](entity)(dSchema, f)
}
}

override def createOrUpdateAndRead(entity: Person, generatedId: Boolean = true)(implicit ex: ExecutionContext): Future[Person] =
context.transaction { implicit f =>
if (generatedId) {
if (generatedId)
context.createWithGenerateIdOrUpdateAndRead[PersonId, Person](entity)(dSchema, f)
} else {
else
context.createOrUpdateAndRead[PersonId, Person](entity)(dSchema, f)
}
}

override def read(id: PersonId)(implicit ex: ExecutionContext): Future[Option[Person]] =
Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ThisBuild / version := "0.8.9"
ThisBuild / version := "0.9.0-SNAPSHOT"

0 comments on commit 22ed681

Please sign in to comment.