Created
September 13, 2013 22:43
-
-
Save mathieuancelin/6557025 to your computer and use it in GitHub Desktop.
This file contains 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
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