0
從內部看,Play Framework從底部開始是異步的。 Play以異步,非阻塞的方式處理每個請求。將框架和非阻塞請求發送到PostgreSQL
如何向PostgreSQL發出非阻塞請求?此刻
@Singleton
class Application @Inject()(usersRepossitory: UsersRepository,
cc: ControllerComponents) extends AbstractController(cc) {
def index = Action {
Ok(usersRepository.list().map(_.id).mkString(","))
}
}
case class User(id: Long)
@Singleton
class UsersRepository @Inject()(dbapi: DBApi) {
private val db = dbapi.database("default")
val parser: RowParser[User] = Macro.namedParser[User]
def list: List[User] = db.withConnection { implicit connection =>
val result: List[User] = SQL"SELECT id FROM users".as(parser.*)
result
}
}