Skip to content
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

SN 0.5 #119

Merged
merged 6 commits into from
Jul 13, 2024
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
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,14 @@ import roach.codecs.*
val connectionString =
"postgresql://postgres:mysecretpassword@localhost:5432/postgres"

Zone { implicit z =>
Pool.single(connectionString) { pool =>
pool.withLease {
Zone:
Pool.single(connectionString): pool =>
pool.withLease:
sql"select typname, typisdefined from pg_type".all(name ~ bool).foreach(println)

// with parameters now
val oid: Option[Int] =
sql"select oid::int4 from pg_type where typname = $varchar".one("bool", int4)
}
}
}
```

### `sql"..."` interpolator
Expand Down
43 changes: 34 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import java.nio.file.Paths
Global / onChangedBuildSource := ReloadOnSourceChanges

val Versions = new {
val Scala = "3.3.1"
val Scala = "3.3.3"

val circe = "0.14.6"
val circe = "0.14.9"

val munit = "1.0.0-M11"
val munit = "1.0.0"

val upickle = "3.2.0"
val upickle = "3.3.1"
}

import bindgen.interface.*
Expand All @@ -36,22 +36,22 @@ lazy val core =
Compile / bindgenBindings += {
val configurator = vcpkgConfigurator.value

Binding
.builder(configurator.includes("libpq") / "libpq-fe.h", "libpq")
Binding(configurator.includes("libpq") / "libpq-fe.h", "libpq")
.withLinkName("pq")
.addCImport("libpq-fe.h")
.withClangFlags(
configurator.pkgConfig
.updateCompilationFlags(List("-std=gnu99"), "libpq")
.toList
)
.build
.withNoLocation(true)
},
bindgenMode := BindgenMode.Manual(
sourceDirectory.value / "main" / "scala" / "generated",
(Compile / resourceDirectory).value / "scala-native"
),
moduleName := "core"
moduleName := "core",
configurePlatform
)

lazy val upickle =
Expand All @@ -64,6 +64,7 @@ lazy val upickle =
)
.settings(moduleName := "upickle")
.settings(common)
.settings(configurePlatform)

lazy val circe =
project
Expand All @@ -75,13 +76,14 @@ lazy val circe =
)
.settings(moduleName := "circe")
.settings(common)
.settings(configurePlatform)

val common = Seq(
organization := "com.indoorvivants.roach",
scalaVersion := Versions.Scala,
libraryDependencies += "org.scalameta" %%% "munit" % Versions.munit % Test,
resolvers ++= Resolver.sonatypeOssRepos("snapshots"),
vcpkgDependencies := Set("libpq")
vcpkgDependencies := VcpkgDependencies("libpq")
)

lazy val docs =
Expand Down Expand Up @@ -127,3 +129,26 @@ inThisBuild(
)

addCommandAlias("checkDocs", "docs/mdoc --in README.md")

val configurePlatform = Seq(
nativeConfig := {
import com.indoorvivants.detective.*
val conf = nativeConfig.value
val arch64 =
if (
Platform.arch == Platform.Arch.Arm && Platform.bits == Platform.Bits.x64
)
List("-arch", "arm64")
else Nil

conf
.withLinkingOptions(
conf.linkingOptions ++ arch64
)
.withCompileOptions(
conf.compileOptions ++ arch64
)
.withIncrementalCompilation(true)
.withMultithreading(true)
}
)
9 changes: 5 additions & 4 deletions module-circe/src/test/scala/CirceTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import roach.codecs.*
import io.circe.Json
import io.circe.JsonNumber
import roach.Pool
import scala.scalanative.unsafe.Zone

class CirceTests extends munit.FunSuite with roach.tests.TestHarness:

Expand All @@ -18,7 +19,7 @@ class CirceTests extends munit.FunSuite with roach.tests.TestHarness:
""")

test("read: raw json") {
zone {
Zone {
withDB { db ?=>
val q =
"""SELECT '{"bar": "baz", "balance": 7.77, "active": false}'::json"""
Expand All @@ -40,7 +41,7 @@ class CirceTests extends munit.FunSuite with roach.tests.TestHarness:

import io.circe.syntax.*

zone {
Zone {
withDB { db ?=>
val row = (512L, Json.obj("hello" := "world", "bla" := 25))
db.executeParams(
Expand All @@ -62,7 +63,7 @@ class CirceTests extends munit.FunSuite with roach.tests.TestHarness:

case class Testi(hello: String, bla: Int) derives io.circe.Codec.AsObject

zone {
Zone {
withDB { db ?=>
val row = (1024L, Testi("yo", 152))

Expand All @@ -83,7 +84,7 @@ class CirceTests extends munit.FunSuite with roach.tests.TestHarness:
case class Top(bar: String, balance: Double, active: Boolean)
derives io.circe.Codec.AsObject

zone {
Zone {
withDB { db ?=>
val q =
"""SELECT '{"bar": "baz", "balance": 7.77, "active": false}'::json"""
Expand Down
Loading
Loading