unicorn
unicorn copied to clipboard
Create entity DSL that allows to eliminate big part of boilerplate.
Doc from DSL pasted below:
/**
* This is basic class to create your Entity. Entity here means database table, row and dedicated basic repository
* together with helper classes such as unique Id type.
* Normally, you need to generate multiple classes/objects, remember to specify correct types etc.
* Generally a lot of boilerplate.
* Using Entity Dsl all you need is:
* 1. Create object that extends from `EntityDsl` with proper name (e.g. User, Invoice)
* 2. Create inside case class `Row` representing raw row of data with one filed called `id` of type `Option[Id]`
* 3. Create inside class Table extending `BaseTable` that represents your table (with Tag and table name).
* Inside Unicorn generate definition for `id` that needs to be added to `*` projection as `id.?`
* 4. Last thing is to implement value `Repository` with new instance of `DslRepository`.
*
* Minimal entity looks like this:
*
* ```
* object User extends EntityDsl(myProfile){
* case class Row(id: Option[Id], name: String)
* class Table(tag: Tag) extends BaseTable(tag, "Table_Name"){
* def name = column[String]("FIRST_NAME")
* override def * = (id.?, name) <> (Row.tupled, Row.unapply)
* }
* override val Repository = new DslRepository(TableQuery[Table])
* }
* ```
* There still some boilerplate (e.g. `new DslRepository(TableQuery[Table])`, `<> (Row.tupled, Row.unapply)`)
* and we plan to elimitate also those in future.
*
* This approach changes slightly the way how you work with your entity. Instead of using e.g. `UserRow` or
* `UsersRepository` now `User.Row` and `User.Repository` should be used.
* Another benefit of this approach is that now you can abstract some pieces of code around entity such as schema
* creation.
*
* @param identifiers identifiers instance use together with you Unicorn instance.
*/
It took me over 2 years to finally create full version. My Bad.
:+1: good stuff