Skip to content

Commit

Permalink
Merge branch 'typelevel:main' into multi-query-statement-discarded
Browse files Browse the repository at this point in the history
  • Loading branch information
rolang authored Feb 8, 2024
2 parents 1644165 + 3f99149 commit 60f0e5d
Show file tree
Hide file tree
Showing 22 changed files with 1,352 additions and 33 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ jobs:

- name: Make target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/series/0.6.x')
run: mkdir -p modules/circe/.jvm/target unidocs/target modules/core/native/target modules/core/js/target modules/circe/.js/target modules/core/jvm/target modules/refined/.native/target modules/refined/.js/target modules/refined/.jvm/target modules/circe/.native/target project/target
run: mkdir -p modules/circe/.jvm/target unidocs/target modules/core/native/target modules/core/js/target modules/postgis/.native/target modules/circe/.js/target modules/postgis/.js/target modules/core/jvm/target modules/refined/.native/target modules/refined/.js/target modules/refined/.jvm/target modules/circe/.native/target modules/postgis/.jvm/target project/target

- name: Compress target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/series/0.6.x')
run: tar cf targets.tar modules/circe/.jvm/target unidocs/target modules/core/native/target modules/core/js/target modules/circe/.js/target modules/core/jvm/target modules/refined/.native/target modules/refined/.js/target modules/refined/.jvm/target modules/circe/.native/target project/target
run: tar cf targets.tar modules/circe/.jvm/target unidocs/target modules/core/native/target modules/core/js/target modules/postgis/.native/target modules/circe/.js/target modules/postgis/.js/target modules/core/jvm/target modules/refined/.native/target modules/refined/.js/target modules/refined/.jvm/target modules/circe/.native/target modules/postgis/.jvm/target project/target

- name: Upload target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/series/0.6.x')
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}-${{ matrix.project }}
path: targets.tar
Expand Down Expand Up @@ -138,7 +138,7 @@ jobs:
docker-compose up -d
- name: Download target directories (2.13, skunkJS)
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13-skunkJS

Expand All @@ -148,7 +148,7 @@ jobs:
rm targets.tar
- name: Download target directories (2.13, skunkJVM)
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13-skunkJVM

Expand All @@ -158,7 +158,7 @@ jobs:
rm targets.tar
- name: Download target directories (2.13, skunkNative)
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13-skunkNative

Expand All @@ -168,7 +168,7 @@ jobs:
rm targets.tar
- name: Download target directories (3, skunkJS)
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3-skunkJS

Expand All @@ -178,7 +178,7 @@ jobs:
rm targets.tar
- name: Download target directories (3, skunkJVM)
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3-skunkJVM

Expand All @@ -188,7 +188,7 @@ jobs:
rm targets.tar
- name: Download target directories (3, skunkNative)
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3-skunkNative

Expand Down
2 changes: 1 addition & 1 deletion bin/local
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ esac
export SERVER_KEY=$(cat world/server.key)
export SERVER_CERT=$(cat world/server.crt)

docker-compose $CMD $EXTRA_FLAGS
docker compose $CMD $EXTRA_FLAGS
26 changes: 19 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ThisBuild / mimaBinaryIssueFilters ++= List(
)

