score:2
you can try this:
import play.api.db.slick.config.driver.simple._
import scala.slick.lifted.tag
case class coordinate(val x: int, val y: int)
class mytable(val tag: tag) extends table[(coordinate, string)](tag, "coordinates") {
def x = column[int]("x")
def y = column[int]("y")
def data = column[string]("data")
def * = (x, y, data).shaped <> ({
case (x, y, data) => (coordinate(x, y), data)
}, { ct: tuple2[coordinate, string] =>
some(ct._1.x, ct._1.y, ct._2)
})
}
object coordinates {
val mytable = tablequery[mytable]
def insert(ct: (coordinate, string))(implicit session: session) = {
mytable.insert(ct)
}
def search(x: int, y: int)(implicit session: session): option[(coordinate, string)] = {
mytable.where(_.x === x).where(_.y === y).firstoption
}
}
Source: stackoverflow.com
Related Query
- Slick transform subset of Table Columns into a Case Class
- Slick 3.1 - Retrieving subset of columns as a case class
- Map table with more than 22 columns to Scala case class by Slick 2.1.0
- Extract two optional columns into a case class in Slick
- How can I omit case class fields in a slick table mapping?
- Transform one case class into another when the argument list is the same
- Represent postgres INET type in slick case class / table definition
- transform dataset into case class via (wrapped) encoders
- Scala Slick Class Table Definition, Error Declaring DateTime columns
- In Scala, is there an easy way to convert a case class into a tuple?
- How to convert Row of a Scala DataFrame into case class most efficiently?
- Scala: Parse JSON directly into a case class
- Shapeless - turn a case class into another with fields in different order
- Read CSV in Scala into case class instances with error handling
- How can I transform a Map to a case class in Scala?
- SLICK How to define bidirectional one-to-many relationship for use in case class
- Custom mapping to nested case class structure in Slick (more than 22 columns)
- scala - parse json of more than 22 elements into case class
- Lift-json extract json with 'type' field into a case class
- Listing columns on a Slick table
- How to transform a categorical variable in Spark into a set of columns coded as {0,1}?
- Slick 2 - Update columns in a table and return whole table object
- Slick 2.10-RC1, Scala 2.11.x, bypassing 22 arity limit with case class (heterogenous)
- Extracting lift-json into a case class with an upper bound
- Unapply regex matching into case class
- Mapped projection with <> to a case class with companion object in Slick
- How to convert values of a case class into Seq?
- In Scala - Converting a case class List into a List of tuples
- Reducing boilerplate in Slick definitions for case class models
- Transform a case class to another by unwrapping types in Scala 3
More Query from same tag
- "More than one scala library" in Scala/Android project
- get all keys of play.api.libs.json.JsValue
- list.filter(!=) compiles, but doesn't work as expected
- How does regex capturing work in scala?
- Scala persistent key value store?
- Scala Parallel Collections- How to return early?
- Writing a unit test for Play websockets
- Advice for build multiusers big website (1. scala lift/spring roo 2. database mongoDB/Postgre ORM/MySql ORM 3. Web-server environment Tomcat etc..)
- Cannot add package description in ScalaDoc (Scala 3)
- Array of JSON to Dataframe in Spark received by Kafka
- Display content based on if user is logged in
- Best way to use Scala MongoClient in Play 2.0
- Class generation and enhancement with CGLIB
- What's the difference between maven-compiler-plugin and scala-maven-plugin?
- Implementing mutable methods in Scala classes
- Query MongoDB - Getting codec error whe querying distinct()
- how to parse nested json array in scala
- Scala Type Tags - Fully qualified versus non-fully qualified
- spark and breeze random number generator ( ClassNotFoundException)
- specs2 - how to use the same variable inside around and inside the test itself?
- "You must be logged in" error in WS Play Framework (scala)
- Play 2.0: Optional list in query
- When should I choose Vector in Scala?
- Unit Testing Components that Uses an Akka Actor
- Adding class to class path of sbt plugin
- Creating filters in play 2.5.X
- sbt native-packager RPM install directory issue
- Only parent class columns created cassandra using cassandra-spark connector
- What exactly did Scala improve with pattern matching in 2.10?
- Why does Scala function allow subclass parameter when specifyied super class parameter