{"id":22152270,"url":"https://github.com/auula/gsql","last_synced_at":"2025-07-26T05:32:12.222Z","repository":{"id":47184416,"uuid":"402410456","full_name":"auula/gsql","owner":"auula","description":"GSQL is a structured query language code builder for golang.","archived":false,"fork":false,"pushed_at":"2021-09-12T08:34:27.000Z","size":88,"stargazers_count":106,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-19T00:30:15.868Z","etag":null,"topics":["builder","code","d-s-l","dsl","dsl-sql-go","dsl-syntax","genreate","golang","languages","query-language","sql","structured-data"],"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/auula.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":"2021-09-02T12:22:45.000Z","updated_at":"2024-01-04T17:00:59.000Z","dependencies_parsed_at":"2022-08-20T10:10:15.509Z","dependency_job_id":null,"html_url":"https://github.com/auula/gsql","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/auula%2Fgsql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/auula%2Fgsql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/auula%2Fgsql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/auula%2Fgsql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/auula","download_url":"https://codeload.github.com/auula/gsql/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227652567,"owners_count":17799235,"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","code","d-s-l","dsl","dsl-sql-go","dsl-syntax","genreate","golang","languages","query-language","sql","structured-data"],"created_at":"2024-12-02T00:49:29.164Z","updated_at":"2024-12-02T00:49:32.173Z","avatar_url":"https://github.com/auula.png","language":"Go","readme":"# GSQL\n\nGSQL is a structured query language code builder for golang.\n\n## Genreate SQL\n\n1. Model Structured\n\n```go\ntype UserInfo struct {\n\tId   int    `db:\"id\" pk:\"id\"`\n\tName string `db:\"name\"`\n\tAge  int    `db:\"age\"`\n}\n```\n\n`db` identifies the database table field，`pk` is the primary key.\n\n2. Simple query\n\n```go\nsql1 := gsql.Select().From(UserInfo{})\n\n// SELECT id, name, age FROM UserInfo\nt.Log(sql1)\n```\n\n\n3. Alias and pass primary key\n\n```go\n\nsql2 := gsql.SelectAs([]string{\"name\", gsql.As(\"age\", \"年龄\"), \"id\"}).From(UserInfo{}).ById(2)\n\n// SELECT name, age AS '年龄' FROM UserInfo WHERE  id = 2\nt.Log(sql2)\n\n\nsql3 := gsql.SelectAs(gsql.Alias(UserInfo{}, map[string]string{\n    \"name\": \"名字\",\n})).From(UserInfo{}).ById(1)\n\n// SELECT id, name AS '名字', age FROM UserInfo WHERE  id = 1\nt.Log(sql3)\n```\n`SelectAs` if the parameter is `slice`，`id = pk:\"id\"` The last parameter must be the primary key field of the table.\n\n4. Query a set of data to provide the primary key\n\n```go\nsql := gsql.Select().From(UserInfo{}).ByIds(1, 2, 3)\n\n// SELECT id, name, age FROM UserInfo WHERE id IN (1, 2, 3)\nt.Log(sql)\n```\n\n5. Query by `In`\n```go\nsql := gsql.Select().From(UserInfo{}).In(\"age\", 21, 19, 28)\n\n// SELECT id, name, age FROM UserInfo WHERE age IN (21, 19, 28)\nt.Log(sql)\n```\n\n6. Query a piece of data\n\n```go\nfunc TestSelectOne(t *testing.T) {\n\t\n\t// SELECT id, name, age FROM UserInfo LIMIT 1\n\t_, sql := gsql.Select().From(UserInfo{}).One()\n\tt.Log(sql)\n\n\t// SELECT id, name, age FROM UserInfo WHERE age \u003e 10 LIMIT 1\n\terr, sql2 := gsql.Select().From(UserInfo{}).Where(\"age \u003e ?\", 10).One()\n\n\tif err == nil {\n\t\tt.Log(sql2)\n\t}\n}\n```\n\n7. Sort or filter\n```go\nfunc TestSelectLimit(t *testing.T) {\n\n\t// SELECT id, name, age FROM UserInfo WHERE age \u003e 10 LIMIT 3 OFFSET 1\n\tsql2 := gsql.Select().From(UserInfo{}).Where(\"age \u003e ?\", 10).Limit(true, 1, 3)\n\n\tt.Log(sql2)\n\n}\n\nfunc TestSelectOrder(t *testing.T) {\n\n\t// SELECT id, name, age FROM UserInfo WHERE age \u003e 10 ORDER BY id ASC LIMIT 3 OFFSET 1\n\tsql2 := gsql.Select().From(UserInfo{}).Where(\"age \u003e ?\", 10).Order([]gsql.Rows{\n\t\t{\"id\", \"ASC\"},\n\t}).Limit(true, 1, 3)\n\n\tt.Log(sql2)\n\n}\n```\n\n8. Insert Data to table\n\n```go\nfunc TestInsert(t *testing.T) {\n\t// INSERT INTO UserInfo (id, name, age) VALUES (1001, 'Tom', 21)\n\tsql := gsql.Insert(UserInfo{}, nil).Values(1001, \"Tom\", 21)\n\tt.Log(sql)\n}\n\nfunc TestInsertFilter(t *testing.T) {\n\t// INSERT INTO UserInfo (name, age) VALUES ('Tom', 21)\n\terr, sql := gsql.Insert(UserInfo{}, []string{\"id\"}).Values(\"Tom\", 21).Build()\n\tif err != nil {\n\t\tt.Log(err)\n\t}\n\tt.Log(sql)\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauula%2Fgsql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fauula%2Fgsql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauula%2Fgsql/lists"}