// This is used in a couple places
lazy val fs2Version = "3.9.3"
lazy val fs2Version = "3.9.4"
lazy val openTelemetryVersion = "1.29.0"
lazy val otel4sVersion = "0.4.0"
lazy val refinedVersion = "0.11.0"
Expand Down Expand Up @@ -98,7 +98,7 @@ lazy val commonSettings = Seq(

lazy val skunk = tlCrossRootProject
.settings(name := "skunk")
.aggregate(core, tests, circe, refined, example, unidocs)
.aggregate(core, tests, circe, refined, postgis, example, unidocs)
.settings(commonSettings)

lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform)
Expand All @@ -111,15 +111,15 @@ lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform)
description := "Tagless, non-blocking data access library for Postgres.",
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % "2.10.0",
"org.typelevel" %%% "cats-effect" % "3.5.2",
"org.typelevel" %%% "cats-effect" % "3.5.3",
"co.fs2" %%% "fs2-core" % fs2Version,
"co.fs2" %%% "fs2-io" % fs2Version,
"org.scodec" %%% "scodec-bits" % "1.1.38",
"org.scodec" %%% "scodec-core" % (if (tlIsScala3.value) "2.2.2" else "1.11.10"),
"org.scodec" %%% "scodec-cats" % "1.2.0",
"org.typelevel" %%% "otel4s-core-trace" % otel4sVersion,
"org.tpolecat" %%% "sourcepos" % "1.1.0",
"org.typelevel" %%% "twiddles-core" % "0.7.1",
"org.typelevel" %%% "twiddles-core" % "0.8.0",
) ++ Seq(
"com.beachape" %%% "enumeratum" % "1.7.3",
).filterNot(_ => tlIsScala3.value)
Expand Down Expand Up @@ -160,10 +160,23 @@ lazy val circe = crossProject(JVMPlatform, JSPlatform, NativePlatform)
)
)

lazy val postgis = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("modules/postgis"))
.dependsOn(core)
.enablePlugins(AutomateHeaderPlugin)
.settings(commonSettings)
.settings(
name := "skunk-postgis",
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-parse" % "1.0.0"
),
)

lazy val tests = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Full)
.in(file("modules/tests"))
.dependsOn(core, circe, refined)
.dependsOn(core, circe, refined, postgis)
.enablePlugins(AutomateHeaderPlugin, NoPublishPlugin)
.settings(commonSettings)
.settings(
Expand All @@ -175,7 +188,7 @@ lazy val tests = crossProject(JVMPlatform, JSPlatform, NativePlatform)
"org.typelevel" %%% "munit-cats-effect" % "2.0.0-M4",
"org.typelevel" %%% "cats-free" % "2.10.0",
"org.typelevel" %%% "cats-laws" % "2.10.0",
"org.typelevel" %%% "cats-effect-testkit" % "3.5.2",
"org.typelevel" %%% "cats-effect-testkit" % "3.5.3",
"org.typelevel" %%% "discipline-munit" % "2.0.0-M3",
"org.typelevel" %%% "cats-time" % "0.5.1",
"eu.timepit" %%% "refined-cats" % refinedVersion,
Expand Down Expand Up @@ -274,4 +287,3 @@ lazy val docs = project
)

// ci

