Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/* ArangoDB
db.tblrecipe.document("2021-88888")
{
"_key" : "2021-88888",
"_id" : "tblrecipe/2021-88888",
"_rev" : "_cRMJ_Yi---",
"fiscal_period" : 2021,
"folio" : "88888",
"date" : 1620049658325,
"id_area" : "3",
"area" : "JURISDICCION SANITARIA 03",
"servicio" : "CONSULTA"
}
*/
def insert(item: Recipe) = {
lazy val collection = dbExample.collection("tblrecipe")
val itemUpdated = item.copy( _id = Recipe.id(item.fiscal_period + "-" + item.folio))
for {
_ <- db.init()
res <- collection.document.insertOne(itemUpdated)
} yield ((item, FoundDoobie())).asRight[String]
}
def byId(item: Recipe): Future[Either[String, (Recipe, EventsDoobieResult)]] = {
lazy val collection = dbExample.collection("tblrecipe")
val identi = item.fiscal_period + "-" + item.folio
for {
_ <- db.init()
res <- collection.document.get[Recipe](Recipe.id(identi))
} yield res match {
case Some(i) => (res.get, FoundDoobie()).asRight[String]
case None => (Recipe(), NotFoundDoobie()).asRight[String]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment