{"id":13397132,"url":"https://github.com/diegogub/aranGO","last_synced_at":"2025-03-13T23:32:09.127Z","repository":{"id":17200143,"uuid":"19968412","full_name":"diegogub/aranGO","owner":"diegogub","description":"Golang driver for ArangoDB","archived":false,"fork":false,"pushed_at":"2020-10-18T22:07:30.000Z","size":169,"stargazers_count":125,"open_issues_count":20,"forks_count":31,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-07-31T18:19:03.979Z","etag":null,"topics":["aql","arango","arangodb","driver","transactions"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/diegogub.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-20T05:10:35.000Z","updated_at":"2023-09-08T16:47:44.000Z","dependencies_parsed_at":"2022-08-04T17:00:33.266Z","dependency_job_id":null,"html_url":"https://github.com/diegogub/aranGO","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diegogub%2FaranGO","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diegogub%2FaranGO/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diegogub%2FaranGO/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diegogub%2FaranGO/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/diegogub","download_url":"https://codeload.github.com/diegogub/aranGO/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243500243,"owners_count":20300761,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aql","arango","arangodb","driver","transactions"],"created_at":"2024-07-30T18:01:11.532Z","updated_at":"2025-03-13T23:32:08.845Z","avatar_url":"https://github.com/diegogub.png","language":"Go","funding_links":[],"categories":["Go","Uncategorized"],"sub_categories":["Uncategorized"],"readme":"aranGO\n======\n~~~\ngo get github.com/diegogub/aranGO\n~~~\nGolang driver for ArangoDB.\n\nHere are the things you can do until now:\n\n  * Databases : create\n  * Collections : drop, create, list, truncate\n  * Documents : save, replace,patch, query (simple query,AQL,Transactions)\n  * Edges : Relate documents, save, patch, replace\n  * Execute transactions\n  * Execute AQL\n  * Replication config\n\nAdditional Features\n-------------------\n  * Minimal Models with hooks\n  * AqlBuilder ( https://gowalker.org/github.com/diegogub/aranGO#AqlStruct , check Filter, it has some nice JSON2AQL filter feature. If you have any suggestion about JSON format and new ideas to improve it feel free to write me or pull-request :P )\n\nAny ideas for the driver or bug fixes please feel free to create a issue or pull-request to dev :)\n\nDocumentation\n-------------\n\nhttps://gowalker.org/github.com/diegogub/aranGO\n\nBasic Usage\n-----------\n~~~~go\nimport ara \"github.com/diegogub/aranGO\"\n\ntype DocTest struct {\n  ara.Document // Must include arango Document in every struct you want to save id, key, rev after saving it\n  Name     string\n  Age      int\n  Likes    []string\n}\n~~~~\n\nConnect and create collections\n-----------------------------------\n~~~go\n    //change false to true if you want to see every http request\n    //Connect(host, user, password string, log bool) (*Session, error) {\n    s,err := ara.Connect(\"http://localhost:8529\",\"diego\",\"test\",false) \n    if err != nil{\n        panic(err)\n    }\n\n    // CreateDB(name string,users []User) error\n    s.CreateDB(\"test\",nil)\n\n    // create Collections test if exist\n    if !s.DB(\"test\").ColExist(\"docs1\"){\n        // CollectionOptions has much more options, here we just define name , sync\n        docs1 := NewCollectionOptions(\"docs1\",true)\n        s.DB(\"test\").CreateCollection(docs1)\n    }\n\n    if !s.DB(\"test\").ColExist(\"docs2\"){\n        docs2 := NewCollectionOptions(\"docs2\",true)\n        s.DB(\"test\").CreateCollection(docs2)\n    }\n\n    if !s.DB(\"test\").ColExist(\"ed\"){\n        edges := NewCollectionOptions(\"ed\",true)\n        edges.IsEdge() // set to Edge\n        s.DB(\"test\").CreateCollection(edges)\n    }\n~~~~\n\nCreate and Relate documents\n---------------------------\n~~~go\n  var d1,d2 DocTest\n  d1.Name = \"Diego\"\n  d1.Age = 22\n  d1.Likes = []string { \"arangodb\", \"golang\", \"linux\" }\n  \n  d2.Name = \"Facundo\"\n  d2.Age = 25\n  d2.Likes = []string { \"php\", \"linux\", \"python\" }\n\n\n  err =s.DB(\"test\").Col(\"docs1\").Save(\u0026d1)\n  err =s.DB(\"test\").Col(\"docs1\").Save(\u0026d2)\n  if err != nil {\n    panic(err)\n  }\n\n  // could also check error in document\n  /*\n  if d1.Error {\n    panic(d1.Message)\n  }\n  */\n\n  // update document\n  d1.Age = 23\n  err =s.DB(\"test\").Col(\"docs1\").Replace(d1.Key,d1)\n  if err != nil {\n    panic(err)\n  }\n  \n  // Relate documents\n  s.DB(\"test\").Col(\"ed\").Relate(d1.Id,d2.Id,map[string]interface{}{ \"is\" : \"friend\" })\n~~~\n\nAQL\n---\n\n~~~go\n// query query \n  q := ara.NewQuery(\"FOR i in docs1 RETURN i\")\n  c ,err:=s.DB(\"test\").Execute(q)\n  if err != nil {\n    panic(err)\n  }\n  var doc DocTest\n\n  for c.FetchOne(\u0026doc){\n    log.Println(doc)\n  }\n\n~~~\n\n\nTransactions\n------------\n\n~~~go\n// saving document with transaction\nfunc TranSave(db *ara.Database,doc interface{},col string,counter string) (*ara.Transaction,error){\n  if  col == \"\" || counter == \"\"{\n    return nil,errors.New(\"Collection or counter must not be nil\")\n  }\n\n  write := []string { col }\n  q := `function(params){\n                var db = require('internal').db;\n                try {\n                  var c = db.`+col+`.document('c');\n                }catch(error){\n                  var tmp = db.`+col+`.save( { '_key' : 'c' , '`+counter+`' : 0 });\n                }\n                var c = db.`+col+`.document('c');\n                var co = c.`+counter+` || 0;\n                co = co + 1 ;\n                // update counter\n                db.`+col+`.update(c, { '`+counter+`' : co }) ;\n                params.doc.s = -1 * co ;\n                params.doc.created = new Date().toISOString();\n                var res = db.`+col+`.save(params.doc) ;\n                return res._key\n        }\n  `\n  t := ara.NewTransaction(q,write,nil)\n  t.Params = map[string]interface{}{ \"doc\" : doc }\n\n  err := t.Execute(db)\n\n  return t,err\n}\n~~~\n\nModels\n------\nTo be a model, any struct must implement Modeler Interface.\n\n~~~go\ntype Modeler interface {\n    // Returns current model key\n    GetKey() string\n    // Returns collection where I should save the model\n    GetCollection() string\n    // Error\n    GetError() (string, bool)\n}\n~~~\n\nImplement Modeler and add tags to struct..\n~~~go\n\ntype DocTest struct {\n  ara.Document // Must include arango Document in every struct you want to save id, key, rev after saving it\n// required tag for strings.\n  Name     string `required:\"-\"`\n// unique tag validate within collection users, if username is unique\n  Username string `unique:\"users\"`\n// enum tag checks string value\n  Type     string `enum:\"A,M,S\"`\n// Next release I will be implementing some other tags to validate int\nand arrays\n  Age      int\n  Likes    []string\n}\n\nfunc (d *DocTest) GetKey() string{\n  return d.Key\n}\n\nfunc (d *DocTest) GetCollection() string {\n  return \"testcollection\"\n}\n\nfunc (d *DocTest) GetError()(string,error){\n    // default error bool and messages. Could be any kind of error\n    return d.Message,d.Error\n}\n\n// pass ArangoDB database as context\nctx, err :=  NewContext(db)\n\n// save model, returns map of errors or empty map\ne := ctx.Save(d1)\n\n// check errors, also Error is saved in Context struct\nif len(e) \u003e 1 {\n  panic(e)\n}\n\n// get other document\nd2.Key = \"d2key\"\nctx.Get(d2)\nlog.Println(d2)\n\n~~~\n\n\nWe can implement hooks to execute when saving,updating or deleting\nmodel..\n~~~go\n// execute before saving\nfunc (d *DocTest) PreSave(c *ara.Context) {\n   var e error\n  // Any extra validation\n  // ......\n  // ......\n  if e != nil {\n    // errors should be set into context struct\n    c.Err[\"presave\"] = \"failed to validate doctest\"\n  }\n\n  return\n}\n~~~\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiegogub%2FaranGO","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiegogub%2FaranGO","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiegogub%2FaranGO/lists"}