Skip to content

Instantly share code, notes, and snippets.

@elyphas
Created May 3, 2021 15:09
Show Gist options
  • Save elyphas/8d4347b25db9b4f335b0aae12e6848ae to your computer and use it in GitHub Desktop.
Save elyphas/8d4347b25db9b4f335b0aae12e6848ae to your computer and use it in GitHub Desktop.
class ConnectionScarango {
implicit val ec: scala.concurrent.ExecutionContext = scala.concurrent.ExecutionContext.global
Profig.initConfiguration().map { in => println(in) }
lazy val db = new ArangoDB(credentials = Some(Credentials("root", "jctaurys")))
lazy val dbExample = db.api.db("example")
//lazy val collection = dbExample.collection("proveedores")
}
class CRecipeScarango extends ConnectionScarango {
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]
}
}
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]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment