{"id":13671007,"url":"https://github.com/databendlabs/databend-go","last_synced_at":"2025-04-24T01:10:10.874Z","repository":{"id":61839605,"uuid":"554581194","full_name":"databendlabs/databend-go","owner":"databendlabs","description":"Golang driver for databend cloud","archived":false,"fork":false,"pushed_at":"2025-04-07T01:53:57.000Z","size":536,"stargazers_count":20,"open_issues_count":6,"forks_count":6,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-24T01:09:51.172Z","etag":null,"topics":[],"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/databendlabs.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":"2022-10-20T03:28:16.000Z","updated_at":"2025-04-07T01:54:02.000Z","dependencies_parsed_at":"2023-11-20T12:30:08.755Z","dependency_job_id":"8a2ac118-e751-4b21-bf82-23d4f8d75e44","html_url":"https://github.com/databendlabs/databend-go","commit_stats":{"total_commits":87,"total_committers":3,"mean_commits":29.0,"dds":0.6091954022988506,"last_synced_commit":"980d68278105f268c4e74fa9eb17b9941700d60b"},"previous_names":["databendcloud/godatabend","databendlabs/databend-go","datafuselabs/databend-go","databendcloud/databend-go"],"tags_count":71,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/databendlabs%2Fdatabend-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/databendlabs%2Fdatabend-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/databendlabs%2Fdatabend-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/databendlabs%2Fdatabend-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/databendlabs","download_url":"https://codeload.github.com/databendlabs/databend-go/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250540941,"owners_count":21447427,"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-08-02T09:00:55.640Z","updated_at":"2025-04-24T01:10:10.858Z","avatar_url":"https://github.com/databendlabs.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# databend-go\n\nGolang driver for [databend cloud](https://www.databend.com/)\n\n## Installation\n\n```\ngo get github.com/datafuselabs/databend-go\n```\n\n## Key features\n\n- Supports native Databend HTTP client-server protocol\n- Compatibility with [`database/sql`](#std-databasesql-interface)\n\n# Examples\n\n## Connecting\n\nConnection can be achieved either via a DSN string with the\nformat `https://user:password@host/database?\u003cquery_option\u003e=\u003cvalue\u003e` and sql/Open method such\nas `https://username:password@tenant--warehousename.ch.datafusecloud.com/test`.\n\n```go\nimport (\n\"database/sql\"\n_ \"github.com/datafuselabs/databend-go\"\n)\n\nfunc ConnectDSN() error {\ndsn, cfg, err := getDSN()\nif err != nil {\nlog.Fatalf(\"failed to create DSN from Config: %v, err: %v\", cfg, err)\n}\nconn, err := sql.Open(\"databend\", dsn)\nif err != nil {\nreturn err\n}\nreturn conn.Ping()\n}\n```\n\n## Connection Settings\n\nIf you are using the [databend cloud](https://app.databend.com/) you can get the connection settings using the following\nway.\n\n- host - the connect host such as `tenant--warehousename.ch.datafusecloud.com` that you can get from databend cloud as\n  follows:\n  \u003cimg width=\"1084\" alt=\"image\" src=\"https://user-images.githubusercontent.com/7600925/201461064-d503cfb3-43e0-4c7c-b270-2898452ebc8e.png\"\u003e\n\n- username/password - auth credentials that you can get from databend cloud connect page as above\n- database - select the current default database\n\n## Execution\n\nOnce a connection has been obtained, users can issue sql statements for execution via the Exec method.\n\n```go\n    dsn, cfg, err := getDSN()\nif err != nil {\nlog.Fatalf(\"failed to create DSN from Config: %v, err: %v\", cfg, err)\n}\nconn, err := sql.Open(\"databend\", dsn)\nif err != nil {\nfmt.Println(err)\n}\nconn.Exec(`DROP TABLE IF EXISTS data`)\n_, err = conn.Exec(`\n    CREATE TABLE IF NOT EXISTS  data(\n        Col1 TINYINT,\n        Col2 VARCHAR\n    )`)\nif err != nil {\nfmt.Println(err)\n}\n_, err = conn.Exec(\"INSERT INTO data VALUES (1, 'test-1')\")\n```\n\n## Batch Insert\n\nIf the create table SQL is `CREATE TABLE test (\ni64 Int64,\nu64 UInt64,\nf64 Float64,\ns   String,\ns2  String,\na16 Array(Int16),\na8  Array(UInt8),\nd   Date,\nt   DateTime)`\nyou can use the next code to batch insert data:\n\n```go\npackage main\n\nimport (\n\t\"database/sql\"\n\t\"fmt\"\n\n\t_ \"github.com/datafuselabs/databend-go\"\n)\n\nfunc main() {\n\tconn, err := sql.Open(\"databend\", \"http://databend:databend@localhost:8000/default?sslmode=disable\")\n\ttx, err := conn.Begin()\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tbatch, err := tx.Prepare(fmt.Sprintf(\"INSERT INTO %s VALUES\", \"test\"))\n\tfor i := 0; i \u003c 10; i++ {\n\t\t_, err = batch.Exec(\n\t\t\t\"1234\",\n\t\t\t\"2345\",\n\t\t\t\"3.1415\",\n\t\t\t\"test\",\n\t\t\t\"test2\",\n\t\t\t\"[4, 5, 6]\",\n\t\t\t\"[1, 2, 3]\",\n\t\t\t\"2021-01-01\",\n\t\t\t\"2021-01-01 00:00:00\",\n\t\t)\n\t}\n\terr = tx.Commit()\n}\n```\n\n## Querying Row/s\n\nQuerying a single row can be achieved using the QueryRow method. This returns a *sql.Row, on which Scan can be invoked\nwith pointers to variables into which the columns should be marshaled.\n\n```go\npackage main\n\nimport (\n\t\"database/sql\"\n\t\"fmt\"\n\n\t_ \"github.com/datafuselabs/databend-go\"\n)\n\nfunc main() {\n\t// create table data (col1 uint8, col2 string);\n\t// insert into data values(1,'col2');\n\tconn, err := sql.Open(\"databend\", \"http://databend:databend@localhost:8000/default?sslmode=disable\")\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\trow := conn.QueryRow(\"SELECT * FROM data\")\n\tvar (\n\t\tcol1 uint8\n\t\tcol2 string\n\t)\n\tif err := row.Scan(\u0026col1, \u0026col2); err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Println(col2)\n}\n```\n\nIterating multiple rows requires the Query method. This returns a *sql.Rows struct on which Next can be invoked to\niterate through the rows. QueryContext equivalent allows passing of a context.\n\n```go\npackage main\n\nimport (\n\t\"database/sql\"\n\t\"fmt\"\n\n\t_ \"github.com/datafuselabs/databend-go\"\n)\n\nfunc main() {\n\t// create table data (col1 uint8, col2 string);\n\t// insert into data values(1,'col2');\n\tconn, err := sql.Open(\"databend\", \"http://databend:databend@localhost:8000/default?sslmode=disable\")\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\trow, err := conn.Query(\"SELECT * FROM data\")\n\tvar (\n\t\tcol1 uint8\n\t\tcol2 string\n\t)\n\tfor row.Next() {\n\t\tif err := row.Scan(\u0026col1, \u0026col2); err != nil {\n\t\t\tfmt.Println(err)\n\t\t}\n\t\tfmt.Println(col2)\n\t}\n}\n```\n\n## Type Mapping\n\nThe following table outlines the mapping between Databend types and Go types:\n\n| Databend Type      | Go Type   |\n|--------------------|-----------|\n| TINYINT            | int8      |\n| SMALLINT           | int16     |\n| INT                | int32     |\n| BIGINT             | int64     |\n| TINYINT UNSIGNED   | uint8     |\n| SMALLINT UNSIGNED  | uint16    |\n| INT UNSIGNED       | uint32    |\n| BIGINT UNSIGNED    | uint64    |\n| Float32            | float32   |\n| Float64            | float64   |\n| Bitmap             | string    |\n| Decimal            | decimal.Decimal|\n| String             | string    |\n| Date               | time.Time |\n| DateTime           | time.Time |\n| Array(T)           | string    |\n| Tuple(T1, T2, ...) | string    |\n| Variant            | string    |\n\n## Compatibility\n\n- If databend version \u003e= v0.9.0 or later, you need to use databend-go version \u003e= v0.3.0.\n- If databend version \u003c 1.2.371, you need to use databend-go version \u003c 0.5.7 and if your databend version \u003e= 1.2.371, you need the databend-go version \u003e=0.5.7. Because from [1.2.371](https://github.com/datafuselabs/databend/releases/tag/v1.2.371), databend support transaction and databend-go has some brake changes. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatabendlabs%2Fdatabend-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatabendlabs%2Fdatabend-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatabendlabs%2Fdatabend-go/lists"}