Skip to content

Commit

Permalink
Merge branch 'arbitrary-arity-tuple' of github.com:Primetalk/zio-prot…
Browse files Browse the repository at this point in the history
…oquill into arbitrary-arity-tuple
  • Loading branch information
Primetalk committed May 8, 2024
2 parents 53daedb + 348eab2 commit cb74dfb
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
module: [ sqltest, db, bigdata ]

steps:
- uses: actions/[email protected].3
- uses: actions/[email protected].5
- name: Setup Java and Scala
uses: actions/[email protected]
with:
Expand All @@ -46,7 +46,7 @@ jobs:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/[email protected].3
- uses: actions/[email protected].5
- name: Setup Java and Scala
uses: actions/[email protected]
with:
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Not Supported:
- Implicit class based extensions. Please see the [Extensions](https://github.com/zio/zio-protoquill#extensions) section below on how to do this.

Planned Future Support
- Monix JDBC (and Cassandra) Contexts (Coming Soon!)
- OrientDB Contexts
- Spark Context

Expand All @@ -45,7 +44,7 @@ For further information, watch:

The simplest way to get started with ProtoQuill is with the standard JDBC contexts.
These are sychronous so for a high-throughput system you will ultimately need to switch
to either the ZIO-based contexts or the Monix ones (Monix contexts coming soon!)
to either the ZIO-based contexts

Add the following to your SBT file:
```scala
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ val filteredModules = {
selectedModules
}

val zioQuillVersion = "4.8.3"
val zioQuillVersion = "4.8.4"
val zioVersion = "2.0.22"

lazy val `quill` =
Expand Down Expand Up @@ -266,7 +266,7 @@ lazy val jdbcTestingLibraries = Seq(
libraryDependencies ++= Seq(
"com.zaxxer" % "HikariCP" % "5.1.0" exclude("org.slf4j", "*"),
// In 8.0.22 error happens: Conversion from java.time.OffsetDateTime to TIMESTAMP is not supported
"com.mysql" % "mysql-connector-j" % "8.3.0" % Test,
"com.mysql" % "mysql-connector-j" % "8.4.0" % Test,
"com.h2database" % "h2" % "2.2.224" % Test,
// In 42.2.18 error happens: PSQLException: conversion to class java.time.OffsetTime from timetz not supported
"org.postgresql" % "postgresql" % "42.7.3" % Test,
Expand Down
6 changes: 0 additions & 6 deletions build/setup_db_scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ function setup_sqlite() {
echo "Setting permissions on sqlite DB File"
chmod a+rw $DB_FILE

# # DB File in quill-jdbc-monix
# DB_FILE=quill-jdbc-monix/quill_test.db
# rm -f $DB_FILE
# sqlite3 $DB_FILE < $SQLITE_SCRIPT
# chmod a+rw $DB_FILE

echo "Sqlite ready!"
}

Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.9
sbt.version=1.10.0
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ resolvers += "Typesafe repository" at "https://repo.typesafe.com/typesafe/releas

addDependencyTreePlugin

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.11")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.12")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12")
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ trait PostgresJsonExtensions extends Encoders with Decoders {
implicit def jsonbAstDecoder: Decoder[JsonbValue[Json]] = astDecoder(JsonbValue(_))

def astEncoder[Wrapper](valueToString: Wrapper => String, jsonType: String): Encoder[Wrapper] =
encoder(Types.VARCHAR, (index, jsonValue, row) => {
encoder(Types.OTHER, (index, jsonValue, row) => {
val obj = new org.postgresql.util.PGobject()
obj.setType(jsonType)
val jsonString = valueToString(jsonValue)
Expand All @@ -50,7 +50,7 @@ trait PostgresJsonExtensions extends Encoders with Decoders {
jsonType: String,
jsonEncoder: JsonEncoder[JsValue]
): Encoder[Wrapper] =
encoder(Types.VARCHAR, (index, jsonValue, row) => {
encoder(Types.OTHER, (index, jsonValue, row) => {
val obj = new org.postgresql.util.PGobject()
obj.setType(jsonType)
val jsonString = jsonEncoder.encodeJson(unwrap(jsonValue), None).toString
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.getquill.postgres

import io.getquill._
import org.scalatest.BeforeAndAfterEach
import zio.Chunk
import zio.json.ast.Json
import zio.json.{ DeriveJsonDecoder, DeriveJsonEncoder, JsonDecoder, JsonEncoder } //
import zio.json.{DeriveJsonDecoder, DeriveJsonEncoder, JsonDecoder, JsonEncoder}

class PostgresJsonSpec extends ZioSpec {
class PostgresJsonSpec extends ZioSpec with BeforeAndAfterEach {
val context = testContext
import testContext._

Expand All @@ -15,22 +16,28 @@ class PostgresJsonSpec extends ZioSpec {
case class JsonEntity(name: String, value: JsonValue[PersonJson])
case class JsonbEntity(name: String, value: JsonbValue[PersonJsonb])

val jsonJoe = JsonValue(PersonJson("Joe", 123))
val jsonValue = JsonEntity("JoeEntity", jsonJoe)
val jsonbJoe = JsonbValue(PersonJsonb("Joe", 123))
case class JsonOptEntity(name: String, value: Option[JsonValue[PersonJson]])
case class JsonbOptEntity(name: String, value: Option[JsonbValue[PersonJsonb]])

val jsonJoe = JsonValue(PersonJson("Joe", 123))
val jsonValue = JsonEntity("JoeEntity", jsonJoe)
val jsonbJoe = JsonbValue(PersonJsonb("Joe", 123))
val jsonbValue = JsonbEntity("JoeEntity", jsonbJoe)

case class JsonAstEntity(name: String, value: JsonValue[Json])
case class JsonbAstEntity(name: String, value: JsonbValue[Json])

case class JsonAstOptEntity(name: String, value: Option[JsonValue[Json]])
case class JsonbAstOptEntity(name: String, value: Option[JsonbValue[Json]])

implicit val personJsonEncoder: JsonEncoder[PersonJson] = DeriveJsonEncoder.gen[PersonJson]
implicit val personJsonDecoder: JsonDecoder[PersonJson] = DeriveJsonDecoder.gen[PersonJson]

implicit val personJsonbEncoder: JsonEncoder[PersonJsonb] = DeriveJsonEncoder.gen[PersonJsonb]
implicit val personJsonbDecoder: JsonDecoder[PersonJsonb] = DeriveJsonDecoder.gen[PersonJsonb]

override def beforeAll() = {
super.beforeAll()
override def beforeEach() = {
super.beforeEach()
testContext.run(quote(query[JsonbEntity].delete)).runSyncUnsafe()
testContext.run(quote(query[JsonEntity].delete)).runSyncUnsafe()
()
Expand All @@ -50,23 +57,99 @@ class PostgresJsonSpec extends ZioSpec {
}
}

"encodes and decodes optional json entity" - {
inline def jsonOptQuery = quote(querySchema[JsonOptEntity]("JsonEntity"))
inline def jsonbOptQuery = quote(querySchema[JsonbOptEntity]("JsonEntity"))

"some json" in {
val value = JsonOptEntity("JoeEntity", Some(jsonJoe))

testContext.run(jsonOptQuery.insertValue(lift(value))).runSyncUnsafe()
val inserted = testContext.run(jsonOptQuery).runSyncUnsafe().head
inserted mustEqual value
}

"some jsonb" in {
val value = JsonbOptEntity("JoeEntity", Some(jsonbJoe))

testContext.run(jsonbOptQuery.insertValue(lift(value))).runSyncUnsafe()
val inserted = testContext.run(jsonbOptQuery).runSyncUnsafe().head
inserted mustEqual value
}

"none json" in {
val value = JsonOptEntity("JoeEntity", None)

testContext.run(jsonOptQuery.insertValue(lift(value))).runSyncUnsafe()
val inserted = testContext.run(jsonOptQuery).runSyncUnsafe().head
inserted mustEqual value
}

"none jsonb" in {
val value = JsonbOptEntity("JoeEntity", None)

testContext.run(jsonbOptQuery.insertValue(lift(value))).runSyncUnsafe()
val inserted = testContext.run(jsonbOptQuery).runSyncUnsafe().head
inserted mustEqual value
}
}

"encodes and decodes json ast" - {
val jsonJoe = Json.Obj(Chunk("age" -> Json.Num(123), "name" -> Json.Str("Joe")))
inline def jsonAstQuery = quote { querySchema[JsonAstEntity]("JsonEntity") }
inline def jsonbAstQuery = quote { querySchema[JsonbAstEntity]("JsonbEntity") }
val jsonJoe = Json.Obj(Chunk("age" -> Json.Num(123), "name" -> Json.Str("Joe")))
inline def jsonAstQuery = quote(querySchema[JsonAstEntity]("JsonEntity"))
inline def jsonbAstQuery = quote(querySchema[JsonbAstEntity]("JsonbEntity"))

val jsonAstValue = JsonAstEntity("JoeEntity", JsonValue(jsonJoe))
val jsonAstValue = JsonAstEntity("JoeEntity", JsonValue(jsonJoe))
val jsonbAstValue = JsonbAstEntity("JoeEntity", JsonbValue(jsonJoe))

"json" in {
testContext.run(jsonAstQuery.insertValue(lift(jsonAstValue))).runSyncUnsafe()
val inserted = testContext.run(jsonAstQuery).runSyncUnsafe().head
inserted mustEqual jsonAstValue
}

"jsonb" in {
testContext.run(jsonbAstQuery.insertValue(lift(jsonbAstValue))).runSyncUnsafe()
val inserted = testContext.run(jsonbAstQuery).runSyncUnsafe().head
inserted mustEqual jsonbAstValue
}
}

"encodes and decodes optional json ast" - {
val jsonJoe = Json.Obj(Chunk("age" -> Json.Num(123), "name" -> Json.Str("Joe")))
inline def jsonAstOptQuery = quote(querySchema[JsonAstOptEntity]("JsonEntity"))
inline def jsonbAstOptQuery = quote(querySchema[JsonbAstOptEntity]("JsonbEntity"))

val jsonbAstValue = JsonbAstEntity("JoeEntity", JsonbValue(jsonJoe))

"some json" in {
val value = JsonAstOptEntity("JoeEntity", Some(JsonValue(jsonJoe)))
testContext.run(jsonAstOptQuery.insertValue(lift(value))).runSyncUnsafe()
val inserted = testContext.run(jsonAstOptQuery).runSyncUnsafe().head
inserted mustEqual value
}

"some jsonb" in {
val value = JsonbAstOptEntity("JoeEntity", Some(JsonbValue(jsonJoe)))
testContext.run(jsonbAstOptQuery.insertValue(lift(value))).runSyncUnsafe()
val inserted = testContext.run(jsonbAstOptQuery).runSyncUnsafe().head
inserted mustEqual value
}

"none json" in {
val value = JsonAstOptEntity("JoeEntity", None)
testContext.run(jsonAstOptQuery.insertValue(lift(value))).runSyncUnsafe()
val inserted = testContext.run(jsonAstOptQuery).runSyncUnsafe().head
inserted mustEqual value
}

"none jsonb" in {
val value = JsonbAstOptEntity("JoeEntity", None)
testContext.run(jsonbAstOptQuery.insertValue(lift(value))).runSyncUnsafe()
val inserted = testContext.run(jsonbAstOptQuery).runSyncUnsafe().head
inserted mustEqual value
}

}

}

0 comments on commit cb74dfb

Please sign in to comment.