4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3'
services:
# main instance for testing
postgres:
image: postgres:11
image: postgis/postgis:11-3.3
volumes:
- ./world/fix_perms.sh:/docker-entrypoint-initdb.d/fix_perms.sh
- ./world/world.sql:/docker-entrypoint-initdb.d/world.sql
Expand Down Expand Up @@ -65,4 +65,4 @@ services:
- 4317:4317
- 4318:4318
environment:
COLLECTOR_OTLP_ENABLED: "true"
COLLECTOR_OTLP_ENABLED: "true"
13 changes: 10 additions & 3 deletions modules/core/shared/src/main/scala/Fragment.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,18 @@ final case class Fragment[A](
def stripMargin: Fragment[A] = stripMargin('|')

def stripMargin(marginChar: Char): Fragment[A] = {
val ps = parts.map {
val head = parts.headOption
val tail = parts.tail
val ps = head.map {
_.bimap(
_.stripMargin(marginChar).replaceAll("\n", " "),
_.map(_.stripMargin(marginChar).replaceAll("\n", " "))
_.stripMargin(marginChar),
_.map(_.stripMargin(marginChar))
)
}.toList ++ tail.map {
_.bimap(
str => str.takeWhile(_ != '\n') + str.dropWhile(_ != '\n').stripMargin(marginChar),
_.map(str => str.takeWhile(_ != '\n') + str.dropWhile(_ != '\n').stripMargin(marginChar))
)
}
Fragment(ps, encoder, origin)
}
Expand Down
1 change: 1 addition & 0 deletions modules/core/shared/src/main/scala/data/Completion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ object Completion {
case object Grant extends Completion
case object Revoke extends Completion
case object AlterIndex extends Completion
case class Merge(count: Int) extends Completion
// more ...

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ object CommandComplete {
val Update: Regex = """UPDATE (\d+)""".r
val Insert: Regex = """INSERT (\d+ \d+)""".r
val Copy: Regex = """COPY (\d+)""".r
val Merge: Regex = """MERGE (\d+)""".r
}

//TODO: maybe make lazy val
Expand Down Expand Up @@ -103,6 +104,7 @@ object CommandComplete {
case "GRANT" => apply(Completion.Grant)
case "REVOKE" => apply(Completion.Revoke)
case "ALTER INDEX" => apply(Completion.AlterIndex)
case Patterns.Merge(s) => apply(Completion.Merge(s.toInt))
// more .. fill in as we hit them

case s => apply(Completion.Unknown(s))
Expand Down
18 changes: 18 additions & 0 deletions modules/postgis/src/main/scala-2/ewkb/platform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2018-2021 by Rob Norris
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT

package skunk.postgis
package ewkb

import scodec.Attempt
import scodec.{Codec => Scodec}
import scodec.bits.BitVector
import scodec.bits.ByteOrdering

trait EWKBCodecPlatform extends EWKBPrimitives {
def ewkbEncode(ewkb: EWKBType, geometry: Geometry, geoEncoder: Scodec[Geometry])(implicit bo: ByteOrdering): Attempt[BitVector] = {
val encoder = byteOrdering :: ewkbType :: geoEncoder
encoder.encode(bo :: ewkb :: geometry :: shapeless.HNil)
}
}
18 changes: 18 additions & 0 deletions modules/postgis/src/main/scala-3/ewkb/platform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2018-2021 by Rob Norris
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT

package skunk.postgis
package ewkb

import scodec.Attempt
import scodec.{Codec => Scodec}
import scodec.bits.BitVector
import scodec.bits.ByteOrdering

trait EWKBCodecPlatform extends EWKBPrimitives {
def ewkbEncode(ewkb: EWKBType, geometry: Geometry, geoEncoder: Scodec[Geometry])(using bo: ByteOrdering): Attempt[BitVector] = {
val encoder = byteOrdering :: ewkbType :: geoEncoder
encoder.encode((bo, ewkb, geometry))
}
}
45 changes: 45 additions & 0 deletions modules/postgis/src/main/scala/codecs.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2018-2021 by Rob Norris
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT

package skunk
package postgis
package codecs

import scala.reflect.ClassTag

import cats.syntax.all._
import scodec.bits.ByteVector
import skunk.data.Type

trait PostGISGeometryCodecs {

val geometry: Codec[Geometry] = Codec.simple[Geometry](
geometry => ewkb.codecs.geometry.encode(geometry).require.toHex,
str => {
ByteVector.fromHex(str).fold(s"[postgis] Bad EWKB Hex: $str".asLeft[Geometry]) { byteVector =>
ewkb.codecs.geometry.decodeValue(byteVector.toBitVector).toEither.leftMap(_.message)
}
},
Type("geometry")
)

val point: Codec[Point] = geometryCodec[Point]
val lineString: Codec[LineString] = geometryCodec[LineString]
val polygon: Codec[Polygon] = geometryCodec[Polygon]
val multiPoint: Codec[MultiPoint] = geometryCodec[MultiPoint]
val multiLineString: Codec[MultiLineString] = geometryCodec[MultiLineString]
val multiPolygon: Codec[MultiPolygon] = geometryCodec[MultiPolygon]
val geometryCollection: Codec[GeometryCollection] = geometryCodec[GeometryCollection]

private def geometryCodec[A >: Null <: Geometry](implicit A: ClassTag[A]): Codec[A] = {
geometry.imap[A](geom => A.runtimeClass.cast(geom).asInstanceOf[A])(o =>
o.asInstanceOf[Geometry]
)
}

}

object geometry extends PostGISGeometryCodecs

object all extends PostGISGeometryCodecs
Loading

0 comments on commit 60f0e5d

Please sign in to comment.