From 278b1c22c9953239da346e9db49b22c920f4b88b Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Mon, 14 Dec 2020 19:18:14 +0100 Subject: [PATCH] Remove old code --- .../scala/docspell/store/impl/Column.scala | 139 ------------------ .../docspell/store/impl/DoobieSyntax.scala | 103 ------------- .../scala/docspell/store/impl/Implicits.scala | 15 -- .../scala/docspell/store/queries/QItem.scala | 14 +- .../docspell/store/records/RAttachment.scala | 14 -- .../store/records/RAttachmentArchive.scala | 13 -- .../store/records/RAttachmentMeta.scala | 12 -- .../store/records/RAttachmentPreview.scala | 11 -- .../store/records/RAttachmentSource.scala | 11 -- .../scala/docspell/store/records/RItem.scala | 42 ------ 10 files changed, 4 insertions(+), 370 deletions(-) delete mode 100644 modules/store/src/main/scala/docspell/store/impl/Column.scala delete mode 100644 modules/store/src/main/scala/docspell/store/impl/DoobieSyntax.scala delete mode 100644 modules/store/src/main/scala/docspell/store/impl/Implicits.scala diff --git a/modules/store/src/main/scala/docspell/store/impl/Column.scala b/modules/store/src/main/scala/docspell/store/impl/Column.scala deleted file mode 100644 index 4dec4d6c..00000000 --- a/modules/store/src/main/scala/docspell/store/impl/Column.scala +++ /dev/null @@ -1,139 +0,0 @@ -package docspell.store.impl - -import cats.data.NonEmptyList - -import docspell.store.impl.DoobieSyntax._ - -import doobie._ -import doobie.implicits._ - -case class Column(name: String, ns: String = "", alias: String = "") { - - val f = { - val col = - if (ns.isEmpty) Fragment.const(name) - else Fragment.const(ns + "." + name) - if (alias.isEmpty) col - else col ++ fr"as" ++ Fragment.const(alias) - } - - def lowerLike[A: Put](value: A): Fragment = - fr"lower(" ++ f ++ fr") LIKE $value" - - def like[A: Put](value: A): Fragment = - f ++ fr"LIKE $value" - - def is[A: Put](value: A): Fragment = - f ++ fr" = $value" - - def lowerIs[A: Put](value: A): Fragment = - fr"lower(" ++ f ++ fr") = $value" - - def is[A: Put](ov: Option[A]): Fragment = - ov match { - case Some(v) => f ++ fr" = $v" - case None => f ++ fr"is null" - } - - def is(c: Column): Fragment = - f ++ fr"=" ++ c.f - - def isSubquery(sq: Fragment): Fragment = - f ++ fr"=" ++ fr"(" ++ sq ++ fr")" - - def isNot[A: Put](value: A): Fragment = - f ++ fr"<> $value" - - def isNot(c: Column): Fragment = - f ++ fr"<>" ++ c.f - - def isNull: Fragment = - f ++ fr"is null" - - def isNotNull: Fragment = - f ++ fr"is not null" - - def isIn(values: Seq[Fragment]): Fragment = - f ++ fr"IN (" ++ commas(values) ++ fr")" - - def isIn[A: Put](values: NonEmptyList[A]): Fragment = - values.tail match { - case Nil => - is(values.head) - case _ => - isIn(values.map(a => sql"$a").toList) - } - - def isLowerIn[A: Put](values: NonEmptyList[A]): Fragment = - fr"lower(" ++ f ++ fr") IN (" ++ commas(values.map(a => sql"$a").toList) ++ fr")" - - def isIn(frag: Fragment): Fragment = - f ++ fr"IN (" ++ frag ++ fr")" - - def isOrDiscard[A: Put](value: Option[A]): Fragment = - value match { - case Some(v) => is(v) - case None => Fragment.empty - } - - def isOneOf[A: Put](values: Seq[A]): Fragment = { - val vals = values.map(v => sql"$v") - isIn(vals) - } - - def isNotOneOf[A: Put](values: Seq[A]): Fragment = { - val vals = values.map(v => sql"$v") - sql"(" ++ f ++ fr"is null or" ++ f ++ fr"not IN (" ++ commas(vals) ++ sql"))" - } - - def isGt[A: Put](a: A): Fragment = - f ++ fr"> $a" - - def isGte[A: Put](a: A): Fragment = - f ++ fr">= $a" - - def isGt(c: Column): Fragment = - f ++ fr">" ++ c.f - - def isLt[A: Put](a: A): Fragment = - f ++ fr"< $a" - - def isLte[A: Put](a: A): Fragment = - f ++ fr"<= $a" - - def isLt(c: Column): Fragment = - f ++ fr"<" ++ c.f - - def setTo[A: Put](value: A): Fragment = - is(value) - - def setTo[A: Put](va: Option[A]): Fragment = - f ++ fr" = $va" - - def ++(next: Fragment): Fragment = - f.++(next) - - def prefix(ns: String): Column = - Column(name, ns) - - def as(alias: String): Column = - Column(name, ns, alias) - - def desc: Fragment = - f ++ fr"desc" - def asc: Fragment = - f ++ fr"asc" - - def max: Fragment = - fr"MAX(" ++ f ++ fr")" - - def increment[A: Put](a: A): Fragment = - f ++ fr"=" ++ f ++ fr"+ $a" - - def decrement[A: Put](a: A): Fragment = - f ++ fr"=" ++ f ++ fr"- $a" - - def substring(from: Int, many: Int): Fragment = - if (many <= 0 || from < 0) fr"${""}" - else fr"SUBSTRING(" ++ f ++ fr"FROM $from FOR $many)" -} diff --git a/modules/store/src/main/scala/docspell/store/impl/DoobieSyntax.scala b/modules/store/src/main/scala/docspell/store/impl/DoobieSyntax.scala deleted file mode 100644 index e465d8ea..00000000 --- a/modules/store/src/main/scala/docspell/store/impl/DoobieSyntax.scala +++ /dev/null @@ -1,103 +0,0 @@ -package docspell.store.impl - -import cats.data.NonEmptyList - -import docspell.common.Timestamp - -import doobie._ -import doobie.implicits._ - -trait DoobieSyntax { - - def groupBy(c0: Column, cs: Column*): Fragment = - groupBy(NonEmptyList.of(c0, cs: _*)) - - def groupBy(cs: NonEmptyList[Column]): Fragment = - fr" GROUP BY " ++ commas(cs.toList.map(_.f)) - - def coalesce(f0: Fragment, fs: Fragment*): Fragment = - sql" coalesce(" ++ commas(f0 :: fs.toList) ++ sql") " - - def power2(c: Column): Fragment = - sql"power(2," ++ c.f ++ sql")" - - def commas(fs: Seq[Fragment]): Fragment = - fs.reduce(_ ++ Fragment.const(",") ++ _) - - def commas(fa: Fragment, fas: Fragment*): Fragment = - commas(fa :: fas.toList) - - def and(fs: Seq[Fragment]): Fragment = - Fragment.const(" (") ++ fs - .filter(f => !isEmpty(f)) - .reduce(_ ++ Fragment.const(" AND ") ++ _) ++ Fragment.const(") ") - - def and(f0: Fragment, fs: Fragment*): Fragment = - and(f0 :: fs.toList) - - def or(fs: Seq[Fragment]): Fragment = - Fragment.const(" (") ++ fs.reduce(_ ++ Fragment.const(" OR ") ++ _) ++ Fragment.const( - ") " - ) - def or(f0: Fragment, fs: Fragment*): Fragment = - or(f0 :: fs.toList) - - def where(fa: Fragment): Fragment = - if (isEmpty(fa)) Fragment.empty - else Fragment.const(" WHERE ") ++ fa - - def orderBy(fa: Fragment): Fragment = - Fragment.const(" ORDER BY ") ++ fa - - def orderBy(c0: Fragment, cs: Fragment*): Fragment = - 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 - ) - - def insertRow(table: Fragment, cols: List[Column], vals: Fragment): Fragment = - Fragment.const("INSERT INTO ") ++ table ++ Fragment.const(" (") ++ - commas(cols.map(_.f)) ++ Fragment.const(") VALUES (") ++ vals ++ Fragment.const(")") - - def insertRows(table: Fragment, cols: List[Column], vals: List[Fragment]): Fragment = - Fragment.const("INSERT INTO ") ++ table ++ Fragment.const(" (") ++ - commas(cols.map(_.f)) ++ Fragment.const(") VALUES ") ++ commas( - vals.map(f => sql"(" ++ f ++ sql")") - ) - - def selectSimple(cols: Seq[Column], table: Fragment, where: Fragment): Fragment = - selectSimple(commas(cols.map(_.f)), table, where) - - def selectSimple(cols: Fragment, table: Fragment, where: Fragment): Fragment = - Fragment.const("SELECT ") ++ cols ++ - Fragment.const(" FROM ") ++ table ++ this.where(where) - - def selectDistinct(cols: Seq[Column], table: Fragment, where: Fragment): Fragment = - Fragment.const("SELECT DISTINCT ") ++ commas(cols.map(_.f)) ++ - 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 - ) - - 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")") - fr"WITH" ++ commas(subsel) - } - - def isEmpty(fragment: Fragment): Boolean = - Fragment.empty.toString() == fragment.toString() - - def currentTime: ConnectionIO[Timestamp] = - Timestamp.current[ConnectionIO] -} - -object DoobieSyntax extends DoobieSyntax diff --git a/modules/store/src/main/scala/docspell/store/impl/Implicits.scala b/modules/store/src/main/scala/docspell/store/impl/Implicits.scala deleted file mode 100644 index 2047b301..00000000 --- a/modules/store/src/main/scala/docspell/store/impl/Implicits.scala +++ /dev/null @@ -1,15 +0,0 @@ -package docspell.store.impl - -object Implicits extends DoobieMeta with DoobieSyntax { - - implicit final class LegacySyntax(col: docspell.store.qb.Column[_]) { - def oldColumn: Column = - Column(col.name) - - def column: Column = - col.table.alias match { - case Some(p) => oldColumn.prefix(p) - case None => oldColumn - } - } -} diff --git a/modules/store/src/main/scala/docspell/store/queries/QItem.scala b/modules/store/src/main/scala/docspell/store/queries/QItem.scala index c4f1884e..feba4947 100644 --- a/modules/store/src/main/scala/docspell/store/queries/QItem.scala +++ b/modules/store/src/main/scala/docspell/store/queries/QItem.scala @@ -10,6 +10,7 @@ import fs2.Stream import docspell.common.syntax.all._ import docspell.common.{IdRef, _} import docspell.store.Store +import docspell.store.qb.DSL._ import docspell.store.qb._ import docspell.store.records._ @@ -20,7 +21,6 @@ import org.log4s._ object QItem { private[this] val logger = getLogger - import docspell.store.qb.DSL._ def moveAttachmentBefore( itemId: Ident, @@ -125,7 +125,7 @@ object QItem { ) ] .option - logger.info(s"Find item query: $cq") + logger.trace(s"Find item query: $cq") val attachs = RAttachment.findByItemWithMeta(id) val sources = RAttachmentSource.findByItemWithMeta(id) val archives = RAttachmentArchive.findByItemWithMeta(id) @@ -382,7 +382,7 @@ object QItem { .changeWhere(cond) .limit(batch) .build - logger.info(s"List $batch items: $sql") + logger.trace(s"List $batch items: $sql") sql.query[ListItem].stream } @@ -423,13 +423,7 @@ object QItem { .orderBy(Tids.weight.desc) .build -// Seq(fr"tids.weight"), -// ("tids(item_id, weight)", fr"(VALUES" ++ values ++ fr")") -// ) ++ -// fr"INNER JOIN tids ON" ++ IC.id.prefix("i").f ++ fr" = tids.item_id" ++ -// fr"ORDER BY tids.weight DESC" - - logger.info(s"fts query: $from") + logger.trace(s"fts query: $from") from.query[ListItem].stream } diff --git a/modules/store/src/main/scala/docspell/store/records/RAttachment.scala b/modules/store/src/main/scala/docspell/store/records/RAttachment.scala index e6cd356c..e781eb89 100644 --- a/modules/store/src/main/scala/docspell/store/records/RAttachment.scala +++ b/modules/store/src/main/scala/docspell/store/records/RAttachment.scala @@ -38,20 +38,6 @@ object RAttachment { def as(alias: String): Table = Table(Some(alias)) - val table = fr"attachment" - - object Columns { - import docspell.store.impl._ - - val id = Column("attachid") - val itemId = Column("itemid") - val fileId = Column("filemetaid") - val position = Column("position") - val created = Column("created") - val name = Column("name") - val all = List(id, itemId, fileId, position, created, name) - } - def insert(v: RAttachment): ConnectionIO[Int] = DML.insert( T, diff --git a/modules/store/src/main/scala/docspell/store/records/RAttachmentArchive.scala b/modules/store/src/main/scala/docspell/store/records/RAttachmentArchive.scala index f32c06fd..f71116e2 100644 --- a/modules/store/src/main/scala/docspell/store/records/RAttachmentArchive.scala +++ b/modules/store/src/main/scala/docspell/store/records/RAttachmentArchive.scala @@ -38,19 +38,6 @@ object RAttachmentArchive { def as(alias: String): Table = Table(Some(alias)) - val table = fr"attachment_archive" - object Columns { - import docspell.store.impl._ - - val id = Column("id") - val fileId = Column("file_id") - val name = Column("filename") - val messageId = Column("message_id") - val created = Column("created") - - val all = List(id, fileId, name, messageId, created) - } - def of(ra: RAttachment, mId: Option[String]): RAttachmentArchive = RAttachmentArchive(ra.id, ra.fileId, ra.name, mId, ra.created) diff --git a/modules/store/src/main/scala/docspell/store/records/RAttachmentMeta.scala b/modules/store/src/main/scala/docspell/store/records/RAttachmentMeta.scala index ad5558b8..4adfbad7 100644 --- a/modules/store/src/main/scala/docspell/store/records/RAttachmentMeta.scala +++ b/modules/store/src/main/scala/docspell/store/records/RAttachmentMeta.scala @@ -45,18 +45,6 @@ object RAttachmentMeta { def as(alias: String): Table = Table(Some(alias)) - val table = fr"attachmentmeta" - object Columns { - import docspell.store.impl._ - - val id = Column("attachid") - val content = Column("content") - val nerlabels = Column("nerlabels") - val proposals = Column("itemproposals") - val pages = Column("page_count") - val all = List(id, content, nerlabels, proposals, pages) - } - def insert(v: RAttachmentMeta): ConnectionIO[Int] = DML.insert( T, diff --git a/modules/store/src/main/scala/docspell/store/records/RAttachmentPreview.scala b/modules/store/src/main/scala/docspell/store/records/RAttachmentPreview.scala index 24f6fc80..61576930 100644 --- a/modules/store/src/main/scala/docspell/store/records/RAttachmentPreview.scala +++ b/modules/store/src/main/scala/docspell/store/records/RAttachmentPreview.scala @@ -36,17 +36,6 @@ object RAttachmentPreview { def as(alias: String): Table = Table(Some(alias)) - val table = fr"attachment_preview" - object Columns { - import docspell.store.impl._ - val id = Column("id") - val fileId = Column("file_id") - val name = Column("filename") - val created = Column("created") - - val all = List(id, fileId, name, created) - } - def insert(v: RAttachmentPreview): ConnectionIO[Int] = DML.insert(T, T.all, fr"${v.id},${v.fileId},${v.name},${v.created}") diff --git a/modules/store/src/main/scala/docspell/store/records/RAttachmentSource.scala b/modules/store/src/main/scala/docspell/store/records/RAttachmentSource.scala index 20629645..62c1b1d8 100644 --- a/modules/store/src/main/scala/docspell/store/records/RAttachmentSource.scala +++ b/modules/store/src/main/scala/docspell/store/records/RAttachmentSource.scala @@ -36,17 +36,6 @@ object RAttachmentSource { def as(alias: String): Table = Table(Some(alias)) - val table = fr"attachment_source" - object Columns { - import docspell.store.impl._ - val id = Column("id") - val fileId = Column("file_id") - val name = Column("filename") - val created = Column("created") - - val all = List(id, fileId, name, created) - } - def of(ra: RAttachment): RAttachmentSource = RAttachmentSource(ra.id, ra.fileId, ra.name, ra.created) diff --git a/modules/store/src/main/scala/docspell/store/records/RItem.scala b/modules/store/src/main/scala/docspell/store/records/RItem.scala index 929b3528..6a65ef83 100644 --- a/modules/store/src/main/scala/docspell/store/records/RItem.scala +++ b/modules/store/src/main/scala/docspell/store/records/RItem.scala @@ -108,48 +108,6 @@ object RItem { def as(alias: String): Table = Table(Some(alias)) - val table = fr"item" - object Columns { - import docspell.store.impl._ - - val id = Column("itemid") - val cid = Column("cid") - val name = Column("name") - val itemDate = Column("itemdate") - val source = Column("source") - val incoming = Column("incoming") - val state = Column("state") - val corrOrg = Column("corrorg") - val corrPerson = Column("corrperson") - val concPerson = Column("concperson") - val concEquipment = Column("concequipment") - val inReplyTo = Column("inreplyto") - val dueDate = Column("duedate") - val created = Column("created") - val updated = Column("updated") - val notes = Column("notes") - val folder = Column("folder_id") - val all = List( - id, - cid, - name, - itemDate, - source, - incoming, - state, - corrOrg, - corrPerson, - concPerson, - concEquipment, - inReplyTo, - dueDate, - created, - updated, - notes, - folder - ) - } - private val currentTime = Timestamp.current[ConnectionIO]