Skip to content

Instantly share code, notes, and snippets.

@deusaquilus
deusaquilus / build.sbt
Created September 8, 2020 18:24
Add Snapshot OSS Quill to Build.sbt
resolvers ++= Seq(
("OSS-Snapshots" at "https://oss.sonatype.org/service/local/repositories/snapshots/content/")
)
libraryDependencies ++= Seq(
"io.getquill" %% "quill-sql" % "3.5.3-SNAPSHOT",
)
@deusaquilus
deusaquilus / Example.scala
Created December 10, 2020 20:28
Grouping into an Array with Quill Spark
case class Address(street: String, zip: Int, personName: String)
case class Person(name: String, addresses: List[String])
/*
In some Data-Models used with Spark, you may want to embed arrays into an object.
You may then want to be able to set array-properties of this kind of object when
a group-by is done. Normally this would be done in Spark using the following way
*/
val addresses: Dataset[Address] = ???
val people = addresses.groupByKey(a => a.personName).mapGroups { case (name, addresses) =>
@deusaquilus
deusaquilus / search_maven_gav.sh
Created January 5, 2021 04:35
Get maven artifacts with coordinates from central
#!/bin/bash
group=$1
artifact=$2
version=$3
# Diff like this:
# diff <(search_maven_gav.sh io.getquill 'quill-*_2.13' 3.6.0-RC2 | awk '{print $2}' | sort) <(search_maven_gav.sh io.getquill 'quill-*_2.13' 3.6.0-RC3 | awk '{print $2}' | sort)
curl -s "https://search.maven.org/solrsearch/select?rows=100&q=g:${group}+AND+a:${artifact}+AND+v:${version}" | jq --raw-output '.response.docs[] | [.g, .a, .v]|@tsv'
@deusaquilus
deusaquilus / LayerProject.scala
Last active March 12, 2021 06:42
Various Zio Bracketing Functions: TODO Check if these work in Dotty
// Provide a single Environment Has clause:
// ZLayer[Orig, E, Has[From] with Rest] => ZLayer[Orig, E, Has[To] with Rest]
def projectionWithEffect[From: Tag, To: Tag, Rest <: Has[_]: Tag, E](effect: (From, Rest) => IO[E, To]): ZLayer[Has[From] with Rest, E, Has[To] with Rest] =
(for {
from <- ZIO.service[From]
rest <- ZIO.environment[Rest]
result <- effect(from, rest)
} yield Has(result) ++ rest).toLayerMany
@deusaquilus
deusaquilus / JAsyncContextF.scala
Created March 18, 2021 18:11
Abstracting Jasync Context Effect - I can do it but really don't want to...
package io.getquill.context.jasync
import com.github.jasync.sql.db.pool.ConnectionPool
import com.github.jasync.sql.db.{ ConcreteConnection, Connection, QueryResult, RowData }
import io.getquill.context.sql.SqlContext
import io.getquill.context.sql.idiom.SqlIdiom
import io.getquill.context.{ Context, TranslateContext }
import io.getquill.monad.ScalaFutureIOMonad
import io.getquill.util.ContextLogger
import io.getquill.{ NamingStrategy, ReturnAction }
@deusaquilus
deusaquilus / example.scala
Created April 9, 2021 18:15
Need to Manually Uninline in Cases with Subclassing
// I first found this in PeopleSpec that was being used by PeoplePostgresAsyncSpec
trait PeopleSpec extends Spec {
inline def peopleInsert =
quote((p: Person) => query[Person].insert(p))
inline def couplesInsert =
quote((c: Couple) => query[Couple].insert(c))
}
// Then this stuff was used in PeoplePostgresAsyncSpec
class PeoplePostgresAsyncSpec extends PeopleSpec {
@deusaquilus
deusaquilus / stuff.scala
Created April 12, 2021 17:29
Getting printouts when writing macro-level decoders
// It's a bit complex because if you throw an error you usually don't get the result
// i.e. the place where the decoder is summoned returns the error because no decoder can be summoned from there
// [error] -- Error: /Users/aleiof/git/dotty_test/quill-sql/src/test/scala/io/getquill/QueryTest.scala:31:26
// [error] 31 | val result = ctx.run(q)
// [error] | ^^^^^^^^^^
// [error] | Decoder could not be summoned during query execution
// if you use report.warning and return something you usually get it
def decode[T: Type, ResultRow: Type](index: Expr[Int], resultRow: Expr[ResultRow])(using Quotes): Expr[T] = {
import quotes.reflect._
@deusaquilus
deusaquilus / EncodingSpec.scala
Created April 27, 2021 00:40
Postgres Async Encoding Spec with Large Encoding Entity
package io.getquill.context.sql
import java.time.LocalDate
import java.util.{ Date, UUID }
import io.getquill.context.Context
import io.getquill._
//case class EncodingTestType(value: String)
case class Number(value: String) extends AnyVal
@deusaquilus
deusaquilus / Parser.scala
Last active May 19, 2021 04:06
Delegating Parsing Function
// Say we have something like this:
case class OperationsParser(root: Parser[Ast] = Parser.empty)(override implicit val qctx: Quotes) extends Parser.Clause[Ast] with ComparisonTechniques {
def delegate: PartialFunction[Expr[_], Ast] = {
case ...
}
}
// Just do this:
case class OperationsParser(root: Parser[Ast] = Parser.empty)(override implicit val qctx: Quotes) extends Parser.Clause[Ast] with ComparisonTechniques {
def delegate: PartialFunction[Expr[_], Ast] = {
@deusaquilus
deusaquilus / BetterAstPrinter.scala
Created May 27, 2021 18:37
Trying to make qprint to print Dotty TypeTrees in AST but not working. Thinks whole thing is a TypeTree
package io.getquill.util
import io.getquill.AstPrinter
import fansi.Str
import io.getquill.ast.Renameable.{ ByStrategy, Fixed }
import io.getquill.ast.Visibility.{ Hidden, Visible }
import io.getquill.ast._
import io.getquill.quat.Quat
import io.getquill.util.Messages.QuatTrace
import pprint.{ Renderer, Tree, Truncated }