{"id":13614187,"url":"https://github.com/rakyll/go-sql-driver-spanner","last_synced_at":"2025-04-07T00:33:43.001Z","repository":{"id":43061749,"uuid":"242247220","full_name":"rakyll/go-sql-driver-spanner","owner":"rakyll","description":"Google Cloud Spanner driver for Go","archived":false,"fork":false,"pushed_at":"2022-03-21T11:33:50.000Z","size":34,"stargazers_count":89,"open_issues_count":2,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-22T10:13:30.328Z","etag":null,"topics":["golang","golang-database","google-cloud-spanner"],"latest_commit_sha":null,"homepage":"","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/rakyll.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":"2020-02-21T23:16:49.000Z","updated_at":"2024-09-11T06:05:16.000Z","dependencies_parsed_at":"2022-09-10T06:50:51.331Z","dependency_job_id":null,"html_url":"https://github.com/rakyll/go-sql-driver-spanner","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/rakyll%2Fgo-sql-driver-spanner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rakyll%2Fgo-sql-driver-spanner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rakyll%2Fgo-sql-driver-spanner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rakyll%2Fgo-sql-driver-spanner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rakyll","download_url":"https://codeload.github.com/rakyll/go-sql-driver-spanner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247574088,"owners_count":20960495,"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":["golang","golang-database","google-cloud-spanner"],"created_at":"2024-08-01T20:00:58.145Z","updated_at":"2025-04-07T00:33:42.759Z","avatar_url":"https://github.com/rakyll.png","language":"Go","funding_links":[],"categories":["Libraries and ORM","Go"],"sub_categories":["Drivers"],"readme":"# go-sql-driver-spanner\n\n[![CircleCI](https://circleci.com/gh/rakyll/go-sql-driver-spanner.svg?style=svg)](https://circleci.com/gh/rakyll/go-sql-driver-spanner) [![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/github.com/rakyll/go-sql-driver-spanner)\n\n[Google Cloud Spanner](https://cloud.google.com/spanner) driver for\nGo's [database/sql](https://golang.org/pkg/database/sql/) package.\n\n\nTHIS IS A WORK-IN-PROGRESS, DON'T USE IT IN PRODUCTION YET.\n\n``` go\nimport _ \"github.com/rakyll/go-sql-driver-spanner\"\n\ndb, err := sql.Open(\"spanner\", \"projects/PROJECT/instances/INSTANCE/databases/DATABASE\")\nif err != nil {\n    log.Fatal(err)\n}\n\n// Print tweets with more than 500 likes.\nrows, err := db.QueryContext(ctx, \"SELECT id, text FROM tweets WHERE likes \u003e @likes\", 500)\nif err != nil {\n    log.Fatal(err)\n}\ndefer rows.Close()\n\nvar (\n    id   int64\n    text string\n)\nfor rows.Next() {\n    if err := rows.Scan(\u0026id, \u0026text); err != nil {\n        log.Fatal(err)\n    }\n    fmt.Println(id, text)\n}\n```\n\n## Statements\n\nStatements support follows the official [Google Cloud Spanner Go](https://pkg.go.dev/cloud.google.com/go/spanner) client style arguments.\n\n```go\ndb.QueryContext(ctx, \"SELECT id, text FROM tweets WHERE likes \u003e @likes\", 500)\n\ndb.ExecContext(ctx, \"INSERT INTO tweets (id, text, rts) VALUES (@id, @text, @rts)\", id, text, 10000)\n\ndb.ExecContext(ctx, \"DELETE FROM tweets WHERE id = @id\", 14544498215374)\n```\n\n## Transactions\n\n- Read-only transactions do strong-reads only.\n- Read-write transactions always uses the strongest isolation\nlevel and ignore the user-specified level.\n\n``` go\ntx, err := db.BeginTx(ctx, \u0026sql.TxOptions{\n    ReadOnly: true, // Read-only transaction.\n})\n\ntx, err := db.BeginTx(ctx, \u0026sql.TxOptions{}) // Read-write transaction.\n```\n\n## Emulator\n\nSee the [Google Cloud Spanner Emulator](https://cloud.google.com/spanner/docs/emulator) support to learn how to start the emulator.\nOnce the emulator is started and the host environmental flag is set, the driver should just work.\n\n```\n$ gcloud beta emulators spanner start\n$ export SPANNER_EMULATOR_HOST=localhost:9010\n```\n\n## Troubleshooting\n\nThis driver shouldn't automatically retry the transactions but it does.\nIt causes unwanted results. Don't use this library in production yet.\n\n---\n\ngorm cannot use the driver as it-is but @rakyll has been working on a dialect.\nShe doesn't have bandwidth to ship a fully featured dialect right now but contact\nher if you would like to contribute.\n\n---\n\n`error = \u003cuse T(nil), not nil\u003e`: Use a typed nil, instead of just nil.\n\nThe following query returns rows with NULL likes:\n\n``` go\nvar nilInt64 *int64\ndb.QueryContext(ctx, \"SELECT id, text FROM tweets WHERE likes = @likes LIMIT 10\", nilInt64)\n```\n\n---\n\nWhen querying and executing with emails, pass them as arguments and don't hardcode\nthem in the query:\n\n``` go\ndb.QueryContext(ctx, \"SELECT id, name ... WHERE email = @email\", \"jbd@google.com\")\n```\n\nThe driver will relax this requirement in the future but it is a work-in-progress for now.\n\n---\n\n[DDLs](https://cloud.google.com/spanner/docs/data-definition-language)\nare not supported in the transactions per Cloud Spanner restriction.\nInstead, run them against the database:\n\n```go\ndb.ExecContext(ctx, \"CREATE TABLE ...\")\n```\n\n## Disclaimer\n\nThis is not an officially supported Google Cloud product.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frakyll%2Fgo-sql-driver-spanner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frakyll%2Fgo-sql-driver-spanner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frakyll%2Fgo-sql-driver-spanner/lists"}