Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Singleton
- class UserDao @Inject()(protected val dbConfigProvider: DatabaseConfigProvider)(implicit ec: ExecutionContext) {
- private val dbConfig = dbConfigProvider.get[JdbcProfile]
- import dbConfig._
- import profile.api._
- private class UserTable(tag: Tag) extends Table[User](tag, "dc_user") {
- def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
- def username = column[String]("username")
- def email = column[String]("email")
- def password = column[String]("password")
- def firstName = column[String]("first_name")
- def lastName = column[String]("last_name")
- def createdAt = column[Timestamp]("created_at", SqlType("timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP"))
- def * = (id, username, email, password, firstName, lastName, createdAt) <> ((User.apply _).tupled, User.unapply)
- }
- private val users = TableQuery[UserTable]
- def add(user: User): Future[Int] = db.run {
- users += user
- }
- def list(page: Int = 0, pageSize: Int = 10, orderBy:Int = 1, filter:String = "%"): Future[Seq[User]] = db.run (
- users.filter(_.firstName === filter).drop(page * pageSize).take(pageSize).result
- )
- def update(user: User): Future[Int] = db.run {
- users.update(user)
- }
- def delete(id: Long): Future[Unit] = db.run {
- users.filter(_.id === id).delete.map(_ => ())
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement