{"id":14956063,"url":"https://github.com/ipfs/go-ds-sql","last_synced_at":"2025-04-04T13:06:41.543Z","repository":{"id":42468433,"uuid":"53704560","full_name":"ipfs/go-ds-sql","owner":"ipfs","description":"An implementation of ipfs/go-datastore that can be backed by any SQL database.","archived":false,"fork":false,"pushed_at":"2025-03-24T09:21:11.000Z","size":65,"stargazers_count":33,"open_issues_count":3,"forks_count":15,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-03-28T12:03:01.256Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/ipfs.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-12T00:12:35.000Z","updated_at":"2025-03-17T21:30:32.000Z","dependencies_parsed_at":"2024-06-18T15:23:29.936Z","dependency_job_id":"f73ee8a6-2a28-450f-bc46-bcef2a492cd2","html_url":"https://github.com/ipfs/go-ds-sql","commit_stats":{"total_commits":43,"total_committers":15,"mean_commits":"2.8666666666666667","dds":0.7209302325581395,"last_synced_commit":"c11912992a3ba1cf8e8cd6a3e59a67992c5f94b1"},"previous_names":["whyrusleeping/sql-datastore"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs%2Fgo-ds-sql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs%2Fgo-ds-sql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs%2Fgo-ds-sql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs%2Fgo-ds-sql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ipfs","download_url":"https://codeload.github.com/ipfs/go-ds-sql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247174458,"owners_count":20896078,"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":[],"created_at":"2024-09-24T13:12:15.573Z","updated_at":"2025-04-04T13:06:41.525Z","avatar_url":"https://github.com/ipfs.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQL Datastore\n\n[![CircleCI](https://circleci.com/gh/ipfs/go-ds-sql.svg?style=shield)](https://circleci.com/gh/ipfs/go-ds-sql)\n[![Coverage](https://codecov.io/gh/ipfs/go-ds-sql/branch/master/graph/badge.svg)](https://codecov.io/gh/ipfs/go-ds-sql)\n[![Standard README](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg)](https://github.com/RichardLitt/standard-readme)\n[![GoDoc](http://img.shields.io/badge/godoc-reference-5272B4.svg)](https://godoc.org/github.com/ipfs/go-ds-sql)\n[![golang version](https://img.shields.io/badge/golang-%3E%3D1.14.0-orange.svg)](https://golang.org/)\n[![Go Report Card](https://goreportcard.com/badge/github.com/ipfs/go-ds-sql)](https://goreportcard.com/report/github.com/ipfs/go-ds-sql)\n\nAn implementation of [the datastore interface](https://github.com/ipfs/go-datastore)\nthat can be backed by any sql database.\n\n## Install\n\n```sh\ngo get github.com/ipfs/go-ds-sql\n```\n\n## Usage\n\n### PostgreSQL\n\nEnsure a database is created and a table exists with `key` and `data` columns. For example, in PostgreSQL you can create a table with the following structure (replacing `table_name` with the name of the table the datastore will use - by default this is `blocks`):\n\n```sql\nCREATE TABLE IF NOT EXISTS table_name (key TEXT NOT NULL UNIQUE, data BYTEA)\n```\n\nIt's recommended to create an index on the `key` column that is optimised for prefix scans. For example, in PostgreSQL you can create a `text_pattern_ops` index on the table:\n\n```sql\nCREATE INDEX IF NOT EXISTS table_name_key_text_pattern_ops_idx ON table_name (key text_pattern_ops)\n```\n\nImport and use in your application:\n\n```go\nimport (\n\t\"database/sql\"\n\t\"github.com/ipfs/go-ds-sql\"\n\tpg \"github.com/ipfs/go-ds-sql/postgres\"\n)\n\nmydb, _ := sql.Open(\"yourdb\", \"yourdbparameters\")\n\n// Implement the Queries interface for your SQL impl.\n// ...or use the provided PostgreSQL queries\nqueries := pg.NewQueries(\"blocks\")\n\nds := sqlds.NewDatastore(mydb, queries)\n```\n\n### SQLite\n\nThe [SQLite](https://sqlite.org) wrapper tries to create the table automatically\n\nPrefix scans are optimized by using GLOB\n\nImport and use in your application:\n\n```go\npackage main\n\nimport (\n\tsqliteds \"github.com/ipfs/go-ds-sql/sqlite\"\n\t_ \"github.com/mattn/go-sqlite3\"\n)\n\nfunc main() {\n\topts := \u0026sqliteds.Options{\n\t\tDSN: \"db.sqlite\",\n\t}\n\n\tds, err := opts.Create()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer func() {\n\t\tif err := ds.Close(); err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t}()\n}\n```\n\nIf no `DSN` is specified, an unique in-memory database will be created\n\n### SQLCipher\n\nThe SQLite wrapper also supports the [SQLCipher](https://www.zetetic.net/sqlcipher/) extension\n\nImport and use in your application:\n\n```go\npackage main\n\nimport (\n\tsqliteds \"github.com/ipfs/go-ds-sql/sqlite\"\n\t_ \"github.com/mutecomm/go-sqlcipher/v4\"\n)\n\nfunc main() {\n\topts := \u0026sqliteds.Options{\n\t\tDSN: \"encdb.sqlite\",\n\t\tKey: ([]byte)(\"32_very_secure_bytes_0123456789a\"),\n\t}\n\n\tds, err := opts.Create()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer func() {\n\t\tif err := ds.Close(); err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t}()\n}\n```\n\n## API\n\n[GoDoc Reference](https://godoc.org/github.com/ipfs/go-ds-sql)\n\n## Contribute\n\nFeel free to dive in! [Open an issue](https://github.com/ipfs/go-ds-sql/issues/new) or submit PRs.\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipfs%2Fgo-ds-sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fipfs%2Fgo-ds-sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipfs%2Fgo-ds-sql/lists"}