rsschermer / entitytled Goto Github PK
View Code? Open in Web Editor NEWData access and persistence library build on top of Scala Slick.
License: MIT License
Data access and persistence library build on top of Scala Slick.
License: MIT License
Eager-loading currently depends on Entity#withIncludes
, which is currently implemented through runtime reflection. This is not ideal, neither for performance, nor for runtime safety.
It's currently not possible to use TableQuery[EntityTable]
with a generic EntityTable
type, because a concrete type parameter is necessary (see http://stackoverflow.com/questions/20090228/how-to-define-generic-type-in-scala).
If a way to achieve a generic TableQuery
or something similar could be found, this:
object Director extends EntityCompanion[Directors, Director] {
val query = TableQuery[Directors]
}
Could be reduced to:
object Director extends EntityCompanion[Directors, Director]
Given the following 2 components:
trait DirectorComponent {
self: Entitytled =>
import driver.api._
case class Director(
id: Option[Long],
name: String,
age: Int)
extends Entity[Director, Long]
object Director extends EntityCompanion[Directors, Director, Long]
class Directors(tag: Tag) extends EntityTable[Director, Long](tag, "DIRECTORS") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name")
def age = column[Int]("age")
def * = (id.?, name) <> ((Director.apply _).tupled, Director.unapply)
}
}
trait MovieComponent {
self: Entitytled with DirectorComponent =>
import driver.api._
case class Movie(
id: Option[Long],
title: String,
directorID: Long)(implicit includes: Includes[Movie])
extends Entity[Movie, Long]
{
val director = one(Movie.director)
}
object Movie extends EntityCompanion[Movies, Movie, Long] {
val director = toOne[Directors, Director]
}
class Movies(tag: Tag) extends EntityTable[Movie, Long](tag, "MOVIES") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def title = column[String]("title")
def directorID = column[Long]("director_id")
def * = (id.?, title, directorID) <> ((Movie.apply _).tupled, Movie.unapply)
def director = foreignKey("MOVIES_DIRECTOR_FK", directorID, TableQuery[Directors])(_.id)
}
}
The compiler fails to resolve an implicit TableQueryProvider[MovieComponent.this.Directors, MovieComponent.this.Director]
(which it needs in order to create a default target query for the toOne relationship defined on the Movie
companion). The reason for this seems to be that the macro implementation that instantiates the TableQueryProvider
expands to a type of TableQueryProvider[DirectorComponent.this.Directors, DirectorComponent.this.Director]
, even though the type parameters passed to the macro method seem to be MovieComponent.this.Directors
and MovieComponent.this.Director
.
See also some experimentation here: https://github.com/RSSchermer/cake-macro-test
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.