Skip to content

Instantly share code, notes, and snippets.

@deusaquilus
deusaquilus / script.sh
Created June 2, 2023 17:50
Choopy to Deusaquilus
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="[email protected]"
CORRECT_NAME="Alexander Ioffe"
CORRECT_EMAIL="[email protected]"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
@deusaquilus
deusaquilus / NestedOptionalOrientSpec.scala
Created June 2, 2022 01:39
Testing Null Option[Product] with OrientDB
package io.getquill.context.orientdb
import io.getquill.{ Insert, Literal, OrientDBSyncContext }
import io.getquill.context.encoding.OptionalNestedSpec
import io.getquill.context.orientdb.orientdb.{ resetSchema, setup }
import org.scalatest.BeforeAndAfterAll
class OptionalProductEncodingJdbcSpec extends OptionalNestedSpec with BeforeAndAfterAll {
val context: OrientDBSyncContext[Literal.type] = orientdb.testSyncDB
@deusaquilus
deusaquilus / typelevel_valuelevel.scala
Last active April 12, 2022 04:25
Cool but useless example of typelevel-valuelevel equivalence
// Type Level
type U[M[_]] = M[Int]
type Bi[A, B] = Map[A, B]
type X[A] = U[[A] =>> Bi[String, A]]
implicitly[X[Int] =:= Bi[String,Int]]
// Result: =:=[X[Int], Map[String, Int]]
// Note that this is also true: implicitly[X[java.util.Date] =:= Bi[String,Int]]
// hence this example is not very good
// Value level
@deusaquilus
deusaquilus / commands.scala
Last active February 10, 2022 22:48
ProtoQuill on Ammonite
// This will download ammonite and put into /usr/local/bin. Command is `amm3`, if you already have `amm` it won't be affected
// sudo sh -c '(echo "#!/usr/bin/env sh" && curl -L https://github.com/com-lihaoyi/Ammonite/releases/download/2.5.2/3.1-2.5.2) > /usr/local/bin/amm3 && chmod +x /usr/local/bin/amm3' && amm3
import $ivy.`io.getquill::quill-sql:3.16.3.Beta2.3`
// https://repo1.maven.org/maven2/io/getquill/quill-sql_3/3.16.3.Beta2.3/quill-sql_3-3.16.3.Beta2.3.pom...
// import $ivy.$
import io.getquill._
// import io.getquill._
@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 }
@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 / 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 / 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 / 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 / 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 }