Created
December 22, 2018 23:00
-
-
Save vichu/011924f0e70c577ceb985c03f517bb72 to your computer and use it in GitHub Desktop.
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
// Query based model | |
abstract class UserById extends Table[UserById, User] { | |
// Override table metadata | |
override def tableName: String = "user_by_id" | |
// Define the table schema | |
object id extends UUIDColumn with PartitionKey | |
object fName extends StringColumn { | |
override def name: String = "firstName" | |
} | |
object lName extends StringColumn { | |
override def name: String = "lastName" | |
} | |
object email extends StringColumn | |
// Define low level queries | |
def createUserById(uuid: UUID, firstName: String, lastName: String, emailId: String): Future[ResultSet] = { | |
insert | |
.value(_.id, uuid) | |
.value(_.fName, firstName) | |
.value(_.lName, lastName) | |
.value(_.email, emailId) | |
.future() | |
} | |
def getUserById(uuid: UUID): Future[Option[User]] = select | |
.all() | |
.where(_.id eqs uuid) | |
.one() | |
} | |
abstract class UserByFirstName extends Table[UserByFirstName, User] { | |
// Override table metadata | |
override def tableName: String = "user_by_first_name" | |
// Define the table schema | |
object fName extends StringColumn with PartitionKey { | |
override def name: String = "firstName" | |
} | |
object id extends UUIDColumn | |
object lName extends StringColumn { | |
override def name: String = "lastName" | |
} | |
object email extends StringColumn | |
// Define low level queries | |
def createUserByUserName(uuid: UUID, firstName: String, lastName: String, emailId: String): Future[ResultSet] = { | |
insert | |
.value(_.id, uuid) | |
.value(_.fName, firstName) | |
.value(_.lName, lastName) | |
.value(_.email, emailId) | |
.future() | |
} | |
def getUserByFirstName(firstName: String): Future[Option[User]] = select | |
.all() | |
.where(_.fName eqs firstName) | |
.one() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment