Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create entity DSL that allows to eliminate big part of boilerplate. #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

romanowski
Copy link
Member

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.
   */

@romanowski romanowski mentioned this pull request Dec 31, 2017
3 tasks
@romanowski
Copy link
Member Author

It took me over 2 years to finally create full version. My Bad.

* override val Repository = new DslRepository(TableQuery[Table])
* }
* ```
* There still some boilerplate (e.g. `new DslRepository(TableQuery[Table])`, `<> (Row.tupled, Row.unapply)`)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<> (Row.tupled, Row.unapply) can already be replaced with slick's .mapTo[Row]

@pdolega
Copy link
Contributor

pdolega commented Jan 25, 2018

👍 good stuff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants