{"id":13795371,"url":"https://github.com/TobiEiss/aranGoDriver","last_synced_at":"2025-05-12T22:30:54.722Z","repository":{"id":68830849,"uuid":"76172392","full_name":"TobiEiss/aranGoDriver","owner":"TobiEiss","description":"ArangoDB-driver in golang","archived":false,"fork":false,"pushed_at":"2023-08-20T11:19:26.000Z","size":74,"stargazers_count":32,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-04T23:09:43.279Z","etag":null,"topics":["aql","arangodb","database","golang","memory-database"],"latest_commit_sha":null,"homepage":"https://github.com/TobiEiss/aranGoDriver","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TobiEiss.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-12-11T12:16:17.000Z","updated_at":"2023-08-20T11:19:31.000Z","dependencies_parsed_at":"2024-03-09T04:15:13.181Z","dependency_job_id":null,"html_url":"https://github.com/TobiEiss/aranGoDriver","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TobiEiss%2FaranGoDriver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TobiEiss%2FaranGoDriver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TobiEiss%2FaranGoDriver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TobiEiss%2FaranGoDriver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TobiEiss","download_url":"https://codeload.github.com/TobiEiss/aranGoDriver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225157000,"owners_count":17429698,"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","arangodb","database","golang","memory-database"],"created_at":"2024-08-03T23:00:55.260Z","updated_at":"2024-11-18T09:32:04.162Z","avatar_url":"https://github.com/TobiEiss.png","language":"Go","readme":"# aranGoDriver [![Build Status](https://travis-ci.org/TobiEiss/aranGoDriver.svg?branch=master)](https://travis-ci.org/TobiEiss/aranGoDriver)\n\nThis project is a golang-driver for [ArangoDB](https://www.arangodb.com/) writen in go.   \nThere is also an embedded-in-memory-Database to run all your tests.\n\nCurrently implemented:\n* [version](#version)\n* [users](#user): create, drop\n* [databases](#database): connect, list, create, drop\n* [collections](#collection): create, drop, truncate, update\n* [documents](#document): create, getById\n* [graphs](#graphs): create, drop, list\n* [migrations](#migrations)\n* [AQL](#aql): simple cursor\n\nIf you miss something, please contact me!\n\n## Getting started\nAll you need is a running Arango-DB and a go-environment.\n\nInstall aranGoDriver:\n`go get github.com/TobiEiss/aranGoDriver`\n\nWrite your first aranGoDriver-Programm:\n```golang\nfunc main() {\n    var session aranGoDriver.Session\n    \n    // Initialize a arango-Session with the address to your arangoDB.\n    //\n    // If you write a test use:\n    // session = aranGoDriver.NewTestSession()\n    //\n    session = aranGoDriver.NewAranGoDriverSession(\"http://localhost:8529\")\n\n    // Connect to your arango-database:\n\tsession.Connect(\"usnername\", \"secretPassword\")\n\n    // Concrats, you are connected!\n    // Let's print out all your databases\n    list, err := session.ListDBs()\n    if err != nil {\n        log.Fatal(\"there was a problem: \", err)\n    }\n    log.Println(list)\n\n    // Create a new database\n    err = session.CreateDB(\"myNewDatabase\")\n    // TODO: handle err\n\n    // Create a new collection\n    err = session.CreateCollection(\"myNewDatabase\", \"myNewCollection\")\n    // TODO: handle err\n\n    // Create Document\n    newDocument := make(map[string]interface{})\n    newDocument[\"foo\"] = \"bar\"\n    arangoID, err = session.CreateDocument(\"myNewDatabase\", \"myNewCollection\", newDocument)\n}\n```\n\n## Test\n\n### Test against a fake-in-memory-database:\n```\ngo test\n```\n\n### Test with a real database\n```\ngo test -dbhost http://localhost:8529 -dbusername root -dbpassword password123\n```\n\n## Usage\n\n### Connect to your ArangoDB\n\nYou need a new Session to your database with the hostname as parameter. Then connect with an existing username and a password.\n```\nsession := aranGoDriver.NewAranGoDriverSession(\"http://localhost:8529\")\nsession.Connect(\"username\", \"password\")\n```\n\n### Version\n```golang\nversion, err := session.Version()\n```\n\n### User\nTo use this methods you need a session as root user.\n```golang\n// create a new user\nerr := session.CreateUser(\"username\", \"password\")\n\n// delete an existing user\nerr := session.DropUser(\"username\")\n\n// grant permissions for a database\nerr := session.GrantDB(\"database\", \"username\", \"rw\")\n// Instead of \"rw\" you can also use \"ro\" or \"none\"\n\n// grant permissions for collections\nerr := session.GrantCollection(\"database\", \"collection\", \"username\", \"rw\") \n// Instead of \"rw\" you can also use \"ro\" or \"none\"\n// and instead of a collection name, you can use \"*\" for all collections\n```\n\n### Database\n```golang\n// list databases\nlist := session.ListDBs()\nfmt.Println(list) // will print ([]string): [ _system test testDB]\n\n// create databases\nerr := session.CreateDB(\"myNewDatabase\")\n\n// drop databases\nerr = session.DropDB(\"myNewDatabase\")\n```\n\n### Collection\n```golang\n// create a collection in a database\nerr = CreateCollection(\"myNewDatabase\", \"myNewCollection\")\n\n// drop collection from database\nerr = DropCollection(\"myNewDatabase\", \"myNewCollection\")\n\n// truncate database\nerr = TruncateCollection(\"myNewDatabase\", \"myNewCollection\")\n```\n\nEdgeCollection:\n```golang\n// create a collection in a database\nerr = CreateEdgeCollection(\"myNewDatabase\", \"myNewEdgeCollection\")\n```\n\n### Document\n```golang\n// create document\ntestDoc[\"foo\"] = \"bar\"\narangoID, err := session.CreateDocument(\"myNewDatabase\", \"myNewCollection\", testDoc)\n\n// get by id\nresultAsMap, err := session.GetCollectionByID(\"myNewDatabase\", idOfDocument)\n\n// update Document\ntestDoc[\"bar\"] = \"foo\"\nerr = session.UpdateDocument(\"myNewDatabase\", arangoID.ID, testDoc)\n```\n\nEdgeDocument\n```golang\narangoID, err := session.CreateDocument(\"myNewDatabase\", \"myNewCollection\", testDoc)\n```\n\n### Graphs\nTo create a graph, you need to define the edges and nodes for the graph.\nThis can be done with the `EdgeDefinition` model.\n```golang\nedgeDefinition := models.EdgeDefinition{\n    Collection: \"myEdgeCollection\",\n    From:       []string{\"myCollection1\"},\n    To:         []string{\"myCollection2\"}}\nedgeDefinitions := []models.EdgeDefinition{edgeDefinition}\n\nerr := session.CreateGraph(\"myDatabase\", \"myGraph\", edgeDefinitions)\n```\n\nIf you want to get rid of an existing graph, you can use the `DropGraph` method.\n```golang\nerr := session.DropGraph(\"myDatabase\", \"myGraph\")\n```\n\nFor an overview of your existing graphs, you can use `ListGraphs`.\n```golang\nstr, b, err := session.ListGraphs(\"myDatabase\")\n```\n\n### Migrations\nIn some cases you need 'migrations'. For example, you need default-user in your database in every environment.\nFor this case, you can use migrations. The aranGoDriver write his own memo in a `migrations`-Collection in the standard `-system`-Database of arango, and execute the migration only one time.\nAranGoDriver will identificate the migration by name.\nTake a look to the following example:\n```golang\n// check migrations\nmig1 := aranGoDriver.Migration{\n    Name: \"mig1\", // name of migration to identificate\n    Handle: func(embeddedSession aranGoDriver.Session) {\n        testMap := make(map[string]interface{})\n        testMap[\"foo\"] = \"foo\"\n        // you can do everything with the database\n        embeddedSession.CreateDocument(\"myDatabase\", \"myCollection\", testMap)\n    },\n}\n// excute migration\n// Run This line before you 'main-loop' of your program\nsession.Migrate(mig1)\n```\n\n### aql\n```golang\n// create query\nquery := \"FOR element in testColl FILTER element.foo == 'bar' RETURN element\"\nresponse, err := session.AqlQuery(\"myNewDatabase\", query, true, 1)\n```\n","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTobiEiss%2FaranGoDriver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTobiEiss%2FaranGoDriver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTobiEiss%2FaranGoDriver/lists"}