diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 5f0de334..79fdb19b 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -22,7 +22,7 @@ object Dependencies { "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-core" % jsoniterVersion, "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % jsoniterVersion % "compile-internal", "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % jsoniterVersion % "test-internal", - "org.mariadb.jdbc" % "mariadb-java-client" % "3.3.3", + "org.mariadb.jdbc" % "mariadb-java-client" % "3.4.0", "org.tpolecat" %% "doobie-core" % doobieVersion, // "org.tpolecat" %% "doobie-scalatest" % doobieVersion % Test, "org.wvlet.airframe" %% "airframe-ulid" % "24.7.0", diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/contentSerializing/repositories/ContentSerializingQuery.scala b/src/main/scala/net/yoshinorin/qualtet/domains/contentSerializing/repositories/ContentSerializingQuery.scala index bddf32d9..b03a3fb8 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/contentSerializing/repositories/ContentSerializingQuery.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/contentSerializing/repositories/ContentSerializingQuery.scala @@ -3,8 +3,8 @@ package net.yoshinorin.qualtet.domains.contentSerializing import cats.data.NonEmptyList import doobie.{Read, Write} import doobie.implicits.toSqlInterpolator -import doobie.util.update.Update -import doobie.util.query +import doobie.util.update.{Update, Update0} +import doobie.util.{fragments, query} import net.yoshinorin.qualtet.domains.contents.ContentId import net.yoshinorin.qualtet.domains.series.SeriesId @@ -26,21 +26,21 @@ object ContentSerializingQuery { Update[ContentSerializing](q) } - def deleteBySeriesId(id: SeriesId): query.Query0[Unit] = { - sql"DELETE FROM contents_serializing WHERE series_id = ${id.value}" - .query[Unit] + def deleteBySeriesId(id: SeriesId): Update0 = { + sql"DELETE FROM contents_serializing WHERE series_id = ${id.value}".update } - def deleteByContentId(id: ContentId): query.Query0[Unit] = { - sql"DELETE FROM contents_serializing WHERE content_id = ${id.value}" - .query[Unit] + def deleteByContentId(id: ContentId): Update0 = { + sql"DELETE FROM contents_serializing WHERE content_id = ${id.value}".update } - def delete(seriesId: SeriesId, contentIds: Seq[ContentId]): query.Query0[Unit] = { - (fr""" + def delete(seriesId: SeriesId, contentIds: Seq[ContentId]): Update0 = { + val query = fr""" DELETE FROM contents_serializing WHERE series_id = ${seriesId.value} - AND """ ++ doobie.util.fragments.in(fr"content_id", NonEmptyList.fromList(contentIds.toList.map(c => c.value)).get)).query[Unit] + AND """ ++ fragments.in(fr"content_id", NonEmptyList.fromList(contentIds.toList.map(c => c.value)).get) + + query.update } } diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/contentSerializing/repositories/ContentSerializingRepository.scala b/src/main/scala/net/yoshinorin/qualtet/domains/contentSerializing/repositories/ContentSerializingRepository.scala index e3fe7ca9..6182c466 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/contentSerializing/repositories/ContentSerializingRepository.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/contentSerializing/repositories/ContentSerializingRepository.scala @@ -45,15 +45,15 @@ object ContentSerializingRepository { } override def deleteBySeriesId(id: SeriesId): ConnectionIO[Unit] = { - ContentSerializingQuery.deleteBySeriesId(id).option.map(_ => ()) + ContentSerializingQuery.deleteBySeriesId(id).run.map(_ => ()) } override def deleteByContentId(id: ContentId): ConnectionIO[Unit] = { - ContentSerializingQuery.deleteByContentId(id).option.map(_ => ()) + ContentSerializingQuery.deleteByContentId(id).run.map(_ => ()) } override def delete(seriesId: SeriesId, contentIds: Seq[ContentId]): ConnectionIO[Unit] = { - ContentSerializingQuery.delete(seriesId, contentIds).option.map(_ => ()) + ContentSerializingQuery.delete(seriesId, contentIds).run.map(_ => ()) } override def fakeRequestInt: ConnectionIO[Int] = 0.pure[ConnectionIO] override def fakeRequestUnit: ConnectionIO[Unit] = ().pure[ConnectionIO] diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/contentTaggings/repositories/ContentTaggingQuery.scala b/src/main/scala/net/yoshinorin/qualtet/domains/contentTaggings/repositories/ContentTaggingQuery.scala index 8de8c62a..e71ed36b 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/contentTaggings/repositories/ContentTaggingQuery.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/contentTaggings/repositories/ContentTaggingQuery.scala @@ -3,8 +3,8 @@ package net.yoshinorin.qualtet.domains.contentTaggings import cats.data.NonEmptyList import doobie.{Read, Write} import doobie.implicits.toSqlInterpolator -import doobie.util.update.Update -import doobie.util.query +import doobie.util.update.{Update, Update0} +import doobie.util.{fragments, query} import net.yoshinorin.qualtet.domains.tags.TagId import net.yoshinorin.qualtet.domains.contents.ContentId @@ -26,29 +26,21 @@ object ContentTaggingQuery { Update[ContentTagging](q) } - def deleteByContentId(id: ContentId): query.Query0[Unit] = { - sql"DELETE FROM contents_tagging WHERE content_id = ${id.value}" - .query[Unit] + def deleteByContentId(id: ContentId): Update0 = { + sql"DELETE FROM contents_tagging WHERE content_id = ${id.value}".update } - def deleteByTagId(id: TagId): query.Query0[Unit] = { - sql"DELETE FROM contents_tagging WHERE tag_id = ${id.value}" - .query[Unit] + def deleteByTagId(id: TagId): Update0 = { + sql"DELETE FROM contents_tagging WHERE tag_id = ${id.value}".update } - def delete(contentId: ContentId, tagIds: Seq[TagId]): query.Query0[Unit] = { - // https://tpolecat.github.io/doobie/docs/05-Parameterized.html#dealing-with-in-clauses - // https://tpolecat.github.io/doobie/docs/08-Fragments.html#composing-sql-literals - // - // val inClauseFragment = fr" tag_id IN (" ++ tagIds.map(n => fr"$n").intercalate(fr",") ++ fr")" - // val sTagIds = tagIds.map(t => s"${t.value}").mkString(",") - // val inClauseFragment = fr" tag_id IN (" ++ fr"${sTagIds}" ++ fr")" - // val inClauseFragment = doobie.util.fragments.in(fr"tag_id", NonEmptyList.fromList(tagIds.toList)) - - (fr""" + def delete(contentId: ContentId, tagIds: Seq[TagId]): Update0 = { + val query = fr""" DELETE FROM contents_tagging WHERE content_id = ${contentId.value} - AND """ ++ doobie.util.fragments.in(fr"tag_id", NonEmptyList.fromList(tagIds.toList.map(t => t.value)).get)).query[Unit] + AND """ ++ fragments.in(fr"tag_id", NonEmptyList.fromList(tagIds.toList.map(t => t.value)).get) + + query.update } } diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/contentTaggings/repositories/ContentTaggingRepository.scala b/src/main/scala/net/yoshinorin/qualtet/domains/contentTaggings/repositories/ContentTaggingRepository.scala index 63d16adc..712217d1 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/contentTaggings/repositories/ContentTaggingRepository.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/contentTaggings/repositories/ContentTaggingRepository.scala @@ -39,13 +39,13 @@ object ContentTaggingRepository { ContentTaggingQuery.findByTagId(id).to[Seq] } override def deleteByContentId(id: ContentId): ConnectionIO[Unit] = { - ContentTaggingQuery.deleteByContentId(id).option.map(_ => ()) + ContentTaggingQuery.deleteByContentId(id).run.map(_ => ()) } override def deleteByTagId(id: TagId): ConnectionIO[Unit] = { - ContentTaggingQuery.deleteByTagId(id).option.map(_ => ()) + ContentTaggingQuery.deleteByTagId(id).run.map(_ => ()) } override def delete(contentId: ContentId, tagIds: Seq[TagId]): ConnectionIO[Unit] = { - ContentTaggingQuery.delete(contentId, tagIds).option.map(_ => ()) + ContentTaggingQuery.delete(contentId, tagIds).run.map(_ => ()) } override def fakeRequestInt: ConnectionIO[Int] = 0.pure[ConnectionIO] override def fakeRequestUnit: ConnectionIO[Unit] = ().pure[ConnectionIO] diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/contents/repositories/ContentQuery.scala b/src/main/scala/net/yoshinorin/qualtet/domains/contents/repositories/ContentQuery.scala index 71a3f262..822ae5ac 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/contents/repositories/ContentQuery.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/contents/repositories/ContentQuery.scala @@ -3,7 +3,7 @@ package net.yoshinorin.qualtet.domains.contents import doobie.{Read, Write} import doobie.implicits.toSqlInterpolator import doobie.util.query.Query0 -import doobie.util.update.Update +import doobie.util.update.{Update, Update0} object ContentQuery { @@ -22,9 +22,8 @@ object ContentQuery { Update[Content](q) } - def delete(id: ContentId): Query0[Unit] = { - sql"DELETE FROM contents WHERE id = ${id.value}" - .query[Unit] + def delete(id: ContentId): Update0 = { + sql"DELETE FROM contents WHERE id = ${id.value}".update } def findById(id: ContentId): Read[Content] ?=> Query0[Content] = { diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/contents/repositories/ContentRepository.scala b/src/main/scala/net/yoshinorin/qualtet/domains/contents/repositories/ContentRepository.scala index 24fd0632..a24b9f80 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/contents/repositories/ContentRepository.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/contents/repositories/ContentRepository.scala @@ -115,7 +115,7 @@ object ContentRepository { ContentQuery.findByPathWithMeta(path).option } override def delete(id: ContentId): ConnectionIO[Unit] = { - ContentQuery.delete(id).option.map(_ => ()) + ContentQuery.delete(id).run.map(_ => ()) } } } diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/externalResources/repositories/ExternalResourceQuery.scala b/src/main/scala/net/yoshinorin/qualtet/domains/externalResources/repositories/ExternalResourceQuery.scala index 53cc36fd..7734ba58 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/externalResources/repositories/ExternalResourceQuery.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/externalResources/repositories/ExternalResourceQuery.scala @@ -2,8 +2,7 @@ package net.yoshinorin.qualtet.domains.externalResources import doobie.Write import doobie.implicits.toSqlInterpolator -import doobie.util.update.Update -import doobie.util.query +import doobie.util.update.{Update, Update0} import net.yoshinorin.qualtet.domains.contents.ContentId object ExternalResourceQuery { @@ -20,9 +19,8 @@ object ExternalResourceQuery { Update[ExternalResource](q) } - def delete(id: ContentId): query.Query0[Unit] = { - sql"DELETE FROM external_resources WHERE content_id = ${id.value}" - .query[Unit] + def delete(id: ContentId): Update0 = { + sql"DELETE FROM external_resources WHERE content_id = ${id.value}".update } } diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/externalResources/repositories/ExternalResourceRepository.scala b/src/main/scala/net/yoshinorin/qualtet/domains/externalResources/repositories/ExternalResourceRepository.scala index adb2cb7a..17e787f7 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/externalResources/repositories/ExternalResourceRepository.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/externalResources/repositories/ExternalResourceRepository.scala @@ -21,7 +21,7 @@ object ExternalResourceRepository { Write[(String, String, String)].contramap(p => (p.contentId.value, p.kind.value, p.name)) override def bulkUpsert(data: List[ExternalResource]): ConnectionIO[Int] = ExternalResourceQuery.bulkUpsert.updateMany(data) - override def delete(contentId: ContentId): ConnectionIO[Unit] = ExternalResourceQuery.delete(contentId).option.map(_ => ()) + override def delete(contentId: ContentId): ConnectionIO[Unit] = ExternalResourceQuery.delete(contentId).run.map(_ => ()) override def fakeRequest(): ConnectionIO[Int] = 0.pure[ConnectionIO] } } diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/robots/repositories/RobotsQuery.scala b/src/main/scala/net/yoshinorin/qualtet/domains/robots/repositories/RobotsQuery.scala index f0b545b8..1375ae6e 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/robots/repositories/RobotsQuery.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/robots/repositories/RobotsQuery.scala @@ -2,8 +2,7 @@ package net.yoshinorin.qualtet.domains.robots import doobie.Write import doobie.implicits.toSqlInterpolator -import doobie.util.update.Update -import doobie.util.query +import doobie.util.update.{Update, Update0} import net.yoshinorin.qualtet.domains.contents.ContentId object RobotsQuery { @@ -18,9 +17,8 @@ object RobotsQuery { Update[Robots](q) } - def delete(id: ContentId): query.Query0[Unit] = { - sql"DELETE FROM robots WHERE content_id = ${id.value}" - .query[Unit] + def delete(id: ContentId): Update0 = { + sql"DELETE FROM robots WHERE content_id = ${id.value}".update } } diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/robots/repositories/RobotsRepository.scala b/src/main/scala/net/yoshinorin/qualtet/domains/robots/repositories/RobotsRepository.scala index 705868a7..619d76d5 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/robots/repositories/RobotsRepository.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/robots/repositories/RobotsRepository.scala @@ -19,7 +19,7 @@ object RobotsRepository { Write[(String, String)].contramap(p => (p.contentId.value, p.attributes.value)) override def upsert(data: Robots): ConnectionIO[Int] = RobotsQuery.upsert.run(data) - override def delete(contentId: ContentId): ConnectionIO[Unit] = RobotsQuery.delete(contentId).option.map(_ => ()) + override def delete(contentId: ContentId): ConnectionIO[Unit] = RobotsQuery.delete(contentId).run.map(_ => ()) } } diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/tags/repositories/TagQuery.scala b/src/main/scala/net/yoshinorin/qualtet/domains/tags/repositories/TagQuery.scala index 0c9f9776..76c71186 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/tags/repositories/TagQuery.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/tags/repositories/TagQuery.scala @@ -3,7 +3,7 @@ package net.yoshinorin.qualtet.domains.tags import doobie.{Read, Write} import doobie.implicits.toSqlInterpolator import doobie.util.query.Query0 -import doobie.util.update.Update +import doobie.util.update.{Update, Update0} import net.yoshinorin.qualtet.domains.contents.ContentId object TagQuery { @@ -59,9 +59,8 @@ object TagQuery { Update[Tag](q) } - def delete(id: TagId): Query0[Unit] = { - sql"DELETE FROM tags WHERE id = ${id.value}" - .query[Unit] + def delete(id: TagId): Update0 = { + sql"DELETE FROM tags WHERE id = ${id.value}".update } } diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/tags/repositories/TagRepository.scala b/src/main/scala/net/yoshinorin/qualtet/domains/tags/repositories/TagRepository.scala index 76dbc874..c8ba8dea 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/tags/repositories/TagRepository.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/tags/repositories/TagRepository.scala @@ -52,7 +52,7 @@ object TagRepository { TagQuery.findByContentId(conetntId).to[Seq] } override def delete(id: TagId): ConnectionIO[Unit] = { - TagQuery.delete(id).option.map(_ => ()) + TagQuery.delete(id).run.map(_ => ()) } override def fakeRequest(): ConnectionIO[Int] = 0.pure[ConnectionIO]