Skip to content

Instantly share code, notes, and snippets.

@mathieuancelin
Created September 13, 2013 22:43
Show Gist options
  • Save mathieuancelin/6557025 to your computer and use it in GitHub Desktop.
Save mathieuancelin/6557025 to your computer and use it in GitHub Desktop.
package controllers
import play.api.mvc._
import org.ancelin.play2.couchbase.plugins.CouchbaseN1QLPlugin._
import play.api.libs.json.Json
import play.api.libs.concurrent.Execution.Implicits._
import play.api.libs.iteratee.{Enumerator, Enumeratee}
case class Person(fname: String, age: Int)
object N1QLController extends Controller {
implicit val personFormat = Json.format[Person]
def find = Action {
Async {
N1QL( """ SELECT fname, age FROM tutorial WHERE age > 30 """ ).enumerate[Person].map { enumerator =>
Ok.stream(
(enumerator &>
Enumeratee.collect[Person] { case p@Person(_, age) if age < 50 => p } ><>
Enumeratee.map[Person](personFormat.writes)) >>>
Enumerator.eof
)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment