{"id":22332761,"url":"https://github.com/xgfone/go-sqlx","last_synced_at":"2025-07-29T19:33:30.493Z","repository":{"id":48518828,"uuid":"256525766","full_name":"xgfone/go-sqlx","owner":"xgfone","description":"A set of the simple, flexible and powerful SQL builders with zero-config.","archived":false,"fork":false,"pushed_at":"2024-10-25T09:23:05.000Z","size":243,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-30T20:49:10.976Z","etag":null,"topics":["builder","database","go","go-sql","golang","mysql","sql","sql-builder","sqlbuilder"],"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/xgfone.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":"2020-04-17T14:29:31.000Z","updated_at":"2024-10-25T09:23:09.000Z","dependencies_parsed_at":"2024-05-29T12:28:44.110Z","dependency_job_id":"79a308b7-ba41-4625-9515-d0d31fb95703","html_url":"https://github.com/xgfone/go-sqlx","commit_stats":null,"previous_names":["xgfone/sqlx"],"tags_count":59,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-sqlx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-sqlx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-sqlx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-sqlx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xgfone","download_url":"https://codeload.github.com/xgfone/go-sqlx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228042051,"owners_count":17860360,"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":["builder","database","go","go-sql","golang","mysql","sql","sql-builder","sqlbuilder"],"created_at":"2024-12-04T04:19:38.018Z","updated_at":"2025-07-29T19:33:30.477Z","avatar_url":"https://github.com/xgfone.png","language":"Go","readme":"# SQL Builder\n\n[![Build Status](https://github.com/xgfone/go-sqlx/actions/workflows/go.yml/badge.svg)](https://github.com/xgfone/go-sqlx/actions/workflows/go.yml)\n[![GoDoc](https://pkg.go.dev/badge/github.com/xgfone/go-sqlx)](https://pkg.go.dev/github.com/xgfone/go-sqlx)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square)](https://raw.githubusercontent.com/xgfone/go-sqlx/master/LICENSE)\n![Minimum Go Version](https://img.shields.io/github/go-mod/go-version/xgfone/go-sqlx?label=Go%2B)\n![Latest SemVer](https://img.shields.io/github/v/tag/xgfone/go-sqlx?sort=semver)\n\nPackage `sqlx` provides a set of flexible and powerful SQL builders, not ORM, which is inspired by [go-sqlbuilder](https://github.com/huandu/go-sqlbuilder). The built result can be used by [`DB.Query()`](https://pkg.go.dev/database/sql#DB.Query) and [`DB.Exec()`](https://pkg.go.dev/database/sql#DB.Exec)\n\n## Install\n\n```shell\n$ go get -u github.com/xgfone/go-sqlx\n```\n\n## Usage\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/xgfone/go-op\"\n\t\"github.com/xgfone/go-sqlx\"\n)\n\nfunc main() {\n\tbuilder := sqlx.Select(\"*\").From(\"table\")\n\tbuilder.Where(op.Equal(\"id\", 123), op.Between(\"age\", 20, 30))\n\n\t// You can set the dialect by hand, which is DefaultDialect by default.\n\t// DefaultDialect is the MySQL dialect, but you can modify it.\n\t// builder.SetDialect(Sqlite3)\n\n\tsql, args := builder.Build()\n\tfmt.Println(sql)\n\tfmt.Println(args)\n\n\t// Output:\n\t// SELECT * FROM `table` WHERE (`id`=? AND `age` BETWEEN ? AND ?)\n\t// [123 20 30]\n}\n```\n\nYou can use `sqlx.DB`, which is the proxy of builder and `sql.DB`, it will automatically set the dialect by the sql driver name. For example,\n\n```go\n// Set the dialect to MySQL.\ndb, _ := sqlx.Open(\"mysql\", \"user:password@tcp(127.0.0.1:3306)/db\")\nbuilder := db.Select(\"*\").From(\"table\").Where(op.Equal(\"id\", 123))\n\nsql, args := builder.Build()\nrows := db.QueryRows(sql, args.Args()...)\n\n// Or\n// rows := builder.QueryRows()\n\nif rows.Err != nil {\n\t// TODO: ...\n\treturn\n}\n\ndefer rows.Close()\n// TODO: ...\n```\n\n### Intercept SQL\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/xgfone/go-op\"\n\t\"github.com/xgfone/go-sqlx\"\n)\n\nfunc main() {\n\t// Open DB connecting the mysql server and set the dialect to MySQL.\n\tdb, err := sqlx.Open(\"mysql\", \"user:password@tcp(127.0.0.1:3306)/db\")\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\tdefer db.Close()\n\n\t// Set the interceptor to print the sql statement.\n\tdb.Interceptor = sqlx.InterceptorFunc(func(sql string, args []any) (string, []any, error) {\n\t\tfmt.Println(sql)\n\t\treturn sql, args, nil\n\t})\n\n\t// Build the SELECT SQL statement\n\tbuilder := db.Select(\"*\").From(\"table\")\n\tbuilder.Where(op.Equal(\"id\", 123))\n\trows := builder.QueryRows()\n\tif rows.Err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\t// TODO: ...\n\n\t// Interceptor will output:\n\t// SELECT * FROM `table` WHERE `id`=?\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxgfone%2Fgo-sqlx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxgfone%2Fgo-sqlx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxgfone%2Fgo-sqlx/lists"}