mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 10:28:27 +00:00
Convert more records
This commit is contained in:
@ -136,32 +136,21 @@ object RegexNerFile {
|
||||
|
||||
object Sql {
|
||||
import doobie._
|
||||
import doobie.implicits._
|
||||
import docspell.store.impl.Implicits._
|
||||
import docspell.store.impl.Column
|
||||
import docspell.store.qb.DSL._
|
||||
import docspell.store.qb._
|
||||
|
||||
def latestUpdate(collective: Ident): ConnectionIO[Option[Timestamp]] = {
|
||||
def max(col: Column, table: Fragment, cidCol: Column): Fragment =
|
||||
selectSimple(col.max ++ fr"as t", table, cidCol.is(collective))
|
||||
def max_(col: Column[_], cidCol: Column[Ident]): Select =
|
||||
Select(select(max(col).as("t")), from(col.table), cidCol === collective)
|
||||
|
||||
val equip = REquipment.as("e")
|
||||
val sql =
|
||||
List(
|
||||
max(
|
||||
ROrganization.Columns.updated,
|
||||
ROrganization.table,
|
||||
ROrganization.Columns.cid
|
||||
),
|
||||
max(RPerson.Columns.updated, RPerson.table, RPerson.Columns.cid),
|
||||
max(
|
||||
equip.updated.oldColumn,
|
||||
Fragment.const(equip.tableName),
|
||||
equip.cid.oldColumn
|
||||
)
|
||||
)
|
||||
.reduce(_ ++ fr"UNION ALL" ++ _)
|
||||
val sql = union(
|
||||
max_(ROrganization.T.updated, ROrganization.T.cid),
|
||||
max_(RPerson.T.updated, RPerson.T.cid),
|
||||
max_(REquipment.T.updated, REquipment.T.cid)
|
||||
)
|
||||
val t = Column[Timestamp]("t", TableDef(""))
|
||||
|
||||
selectSimple(fr"MAX(t)", fr"(" ++ sql ++ fr") as x", Fragment.empty)
|
||||
run(select(max(t)), fromSubSelect(sql).as("x"))
|
||||
.query[Option[Timestamp]]
|
||||
.option
|
||||
.map(_.flatten)
|
||||
|
Reference in New Issue
Block a user