Skip to content

Instantly share code, notes, and snippets.

@elyphas
Created May 3, 2021 14:55
Show Gist options
  • Save elyphas/6ab5f5d51ce46abfa4fb7fcb00e0978a to your computer and use it in GitHub Desktop.
Save elyphas/6ab5f5d51ce46abfa4fb7fcb00e0978a to your computer and use it in GitHub Desktop.
/* 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