mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-03-28 01:35:06 +00:00
Merge pull request #2355 from eikek/update-doobie
Update doobie to 1.0.0-RC4
This commit is contained in:
commit
e3f2fcb3f7
@ -9,17 +9,9 @@ package docspell.ftspsql
|
||||
import docspell.common._
|
||||
|
||||
import doobie._
|
||||
import doobie.util.log.Success
|
||||
|
||||
trait DoobieMeta {
|
||||
|
||||
implicit val sqlLogging: LogHandler = LogHandler {
|
||||
case e @ Success(_, _, _, _) =>
|
||||
DoobieMeta.logger.debug("SQL " + e)
|
||||
case e =>
|
||||
DoobieMeta.logger.error(s"SQL Failure: $e")
|
||||
}
|
||||
|
||||
implicit val metaIdent: Meta[Ident] =
|
||||
Meta[String].timap(Ident.unsafe)(_.id)
|
||||
|
||||
@ -29,7 +21,3 @@ trait DoobieMeta {
|
||||
implicit val metaCollectiveId: Meta[CollectiveId] =
|
||||
Meta[Long].timap(CollectiveId(_))(_.value)
|
||||
}
|
||||
|
||||
object DoobieMeta {
|
||||
private val logger = org.log4s.getLogger
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import fs2.Stream
|
||||
import docspell.common._
|
||||
import docspell.ftsclient._
|
||||
import docspell.logging.Logger
|
||||
import docspell.store.impl.DoobieLogging
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource
|
||||
import doobie._
|
||||
@ -157,7 +158,8 @@ object PsqlFtsClient {
|
||||
ds.setPassword(cfg.password.pass)
|
||||
ds.setDriverClassName("org.postgresql.Driver")
|
||||
}
|
||||
xa = HikariTransactor[F](ds, connectEC)
|
||||
logh = DoobieLogging[F](docspell.logging.getLogger[F])
|
||||
xa = HikariTransactor[F](ds, connectEC, Some(logh))
|
||||
|
||||
pc = new PsqlFtsClient[F](cfg, xa)
|
||||
} yield pc
|
||||
|
@ -9,6 +9,7 @@ package db.migration.common
|
||||
import cats.effect.IO
|
||||
|
||||
import docspell.logging.Logger
|
||||
import docspell.store.impl.DoobieLogging
|
||||
|
||||
import doobie.util.transactor.{Strategy, Transactor}
|
||||
import org.flywaydb.core.api.migration.Context
|
||||
@ -18,7 +19,8 @@ trait TransactorSupport {
|
||||
def logger: Logger[IO]
|
||||
|
||||
def mkTransactor(ctx: Context): Transactor[IO] = {
|
||||
val xa = Transactor.fromConnection[IO](ctx.getConnection)
|
||||
val logHandler = DoobieLogging[IO](logger)
|
||||
val xa = Transactor.fromConnection[IO](ctx.getConnection, Some(logHandler))
|
||||
logger.asUnsafe.info(s"Creating transactor for db migrations from connection: $xa")
|
||||
Transactor.strategy.set(xa, Strategy.void) // transactions are handled by flyway
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import fs2._
|
||||
import fs2.io.file.Files
|
||||
|
||||
import docspell.store.file.{FileRepository, FileRepositoryConfig}
|
||||
import docspell.store.impl.StoreImpl
|
||||
import docspell.store.impl.{DoobieLogging, StoreImpl}
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource
|
||||
import doobie._
|
||||
@ -60,8 +60,9 @@ object Store {
|
||||
ds.setPassword(jdbc.password)
|
||||
ds.setDriverClassName(jdbc.dbms.driverClass)
|
||||
}
|
||||
xa = HikariTransactor(ds, connectEC)
|
||||
fr = FileRepository(xa, ds, fileRepoConfig, true)
|
||||
logh = DoobieLogging[F](docspell.logging.getLogger[F])
|
||||
xa = HikariTransactor[F](ds, connectEC, Some(logh))
|
||||
fr = FileRepository(xa, ds, fileRepoConfig, withAttributeStore = true)
|
||||
st = new StoreImpl[F](fr, jdbc, schemaCfg, ds, xa)
|
||||
_ <- Resource.eval(st.migrate)
|
||||
} yield st
|
||||
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2020 Eike K. & Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package docspell.store.impl
|
||||
|
||||
import cats.Applicative
|
||||
import cats.syntax.all._
|
||||
|
||||
import docspell.logging.Logger
|
||||
import docspell.store.impl.DoobieLogging.LogLabel
|
||||
|
||||
import doobie.util.log
|
||||
import doobie.util.log.LogHandler
|
||||
|
||||
final class DoobieLogging[F[_]: Applicative](logger: Logger[F]) extends LogHandler[F] {
|
||||
override def run(logEvent: log.LogEvent): F[Unit] =
|
||||
if (LogLabel.fromEvent(logEvent).contains(LogLabel.Silent)) ().pure[F]
|
||||
else
|
||||
logEvent match {
|
||||
case log.Success(sql, args, _, exec, _) =>
|
||||
logger.trace(s"SQL: $sql ($args) executed in $exec")
|
||||
|
||||
case log.ProcessingFailure(sql, args, _, _, _, failure) =>
|
||||
logger.error(failure)(s"SQL processing failed: $sql ($args)")
|
||||
|
||||
case log.ExecFailure(sql, args, _, _, failure) =>
|
||||
logger.error(failure)(s"SQL exec failed: $sql ($args)")
|
||||
}
|
||||
}
|
||||
|
||||
object DoobieLogging {
|
||||
|
||||
def apply[F[_]: Applicative](logger: Logger[F]): DoobieLogging[F] =
|
||||
new DoobieLogging[F](logger)
|
||||
|
||||
sealed trait LogLabel extends Product {
|
||||
lazy val name: String = productPrefix.toLowerCase
|
||||
}
|
||||
object LogLabel {
|
||||
case object Silent extends LogLabel
|
||||
|
||||
val all: List[LogLabel] = List(Silent)
|
||||
|
||||
def fromString(str: String): Option[LogLabel] =
|
||||
all.find(_.name.equalsIgnoreCase(str))
|
||||
|
||||
def fromEvent(e: log.LogEvent): Option[LogLabel] =
|
||||
fromString(e.label)
|
||||
}
|
||||
}
|
@ -22,21 +22,12 @@ import binny.BinaryId
|
||||
import com.github.eikek.calev.CalEvent
|
||||
import doobie._
|
||||
import doobie.implicits.legacy.instant._
|
||||
import doobie.util.log.Success
|
||||
import emil.doobie.EmilDoobieMeta
|
||||
import io.circe.Json
|
||||
import io.circe.{Decoder, Encoder}
|
||||
import io.circe.{Decoder, Encoder, Json}
|
||||
import scodec.bits.ByteVector
|
||||
|
||||
trait DoobieMeta extends EmilDoobieMeta {
|
||||
|
||||
implicit val sqlLogging: LogHandler = LogHandler {
|
||||
case e @ Success(_, _, _, _) =>
|
||||
DoobieMeta.logger.trace(s"SQL: $e")
|
||||
case e =>
|
||||
DoobieMeta.logger.warn(s"SQL Failure: $e")
|
||||
}
|
||||
|
||||
def jsonMeta[A](implicit d: Decoder[A], e: Encoder[A]): Meta[A] =
|
||||
Meta[String].imap(str => str.parseJsonAs[A].fold(ex => throw ex, identity))(a =>
|
||||
e.apply(a).noSpaces
|
||||
@ -180,12 +171,9 @@ trait DoobieMeta extends EmilDoobieMeta {
|
||||
}
|
||||
|
||||
object DoobieMeta extends DoobieMeta {
|
||||
import org.log4s._
|
||||
private val logger = getLogger
|
||||
|
||||
private def parseJsonUnsafe(str: String): Json =
|
||||
io.circe.parser
|
||||
.parse(str)
|
||||
.fold(throw _, identity)
|
||||
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ final class StoreImpl[F[_]: Async: Files](
|
||||
) extends Store[F] {
|
||||
private[this] val xa = transactor
|
||||
|
||||
val dbms = jdbc.dbms
|
||||
val dbms: Db = jdbc.dbms
|
||||
|
||||
def createFileRepository(
|
||||
cfg: FileRepositoryConfig,
|
||||
|
@ -8,7 +8,7 @@ package docspell.store.qb
|
||||
|
||||
import cats.data.{NonEmptyList => Nel}
|
||||
|
||||
import docspell.store.impl.DoobieMeta
|
||||
import docspell.store.impl.{DoobieLogging, DoobieMeta}
|
||||
import docspell.store.qb.impl._
|
||||
|
||||
import doobie._
|
||||
@ -34,7 +34,9 @@ object DML extends DoobieMeta {
|
||||
cols: Nel[Column[_]],
|
||||
values: Fragment
|
||||
): ConnectionIO[Int] =
|
||||
insertFragment(table, cols, List(values)).update(LogHandler.nop).run
|
||||
insertFragment(table, cols, List(values))
|
||||
.updateWithLabel(DoobieLogging.LogLabel.Silent.name)
|
||||
.run
|
||||
|
||||
def insertMany(
|
||||
table: TableDef,
|
||||
|
@ -16,8 +16,8 @@ object Dependencies {
|
||||
val CirceGenericExtrasVersion = "0.14.3"
|
||||
val CirceYamlVersion = "0.15.1"
|
||||
val ClipboardJsVersion = "2.0.11"
|
||||
val DoobieVersion = "1.0.0-RC2"
|
||||
val EmilVersion = "0.13.0"
|
||||
val DoobieVersion = "1.0.0-RC4"
|
||||
val EmilVersion = "0.15.0"
|
||||
val FlexmarkVersion = "0.64.8"
|
||||
val FlywayVersion = "10.0.0"
|
||||
val Fs2Version = "3.9.2"
|
||||
|
Loading…
x
Reference in New Issue
Block a user