mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
scalafmtAll
This commit is contained in:
@ -15,7 +15,10 @@ sealed trait AddResult {
|
||||
object AddResult {
|
||||
|
||||
def fromUpdate(e: Either[Throwable, Int]): AddResult =
|
||||
e.fold(Failure, n => if (n > 0) Success else Failure(new Exception("No rows updated")))
|
||||
e.fold(
|
||||
Failure,
|
||||
n => if (n > 0) Success else Failure(new Exception("No rows updated"))
|
||||
)
|
||||
|
||||
case object Success extends AddResult {
|
||||
def toEither = Right(())
|
||||
|
@ -88,7 +88,6 @@ trait DoobieMeta extends EmilDoobieMeta {
|
||||
implicit val metaLanguage: Meta[Language] =
|
||||
Meta[String].imap(Language.unsafe)(_.iso3)
|
||||
|
||||
|
||||
implicit val metaCalEvent: Meta[CalEvent] =
|
||||
Meta[String].timap(CalEvent.unsafe)(_.asString)
|
||||
}
|
||||
|
@ -27,7 +27,9 @@ trait DoobieSyntax {
|
||||
and(f0 :: fs.toList)
|
||||
|
||||
def or(fs: Seq[Fragment]): Fragment =
|
||||
Fragment.const(" (") ++ fs.reduce(_ ++ Fragment.const(" OR ") ++ _) ++ Fragment.const(") ")
|
||||
Fragment.const(" (") ++ fs.reduce(_ ++ Fragment.const(" OR ") ++ _) ++ Fragment.const(
|
||||
") "
|
||||
)
|
||||
def or(f0: Fragment, fs: Fragment*): Fragment =
|
||||
or(f0 :: fs.toList)
|
||||
|
||||
@ -42,7 +44,9 @@ trait DoobieSyntax {
|
||||
fr"ORDER BY" ++ commas(c0 :: cs.toList)
|
||||
|
||||
def updateRow(table: Fragment, where: Fragment, setter: Fragment): Fragment =
|
||||
Fragment.const("UPDATE ") ++ table ++ Fragment.const(" SET ") ++ setter ++ this.where(where)
|
||||
Fragment.const("UPDATE ") ++ table ++ Fragment.const(" SET ") ++ setter ++ this.where(
|
||||
where
|
||||
)
|
||||
|
||||
def insertRow(table: Fragment, cols: List[Column], vals: Fragment): Fragment =
|
||||
Fragment.const("INSERT INTO ") ++ table ++ Fragment.const(" (") ++
|
||||
@ -66,15 +70,17 @@ trait DoobieSyntax {
|
||||
Fragment.const(") FROM ") ++ table ++ this.where(where)
|
||||
|
||||
def selectCount(col: Column, table: Fragment, where: Fragment): Fragment =
|
||||
Fragment.const("SELECT COUNT(") ++ col.f ++ Fragment.const(") FROM ") ++ table ++ this.where(
|
||||
where
|
||||
)
|
||||
Fragment.const("SELECT COUNT(") ++ col.f ++ Fragment.const(") FROM ") ++ table ++ this
|
||||
.where(
|
||||
where
|
||||
)
|
||||
|
||||
def deleteFrom(table: Fragment, where: Fragment): Fragment =
|
||||
fr"DELETE FROM" ++ table ++ this.where(where)
|
||||
|
||||
def withCTE(ps: (String, Fragment)*): Fragment = {
|
||||
val subsel: Seq[Fragment] = ps.map(p => Fragment.const(p._1) ++ fr"AS (" ++ p._2 ++ fr")")
|
||||
val subsel: Seq[Fragment] =
|
||||
ps.map(p => Fragment.const(p._1) ++ fr"AS (" ++ p._2 ++ fr")")
|
||||
fr"WITH" ++ commas(subsel)
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,15 @@ import docspell.store.{AddResult, JdbcConfig, Store}
|
||||
import doobie._
|
||||
import doobie.implicits._
|
||||
|
||||
final class StoreImpl[F[_]: Effect](jdbc: JdbcConfig, xa: Transactor[F]) extends Store[F] {
|
||||
final class StoreImpl[F[_]: Effect](jdbc: JdbcConfig, xa: Transactor[F])
|
||||
extends Store[F] {
|
||||
val bitpeaceCfg =
|
||||
BitpeaceConfig("filemeta", "filechunk", TikaMimetypeDetect, Ident.randomId[F].map(_.id))
|
||||
BitpeaceConfig(
|
||||
"filemeta",
|
||||
"filechunk",
|
||||
TikaMimetypeDetect,
|
||||
Ident.randomId[F].map(_.id)
|
||||
)
|
||||
|
||||
def migrate: F[Int] =
|
||||
FlywayMigrate.run[F](jdbc)
|
||||
|
@ -15,7 +15,9 @@ object FlywayMigrate {
|
||||
val name = if (dbtype == "h2") "postgresql" else dbtype
|
||||
List(s"classpath:db/migration/${name}")
|
||||
case None =>
|
||||
logger.warn(s"Cannot read database name from jdbc url: ${jdbc.url}. Go with PostgreSQL")
|
||||
logger.warn(
|
||||
s"Cannot read database name from jdbc url: ${jdbc.url}. Go with PostgreSQL"
|
||||
)
|
||||
List("classpath:db/postgresql")
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ object QAttachment {
|
||||
.foldMonoid
|
||||
} yield n + f
|
||||
|
||||
def deleteArchive[F[_]: Sync](store: Store[F])(attachId: Ident): F[Int] = {
|
||||
def deleteArchive[F[_]: Sync](store: Store[F])(attachId: Ident): F[Int] =
|
||||
(for {
|
||||
aa <- OptionT(store.transact(RAttachmentArchive.findById(attachId)))
|
||||
n <- OptionT.liftF(store.transact(RAttachmentArchive.deleteAll(aa.fileId)))
|
||||
@ -64,7 +64,6 @@ object QAttachment {
|
||||
.drain
|
||||
)
|
||||
} yield n).getOrElse(0)
|
||||
}
|
||||
|
||||
def deleteItemAttachments[F[_]: Sync](
|
||||
store: Store[F]
|
||||
|
@ -10,7 +10,12 @@ import docspell.common.ContactKind
|
||||
|
||||
object QCollective {
|
||||
|
||||
case class InsightData(incoming: Int, outgoing: Int, bytes: Long, tags: Map[String, Int])
|
||||
case class InsightData(
|
||||
incoming: Int,
|
||||
outgoing: Int,
|
||||
bytes: Long,
|
||||
tags: Map[String, Int]
|
||||
)
|
||||
|
||||
def getInsights(coll: Ident): ConnectionIO[InsightData] = {
|
||||
val IC = RItem.Columns
|
||||
@ -49,7 +54,9 @@ object QCollective {
|
||||
fr"count(" ++ RC.itemId.prefix("r").f ++ fr")"
|
||||
) ++
|
||||
fr"FROM" ++ RTagItem.table ++ fr"r" ++
|
||||
fr"INNER JOIN" ++ RTag.table ++ fr"t ON" ++ RC.tagId.prefix("r").is(TC.tid.prefix("t")) ++
|
||||
fr"INNER JOIN" ++ RTag.table ++ fr"t ON" ++ RC.tagId
|
||||
.prefix("r")
|
||||
.is(TC.tid.prefix("t")) ++
|
||||
fr"WHERE" ++ TC.cid.prefix("t").is(coll) ++
|
||||
fr"GROUP BY" ++ TC.name.prefix("t").f
|
||||
|
||||
|
@ -24,8 +24,8 @@ object QItem {
|
||||
inReplyTo: Option[IdRef],
|
||||
tags: Vector[RTag],
|
||||
attachments: Vector[(RAttachment, FileMeta)],
|
||||
sources: Vector[(RAttachmentSource, FileMeta)],
|
||||
archives: Vector[(RAttachmentArchive, FileMeta)]
|
||||
sources: Vector[(RAttachmentSource, FileMeta)],
|
||||
archives: Vector[(RAttachmentArchive, FileMeta)]
|
||||
) {
|
||||
|
||||
def filterCollective(coll: Ident): Option[ItemData] =
|
||||
@ -75,8 +75,8 @@ object QItem {
|
||||
)
|
||||
]
|
||||
.option
|
||||
val attachs = RAttachment.findByItemWithMeta(id)
|
||||
val sources = RAttachmentSource.findByItemWithMeta(id)
|
||||
val attachs = RAttachment.findByItemWithMeta(id)
|
||||
val sources = RAttachmentSource.findByItemWithMeta(id)
|
||||
val archives = RAttachmentArchive.findByItemWithMeta(id)
|
||||
|
||||
val tags = RTag.findByItem(id)
|
||||
@ -87,7 +87,9 @@ object QItem {
|
||||
srcs <- sources
|
||||
arch <- archives
|
||||
ts <- tags
|
||||
} yield data.map(d => ItemData(d._1, d._2, d._3, d._4, d._5, d._6, ts, att, srcs, arch))
|
||||
} yield data.map(d =>
|
||||
ItemData(d._1, d._2, d._3, d._4, d._5, d._6, ts, att, srcs, arch)
|
||||
)
|
||||
}
|
||||
|
||||
case class ListItem(
|
||||
|
@ -17,13 +17,19 @@ object QJob {
|
||||
|
||||
def takeNextJob[F[_]: Effect](
|
||||
store: Store[F]
|
||||
)(priority: Ident => F[Priority], worker: Ident, retryPause: Duration): F[Option[RJob]] =
|
||||
)(
|
||||
priority: Ident => F[Priority],
|
||||
worker: Ident,
|
||||
retryPause: Duration
|
||||
): F[Option[RJob]] =
|
||||
Stream
|
||||
.range(0, 10)
|
||||
.evalMap(n => takeNextJob1(store)(priority, worker, retryPause, n))
|
||||
.evalTap { x =>
|
||||
if (x.isLeft)
|
||||
logger.fdebug[F]("Cannot mark job, probably due to concurrent updates. Will retry.")
|
||||
logger.fdebug[F](
|
||||
"Cannot mark job, probably due to concurrent updates. Will retry."
|
||||
)
|
||||
else ().pure[F]
|
||||
}
|
||||
.find(_.isRight)
|
||||
@ -54,7 +60,9 @@ object QJob {
|
||||
} yield if (n == 1) Right(job) else Left(()))
|
||||
|
||||
for {
|
||||
_ <- logger.ftrace[F](s"About to take next job (worker ${worker.id}), try $currentTry")
|
||||
_ <- logger.ftrace[F](
|
||||
s"About to take next job (worker ${worker.id}), try $currentTry"
|
||||
)
|
||||
now <- Timestamp.current[F]
|
||||
group <- store.transact(selectNextGroup(worker, now, retryPause))
|
||||
_ <- logger.ftrace[F](s"Choose group ${group.map(_.id)}")
|
||||
@ -66,7 +74,8 @@ object QJob {
|
||||
_ <- logger.ftrace[F](s"Found job: ${job.map(_.info)}")
|
||||
res <- job.traverse(j => markJob(j))
|
||||
} yield res.map(_.map(_.some)).getOrElse {
|
||||
if (group.isDefined) Left(()) // if a group was found, but no job someone else was faster
|
||||
if (group.isDefined)
|
||||
Left(()) // if a group was found, but no job someone else was faster
|
||||
else Right(None)
|
||||
}
|
||||
}
|
||||
@ -103,7 +112,9 @@ object QJob {
|
||||
union
|
||||
.query[Ident]
|
||||
.to[List]
|
||||
.map(_.headOption) // either one or two results, but may be empty if RJob table is empty
|
||||
.map(
|
||||
_.headOption
|
||||
) // either one or two results, but may be empty if RJob table is empty
|
||||
}
|
||||
|
||||
def selectNextJob(
|
||||
@ -119,15 +130,19 @@ object QJob {
|
||||
val waiting: JobState = JobState.Waiting
|
||||
val stuck: JobState = JobState.Stuck
|
||||
|
||||
val stuckTrigger = coalesce(JC.startedmillis.f, sql"${now.toMillis}") ++ fr"+" ++ power2(
|
||||
JC.retries
|
||||
) ++ fr"* ${initialPause.millis}"
|
||||
val stuckTrigger =
|
||||
coalesce(JC.startedmillis.f, sql"${now.toMillis}") ++ fr"+" ++ power2(
|
||||
JC.retries
|
||||
) ++ fr"* ${initialPause.millis}"
|
||||
val sql = selectSimple(
|
||||
JC.all,
|
||||
RJob.table,
|
||||
and(
|
||||
JC.group.is(group),
|
||||
or(JC.state.is(waiting), and(JC.state.is(stuck), stuckTrigger ++ fr"< ${now.toMillis}"))
|
||||
or(
|
||||
JC.state.is(waiting),
|
||||
and(JC.state.is(stuck), stuckTrigger ++ fr"< ${now.toMillis}")
|
||||
)
|
||||
)
|
||||
) ++
|
||||
orderBy(JC.state.asc, psort, JC.submitted.asc) ++
|
||||
@ -189,7 +204,9 @@ object QJob {
|
||||
def findAll[F[_]: Effect](ids: Seq[Ident], store: Store[F]): F[Vector[RJob]] =
|
||||
store.transact(RJob.findFromIds(ids))
|
||||
|
||||
def queueStateSnapshot(collective: Ident): Stream[ConnectionIO, (RJob, Vector[RJobLog])] = {
|
||||
def queueStateSnapshot(
|
||||
collective: Ident
|
||||
): Stream[ConnectionIO, (RJob, Vector[RJobLog])] = {
|
||||
val JC = RJob.Columns
|
||||
val waiting: Set[JobState] = Set(JobState.Waiting, JobState.Stuck, JobState.Scheduled)
|
||||
val running: Set[JobState] = Set(JobState.Running)
|
||||
|
@ -15,7 +15,11 @@ trait JobQueue[F[_]] {
|
||||
|
||||
def insertAll(jobs: Seq[RJob]): F[Unit]
|
||||
|
||||
def nextJob(prio: Ident => F[Priority], worker: Ident, retryPause: Duration): F[Option[RJob]]
|
||||
def nextJob(
|
||||
prio: Ident => F[Priority],
|
||||
worker: Ident,
|
||||
retryPause: Duration
|
||||
): F[Option[RJob]]
|
||||
}
|
||||
|
||||
object JobQueue {
|
||||
@ -29,14 +33,16 @@ object JobQueue {
|
||||
worker: Ident,
|
||||
retryPause: Duration
|
||||
): F[Option[RJob]] =
|
||||
logger.ftrace("Select next job") *> QJob.takeNextJob(store)(prio, worker, retryPause)
|
||||
logger
|
||||
.ftrace("Select next job") *> QJob.takeNextJob(store)(prio, worker, retryPause)
|
||||
|
||||
def insert(job: RJob): F[Unit] =
|
||||
store
|
||||
.transact(RJob.insert(job))
|
||||
.flatMap { n =>
|
||||
if (n != 1)
|
||||
Effect[F].raiseError(new Exception(s"Inserting job failed. Update count: $n"))
|
||||
Effect[F]
|
||||
.raiseError(new Exception(s"Inserting job failed. Update count: $n"))
|
||||
else ().pure[F]
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,7 @@ object Marked {
|
||||
|
||||
final case object NotMarkable extends Marked[Nothing]
|
||||
|
||||
|
||||
def found[A](v: A): Marked[A] = Found(v)
|
||||
def notFound[A]: Marked[A] = NotFound
|
||||
def notFound[A]: Marked[A] = NotFound
|
||||
def notMarkable[A]: Marked[A] = NotMarkable
|
||||
}
|
||||
|
@ -38,7 +38,11 @@ object RAttachment {
|
||||
fr"${v.id},${v.itemId},${v.fileId.id},${v.position},${v.created},${v.name}"
|
||||
).update.run
|
||||
|
||||
def updateFileIdAndName(attachId: Ident, fId: Ident, fname: Option[String]): ConnectionIO[Int] =
|
||||
def updateFileIdAndName(
|
||||
attachId: Ident,
|
||||
fId: Ident,
|
||||
fname: Option[String]
|
||||
): ConnectionIO[Int] =
|
||||
updateRow(table, id.is(attachId), commas(fileId.setTo(fId), name.setTo(fname))).update.run
|
||||
|
||||
def updatePosition(attachId: Ident, pos: Int): ConnectionIO[Int] =
|
||||
@ -55,13 +59,17 @@ object RAttachment {
|
||||
val aFileMeta = fileId.prefix("a")
|
||||
val mId = RFileMeta.Columns.id.prefix("m")
|
||||
|
||||
val from = table ++ fr"a INNER JOIN" ++ RFileMeta.table ++ fr"m ON" ++ aFileMeta.is(mId)
|
||||
val from =
|
||||
table ++ fr"a INNER JOIN" ++ RFileMeta.table ++ fr"m ON" ++ aFileMeta.is(mId)
|
||||
val cond = aId.is(attachId)
|
||||
|
||||
selectSimple(cols, from, cond).query[FileMeta].option
|
||||
}
|
||||
|
||||
def findByIdAndCollective(attachId: Ident, collective: Ident): ConnectionIO[Option[RAttachment]] =
|
||||
def findByIdAndCollective(
|
||||
attachId: Ident,
|
||||
collective: Ident
|
||||
): ConnectionIO[Option[RAttachment]] =
|
||||
selectSimple(
|
||||
all.map(_.prefix("a")),
|
||||
table ++ fr"a," ++ RItem.table ++ fr"i",
|
||||
@ -75,7 +83,10 @@ object RAttachment {
|
||||
def findByItem(id: Ident): ConnectionIO[Vector[RAttachment]] =
|
||||
selectSimple(all, table, itemId.is(id)).query[RAttachment].to[Vector]
|
||||
|
||||
def findByItemAndCollective(id: Ident, coll: Ident): ConnectionIO[Vector[RAttachment]] = {
|
||||
def findByItemAndCollective(
|
||||
id: Ident,
|
||||
coll: Ident
|
||||
): ConnectionIO[Vector[RAttachment]] = {
|
||||
val q = selectSimple(all.map(_.prefix("a")), table ++ fr"a", Fragment.empty) ++
|
||||
fr"INNER JOIN" ++ RItem.table ++ fr"i ON" ++ RItem.Columns.id
|
||||
.prefix("i")
|
||||
@ -97,8 +108,9 @@ object RAttachment {
|
||||
val iId = RItem.Columns.id.prefix("i")
|
||||
val iColl = RItem.Columns.cid.prefix("i")
|
||||
|
||||
val from = table ++ fr"a INNER JOIN" ++ RFileMeta.table ++ fr"m ON" ++ afileMeta.is(mId) ++
|
||||
fr"INNER JOIN" ++ RItem.table ++ fr"i ON" ++ aItem.is(iId)
|
||||
val from =
|
||||
table ++ fr"a INNER JOIN" ++ RFileMeta.table ++ fr"m ON" ++ afileMeta.is(mId) ++
|
||||
fr"INNER JOIN" ++ RItem.table ++ fr"i ON" ++ aItem.is(iId)
|
||||
val cond = Seq(aItem.is(id), iColl.is(coll))
|
||||
|
||||
selectSimple(cols, from, and(cond)).query[(RAttachment, FileMeta)].to[Vector]
|
||||
|
@ -23,11 +23,11 @@ object RAttachmentArchive {
|
||||
val table = fr"attachment_archive"
|
||||
|
||||
object Columns {
|
||||
val id = Column("id")
|
||||
val fileId = Column("file_id")
|
||||
val name = Column("filename")
|
||||
val id = Column("id")
|
||||
val fileId = Column("file_id")
|
||||
val name = Column("filename")
|
||||
val messageId = Column("message_id")
|
||||
val created = Column("created")
|
||||
val created = Column("created")
|
||||
|
||||
val all = List(id, fileId, name, messageId, created)
|
||||
}
|
||||
|
@ -20,7 +20,8 @@ case class RAttachmentMeta(
|
||||
}
|
||||
|
||||
object RAttachmentMeta {
|
||||
def empty(attachId: Ident) = RAttachmentMeta(attachId, None, Nil, MetaProposalList.empty)
|
||||
def empty(attachId: Ident) =
|
||||
RAttachmentMeta(attachId, None, Nil, MetaProposalList.empty)
|
||||
|
||||
val table = fr"attachmentmeta"
|
||||
|
||||
|
@ -63,7 +63,9 @@ object RAttachmentSource {
|
||||
selectSimple(all.map(_.prefix("a")), from, where).query[RAttachmentSource].option
|
||||
}
|
||||
|
||||
def findByItemWithMeta(id: Ident): ConnectionIO[Vector[(RAttachmentSource, FileMeta)]] = {
|
||||
def findByItemWithMeta(
|
||||
id: Ident
|
||||
): ConnectionIO[Vector[(RAttachmentSource, FileMeta)]] = {
|
||||
import bitpeace.sql._
|
||||
|
||||
val aId = Columns.id.prefix("a")
|
||||
|
@ -7,7 +7,12 @@ import doobie._
|
||||
import doobie.implicits._
|
||||
import fs2.Stream
|
||||
|
||||
case class RCollective(id: Ident, state: CollectiveState, language: Language, created: Timestamp)
|
||||
case class RCollective(
|
||||
id: Ident,
|
||||
state: CollectiveState,
|
||||
language: Language,
|
||||
created: Timestamp
|
||||
)
|
||||
|
||||
object RCollective {
|
||||
|
||||
|
@ -40,7 +40,9 @@ object RInvitation {
|
||||
deleteFrom(table, id.is(invite)).update.run
|
||||
|
||||
def useInvite(invite: Ident, minCreated: Timestamp): ConnectionIO[Boolean] = {
|
||||
val get = selectCount(id, table, and(id.is(invite), created.isGt(minCreated))).query[Int].unique
|
||||
val get = selectCount(id, table, and(id.is(invite), created.isGt(minCreated)))
|
||||
.query[Int]
|
||||
.unique
|
||||
for {
|
||||
inv <- get
|
||||
_ <- delete(invite)
|
||||
|
@ -113,7 +113,11 @@ object RItem {
|
||||
def updateState(itemId: Ident, itemState: ItemState): ConnectionIO[Int] =
|
||||
for {
|
||||
t <- currentTime
|
||||
n <- updateRow(table, id.is(itemId), commas(state.setTo(itemState), updated.setTo(t))).update.run
|
||||
n <- updateRow(
|
||||
table,
|
||||
id.is(itemId),
|
||||
commas(state.setTo(itemState), updated.setTo(t))
|
||||
).update.run
|
||||
} yield n
|
||||
|
||||
def updateStateForCollective(
|
||||
@ -160,7 +164,11 @@ object RItem {
|
||||
).update.run
|
||||
} yield n
|
||||
|
||||
def updateCorrPerson(itemId: Ident, coll: Ident, person: Option[Ident]): ConnectionIO[Int] =
|
||||
def updateCorrPerson(
|
||||
itemId: Ident,
|
||||
coll: Ident,
|
||||
person: Option[Ident]
|
||||
): ConnectionIO[Int] =
|
||||
for {
|
||||
t <- currentTime
|
||||
n <- updateRow(
|
||||
@ -180,7 +188,11 @@ object RItem {
|
||||
).update.run
|
||||
} yield n
|
||||
|
||||
def updateConcPerson(itemId: Ident, coll: Ident, person: Option[Ident]): ConnectionIO[Int] =
|
||||
def updateConcPerson(
|
||||
itemId: Ident,
|
||||
coll: Ident,
|
||||
person: Option[Ident]
|
||||
): ConnectionIO[Int] =
|
||||
for {
|
||||
t <- currentTime
|
||||
n <- updateRow(
|
||||
@ -200,7 +212,11 @@ object RItem {
|
||||
).update.run
|
||||
} yield n
|
||||
|
||||
def updateConcEquip(itemId: Ident, coll: Ident, equip: Option[Ident]): ConnectionIO[Int] =
|
||||
def updateConcEquip(
|
||||
itemId: Ident,
|
||||
coll: Ident,
|
||||
equip: Option[Ident]
|
||||
): ConnectionIO[Int] =
|
||||
for {
|
||||
t <- currentTime
|
||||
n <- updateRow(
|
||||
@ -250,7 +266,11 @@ object RItem {
|
||||
).update.run
|
||||
} yield n
|
||||
|
||||
def updateDueDate(itemId: Ident, coll: Ident, date: Option[Timestamp]): ConnectionIO[Int] =
|
||||
def updateDueDate(
|
||||
itemId: Ident,
|
||||
coll: Ident,
|
||||
date: Option[Timestamp]
|
||||
): ConnectionIO[Int] =
|
||||
for {
|
||||
t <- currentTime
|
||||
n <- updateRow(
|
||||
|
@ -6,7 +6,13 @@ import docspell.common._
|
||||
import docspell.store.impl.Column
|
||||
import docspell.store.impl.Implicits._
|
||||
|
||||
case class RJobLog(id: Ident, jobId: Ident, level: LogLevel, created: Timestamp, message: String) {}
|
||||
case class RJobLog(
|
||||
id: Ident,
|
||||
jobId: Ident,
|
||||
level: LogLevel,
|
||||
created: Timestamp,
|
||||
message: String
|
||||
) {}
|
||||
|
||||
object RJobLog {
|
||||
|
||||
@ -26,7 +32,9 @@ object RJobLog {
|
||||
insertRow(table, all, fr"${v.id},${v.jobId},${v.level},${v.created},${v.message}").update.run
|
||||
|
||||
def findLogs(id: Ident): ConnectionIO[Vector[RJobLog]] =
|
||||
(selectSimple(all, table, jobId.is(id)) ++ orderBy(created.asc)).query[RJobLog].to[Vector]
|
||||
(selectSimple(all, table, jobId.is(id)) ++ orderBy(created.asc))
|
||||
.query[RJobLog]
|
||||
.to[Vector]
|
||||
|
||||
def deleteAll(job: Ident): ConnectionIO[Int] =
|
||||
deleteFrom(table, jobId.is(job)).update.run
|
||||
|
@ -68,7 +68,10 @@ object ROrganization {
|
||||
}
|
||||
|
||||
def existsByName(coll: Ident, oname: String): ConnectionIO[Boolean] =
|
||||
selectCount(oid, table, and(cid.is(coll), name.is(oname))).query[Int].unique.map(_ > 0)
|
||||
selectCount(oid, table, and(cid.is(coll), name.is(oname)))
|
||||
.query[Int]
|
||||
.unique
|
||||
.map(_ > 0)
|
||||
|
||||
def findById(id: Ident): ConnectionIO[Option[ROrganization]] = {
|
||||
val sql = selectSimple(all, table, cid.is(id))
|
||||
@ -93,7 +96,9 @@ object ROrganization {
|
||||
val CC = RContact.Columns
|
||||
val q = fr"SELECT DISTINCT" ++ commas(oid.prefix("o").f, name.prefix("o").f) ++
|
||||
fr"FROM" ++ table ++ fr"o" ++
|
||||
fr"INNER JOIN" ++ RContact.table ++ fr"c ON" ++ CC.orgId.prefix("c").is(oid.prefix("o")) ++
|
||||
fr"INNER JOIN" ++ RContact.table ++ fr"c ON" ++ CC.orgId
|
||||
.prefix("c")
|
||||
.is(oid.prefix("o")) ++
|
||||
fr"WHERE" ++ and(
|
||||
cid.prefix("o").is(coll),
|
||||
CC.kind.prefix("c").is(contactKind),
|
||||
@ -103,7 +108,10 @@ object ROrganization {
|
||||
q.query[IdRef].to[Vector]
|
||||
}
|
||||
|
||||
def findAll(coll: Ident, order: Columns.type => Column): Stream[ConnectionIO, ROrganization] = {
|
||||
def findAll(
|
||||
coll: Ident,
|
||||
order: Columns.type => Column
|
||||
): Stream[ConnectionIO, ROrganization] = {
|
||||
val sql = selectSimple(all, table, cid.is(coll)) ++ orderBy(order(Columns).f)
|
||||
sql.query[ROrganization].stream
|
||||
}
|
||||
|
@ -71,7 +71,10 @@ object RPerson {
|
||||
}
|
||||
|
||||
def existsByName(coll: Ident, pname: String): ConnectionIO[Boolean] =
|
||||
selectCount(pid, table, and(cid.is(coll), name.is(pname))).query[Int].unique.map(_ > 0)
|
||||
selectCount(pid, table, and(cid.is(coll), name.is(pname)))
|
||||
.query[Int]
|
||||
.unique
|
||||
.map(_ > 0)
|
||||
|
||||
def findById(id: Ident): ConnectionIO[Option[RPerson]] = {
|
||||
val sql = selectSimple(all, table, cid.is(id))
|
||||
@ -103,7 +106,9 @@ object RPerson {
|
||||
val CC = RContact.Columns
|
||||
val q = fr"SELECT DISTINCT" ++ commas(pid.prefix("p").f, name.prefix("p").f) ++
|
||||
fr"FROM" ++ table ++ fr"p" ++
|
||||
fr"INNER JOIN" ++ RContact.table ++ fr"c ON" ++ CC.personId.prefix("c").is(pid.prefix("p")) ++
|
||||
fr"INNER JOIN" ++ RContact.table ++ fr"c ON" ++ CC.personId
|
||||
.prefix("c")
|
||||
.is(pid.prefix("p")) ++
|
||||
fr"WHERE" ++ and(
|
||||
cid.prefix("p").is(coll),
|
||||
CC.kind.prefix("c").is(contactKind),
|
||||
@ -114,7 +119,10 @@ object RPerson {
|
||||
q.query[IdRef].to[Vector]
|
||||
}
|
||||
|
||||
def findAll(coll: Ident, order: Columns.type => Column): Stream[ConnectionIO, RPerson] = {
|
||||
def findAll(
|
||||
coll: Ident,
|
||||
order: Columns.type => Column
|
||||
): Stream[ConnectionIO, RPerson] = {
|
||||
val sql = selectSimple(all, table, cid.is(coll)) ++ orderBy(order(Columns).f)
|
||||
sql.query[RPerson].stream
|
||||
}
|
||||
|
@ -37,7 +37,17 @@ object RSentMail {
|
||||
for {
|
||||
id <- Ident.randomId[F]
|
||||
now <- Timestamp.current[F]
|
||||
} yield RSentMail(id, uid, messageId, sender, connName, subject, recipients, body, now)
|
||||
} yield RSentMail(
|
||||
id,
|
||||
uid,
|
||||
messageId,
|
||||
sender,
|
||||
connName,
|
||||
subject,
|
||||
recipients,
|
||||
body,
|
||||
now
|
||||
)
|
||||
|
||||
def forItem(
|
||||
itemId: Ident,
|
||||
|
@ -86,7 +86,10 @@ object RSource {
|
||||
def findCollective(sourceId: Ident): ConnectionIO[Option[Ident]] =
|
||||
selectSimple(List(cid), table, sid.is(sourceId)).query[Ident].option
|
||||
|
||||
def findAll(coll: Ident, order: Columns.type => Column): ConnectionIO[Vector[RSource]] = {
|
||||
def findAll(
|
||||
coll: Ident,
|
||||
order: Columns.type => Column
|
||||
): ConnectionIO[Vector[RSource]] = {
|
||||
val sql = selectSimple(all, table, cid.is(coll)) ++ orderBy(order(Columns).f)
|
||||
sql.query[RSource].to[Vector]
|
||||
}
|
||||
|
@ -29,7 +29,11 @@ object RTag {
|
||||
|
||||
def insert(v: RTag): ConnectionIO[Int] = {
|
||||
val sql =
|
||||
insertRow(table, all, fr"${v.tagId},${v.collective},${v.name},${v.category},${v.created}")
|
||||
insertRow(
|
||||
table,
|
||||
all,
|
||||
fr"${v.tagId},${v.collective},${v.name},${v.category},${v.created}"
|
||||
)
|
||||
sql.update.run
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,8 @@ object RUser {
|
||||
val lastLogin = Column("lastlogin")
|
||||
val created = Column("created")
|
||||
|
||||
val all = List(uid, login, cid, password, state, email, loginCount, lastLogin, created)
|
||||
val all =
|
||||
List(uid, login, cid, password, state, email, loginCount, lastLogin, created)
|
||||
}
|
||||
|
||||
import Columns._
|
||||
|
@ -178,7 +178,8 @@ object RUserEmail {
|
||||
case None => Seq.empty
|
||||
})
|
||||
|
||||
(selectSimple(all.map(_.prefix("m")), from, and(cond)) ++ orderBy(mName.f)).query[RUserEmail]
|
||||
(selectSimple(all.map(_.prefix("m")), from, and(cond)) ++ orderBy(mName.f))
|
||||
.query[RUserEmail]
|
||||
}
|
||||
|
||||
def findByAccount(
|
||||
@ -198,9 +199,10 @@ object RUserEmail {
|
||||
|
||||
deleteFrom(
|
||||
table,
|
||||
fr"uid in (" ++ selectSimple(Seq(uId), RUser.table, and(cond)) ++ fr") AND" ++ name.is(
|
||||
connName
|
||||
)
|
||||
fr"uid in (" ++ selectSimple(Seq(uId), RUser.table, and(cond)) ++ fr") AND" ++ name
|
||||
.is(
|
||||
connName
|
||||
)
|
||||
).update.run
|
||||
}
|
||||
|
||||
@ -208,5 +210,8 @@ object RUserEmail {
|
||||
getByName(accId, name).map(_.isDefined)
|
||||
|
||||
def exists(userId: Ident, connName: Ident): ConnectionIO[Boolean] =
|
||||
selectCount(id, table, and(uid.is(userId), name.is(connName))).query[Int].unique.map(_ > 0)
|
||||
selectCount(id, table, and(uid.is(userId), name.is(connName)))
|
||||
.query[Int]
|
||||
.unique
|
||||
.map(_ > 0)
|
||||
}
|
||||
|
Reference in New Issue
Block a user