{"id":19107720,"url":"https://github.com/dominikbraun/graph-sql","last_synced_at":"2025-10-28T06:33:16.779Z","repository":{"id":143000408,"uuid":"608236915","full_name":"dominikbraun/graph-sql","owner":"dominikbraun","description":"An SQL storage implementation for graph data structures.","archived":false,"fork":false,"pushed_at":"2023-07-18T00:29:02.000Z","size":15,"stargazers_count":9,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-02T10:54:57.018Z","etag":null,"topics":["graph","graph-algorithm","graph-database","graph-storage","graph-store","graph-theory"],"latest_commit_sha":null,"homepage":"https://graph.dominikbraun.io","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/dominikbraun.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-03-01T15:49:50.000Z","updated_at":"2024-07-31T08:59:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"234e0a29-fe5e-4f26-ba84-eb314e47c5c3","html_url":"https://github.com/dominikbraun/graph-sql","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/dominikbraun/graph-sql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominikbraun%2Fgraph-sql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominikbraun%2Fgraph-sql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominikbraun%2Fgraph-sql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominikbraun%2Fgraph-sql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dominikbraun","download_url":"https://codeload.github.com/dominikbraun/graph-sql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominikbraun%2Fgraph-sql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276492818,"owners_count":25652049,"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","status":"online","status_checked_at":"2025-09-22T02:00:08.972Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["graph","graph-algorithm","graph-database","graph-storage","graph-store","graph-theory"],"created_at":"2024-11-09T04:13:38.163Z","updated_at":"2025-09-22T23:58:21.627Z","avatar_url":"https://github.com/dominikbraun.png","language":"Go","readme":"# graph-sql\n\n`graph-sql` is an SQL storage implementation for graph data structures created with\n[_graph_](https://github.com/dominikbraun/graph).\n\n## Usage\n\n### 0. Get your database up and running\n\nIf you don't have a database running, you may spin up a MariaDB container with a `graph` database\nto get started quickly.\n\n```\ndocker run -e MARIADB_DATABASE=graph -e MARIADB_ROOT_PASSWORD=root -p 3306:3306 mariadb\n```\n\n### 1. Connect to your database\n\nThe first step is to establish a connection to your database server, more specifically to the actual\ndatabase schema.\n\nFor instance, a connection to the MariaDB container from the example above can be established as\nfollows:\n\n```go\npackage main\n\nimport (\n\t\"database/sql\"\n\n\t_ \"github.com/go-sql-driver/mysql\"\n)\n\nfunc main() {\n\tdb, err := sql.Open(\"mysql\", \"root:root@tcp(localhost:3306)/graph\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\n### 2. Create a new store\n\nUse the retrieved `sql.DB` instance to create a new store.\n\n```go\nstore := graphsql.New[int, int](db, graphsql.DefaultConfig)\n```\n\nThe `New` function has two type parameters. These are the types of the vertex hashes and vertex\nvalues, and they have to be the same as for the graph itself. If you're not familiar with graph's\nhashing system, check out the [concept of hashes](https://github.com/dominikbraun/graph#hashes).\n\nThis example uses a sane default configuration provided by this library, but you can configure it to\nyour needs (see [Configuration](#configuration)).\n\n### 3. Set up the table schema\n\nCreate all required tables by calling `SetupTables`. This should only happen once.\n\n```go\nif err := store.SetupTables(); err != nil {\n\tlog.Fatal(err)\n}\n```\n\n### 4. Create a graph backed by the store\n\nFinally, the store instance can be passed to `graph.NewWithStore`, which will create a graph backed\nby this store.\n\n```go \ng := graph.NewWithStore(graph.IntHash, store)\n```\n\n### 5. Full example\n\nA complete program that utilizes a MariaDB database to store a graph of integers may look like as\nfollows:\n\n```go\npackage main\n\nimport (\n\t\"database/sql\"\n\t\"log\"\n\n\t\"github.com/dominikbraun/graph\"\n\tgraphsql \"github.com/dominikbraun/graph-sql\"\n\t_ \"github.com/go-sql-driver/mysql\"\n)\n\nfunc main() {\n\tdb, err := sql.Open(\"mysql\", \"root:root@tcp(localhost:3306)/graph\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tstore := graphsql.New[int, int](db, graphsql.DefaultConfig)\n\n\tif err = store.SetupTables(); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tg := graph.NewWithStore(graph.IntHash, store)\n\n\t// This will persist two vertices and an edge in the database.\n\t_ = g.AddVertex(1)\n\t_ = g.AddVertex(2)\n\t_ = g.AddEdge(1, 2)\n}\n\n```\n\n## Configuration\n\nThe table schema created by `graph-sql` can be configured using a `Config` passed to `New`. You can\neither use the provided `DefaultConfig` or create your own one.\n\n| Field             | Description                              | Default    |\n|-------------------|------------------------------------------|------------|\n| `VerticesTable`   | The name of the vertices table.          | `vertices` |\n| `EdgesTable`      | The name of the edges table.             | `edges`    |\n| `VertexHashType`  | The database type of the vertex hashes.  | `TEXT`     |\n| `VertexValueType` | The database type of the vertex values.* | `JSON`     |\n\n*Vertex values are stored as JSON by this library.\n\n## Table schema\n\n### `vertices`\n\n| Column       | Type     | NULL | Key     | Extra            |\n|--------------|----------|------|---------|------------------|\n| `id`         | `BIGINT` | No   | Primary | `AUTO_INCREMENT` |\n| `hash`       | `TEXT`   | Yes  |         |                  |\n| `value`      | `JSON`   | Yes  |         |                  |\n| `weight`     | `INT`    | Yes  |         |                  |\n| `attributes` | `JSON`   | Yes  |         |                  |\n\n### `edges`\n\n| Column        | Type     | NULL | Key     | Extra            |\n|---------------|----------|------|---------|------------------|\n| `id`          | `BIGINT` | No   | Primary | `AUTO_INCREMENT` |\n| `source_hash` | `TEXT`   | Yes  |         |                  |\n| `target_hash` | `TEXT`   | Yes  |         |                  |\n| `weight`      | `INT`    | Yes  |         |                  |\n| `attributes`  | `JSON`   | Yes  |         |                  |\n| `data`        | `BLOB`   | Yes  |         |                  |\n\n## Graph operations\n\nCheck out the [graph](https://github.com/dominikbraun/graph) repository for an overview of built-in\ngraph algorithms and operations.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominikbraun%2Fgraph-sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdominikbraun%2Fgraph-sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominikbraun%2Fgraph-sql/lists"}