ajozwik / sbt-quill-crud-generic

Plugin to create generic repository based on quill

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sbt-quill-crud-generic

Codacy Badge Maven Central Coverage Status Scala CI codecov

Plugin to create generic repository based on quill-generic and quill

See quill-macro-example for example of usage

  • create model classes (must be visible during compilation)

  • add plugin (project/plugins.sbt)

addSbtPlugin("com.github.ajozwik" % "sbt-quill-crud-generic" % "<version>")
package pl.jozwik.example.model

import java.time.LocalDate

import pl.jozwik.quillgeneric.quillmacro.WithId

final case class PersonId(value: Int) extends AnyVal

final case class Person(id: PersonId, firstName: String, lastName: String, birthDate: LocalDate) extends WithId[PersonId]
  • add imports:
import pl.jozwik.quillgeneric.sbt.RepositoryDescription
import pl.jozwik.quillgeneric.sbt.QuillRepositoryPlugin._
  • add settings
  generateDescription := Seq(
    RepositoryDescription("pl.jozwik.example.model.Person",
    "pl.jozwik.example.model.PersonId",
    "pl.jozwik.example.repository.PersonRepository",
    true,
    Option("pl.jozwik.example.repository.MyPersonRepository[Dialect, Naming]"))
    )

For simpler inject support (guice/spring) you can use own trait

package pl.jozwik.example.repository

import java.time.LocalDate

import io.getquill.NamingStrategy
import io.getquill.context.sql.idiom.SqlIdiom
import pl.jozwik.quillgeneric.quillmacro.sync.JdbcRepository
import pl.jozwik.quillgeneric.sbt.model.{ Person, PersonId }

trait MyPersonRepository[Dialect <: SqlIdiom, Naming <: NamingStrategy]
  extends JdbcRepository[PersonId, Person, Dialect, Naming] {
  def max: Option[LocalDate] = {
    import context._
    val r = dynamicSchema.map(p => p.birthDate)
    context.run(r.max)
  }
}
  • enable auto plugin
  enablePlugins(QuillRepositoryPlugin)
  • run compile task
sbt compile

The generated repositories are in:

target/scala-<version>/src_managed/main/

Example of usage are here

About

Plugin to create generic repository based on quill

License:MIT License


Languages

Language:Scala 99.9%Language:Shell 0.1%