Created
October 11, 2011 09:08
-
-
Save sheki/1277636 to your computer and use it in GitHub Desktop.
Squeryl Scala Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [error] /Users/abhishekk/flipkart/platform/star-command/src/main/scala/flipkart/platform/starcommand/model/Models.scala:34: inferred type arguments [flipkart.platform.starcommand.model.Host,flipkart.platform.starcommand.model.Tag,Nothing] do not conform to method manyToManyRelation's type parameter bounds [L <: org.squeryl.KeyedEntity[_],R <: org.squeryl.KeyedEntity[_],A <: org.squeryl.KeyedEntity[_]] | |
| [error] val hostTags = manyToManyRelation(hosts, tags).via[HostTag]((h, t, ht) => (ht.tagId == t.id, h.id == ht.hostId)) | |
| [error] ^ | |
| [error] one error found |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Host(val id: Long, | |
| val name: String, | |
| val config: Option[String]) { | |
| def this() = this (0, "", Some("")) | |
| } | |
| class Tag(val id: Long, | |
| val name: String, | |
| val config: Option[String]) { | |
| def this() = this (0, "", Some("")) | |
| } | |
| class HostTag(val hostId: Int, val tagId: Int) extends KeyedEntity[CompositeKey2[Int, Int]] { | |
| def id = compositeKey(hostId, tagId) | |
| } | |
| object HostDB extends Schema { | |
| val hosts = table[Host] | |
| val tags = table[Tag] | |
| val hostTags = manyToManyRelation(hosts, tags).via[HostTag]((h, t, ht) => (ht.tagId == t.id, h.id == ht.hostId)) | |
| on(hosts)(host => declare( | |
| host.id is(unique, indexed, primaryKey), | |
| host.name is(unique, indexed), | |
| host.config is (dbType("text")) | |
| )) | |
| on(tags)(tag => declare( | |
| tag.id is(unique, indexed, primaryKey), | |
| tag.name is(unique, indexed), | |
| tag.config is (dbType("text")) | |
| )) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment