{"id":23818940,"url":"https://github.com/rogozhka/query","last_synced_at":"2025-02-21T22:16:20.889Z","repository":{"id":32503629,"uuid":"119105541","full_name":"rogozhka/query","owner":"rogozhka","description":"Tiny Go package to fetch SQL rows as a slice of map[string]string","archived":false,"fork":false,"pushed_at":"2022-11-28T19:51:06.000Z","size":27,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-02T06:19:16.111Z","etag":null,"topics":["golang-library","mysql","sql"],"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/rogozhka.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":"2018-01-26T21:32:13.000Z","updated_at":"2024-11-27T20:31:17.000Z","dependencies_parsed_at":"2023-01-14T21:26:01.875Z","dependency_job_id":null,"html_url":"https://github.com/rogozhka/query","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rogozhka%2Fquery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rogozhka%2Fquery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rogozhka%2Fquery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rogozhka%2Fquery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rogozhka","download_url":"https://codeload.github.com/rogozhka/query/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240094991,"owners_count":19746792,"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-library","mysql","sql"],"created_at":"2025-01-02T06:19:23.893Z","updated_at":"2025-02-21T22:16:20.867Z","avatar_url":"https://github.com/rogozhka.png","language":"Go","readme":"**Query** is a tiny package for executing select-like queries and converting `sql.Rows` into slice of `map[string]string`. The new map is allocated for each row. Keys are column names as seen in sql.\n\n\n\n## Install\n\nUse go modules and just\n```\nimport \"github.com/rogozhka/query\"\n``` \n\nor \n\n```bash\ngo get -u github.com/rogozhka/query\n```\n\n\n\n## Example\n\n```go\npackage main\n\nimport (\n\t\"github.com/rogozhka/query\"\n\n\t\"database/sql\"\n\t\"fmt\"\n\t\"log\"\n\t\n\t_ \"github.com/go-sql-driver/mysql\"\n)\n\nfunc main() {\n\n\tdb, err := sql.Open(\"mysql\",\n\t\t\"username:pass@tcp(hostname)/database_name\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tif db == nil {\n\t\tpanic(fmt.Errorf(\"db is nil\"))\n\t}\n\tdefer db.Close()\n\n\t// fetch all the rows into slice of map[string]string\n\trows, err := query.Fetch(\"SELECT * FROM `example_table`\", db)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfor _, row := range rows {\n\t\tfor colName, val := range row {\n\t\t\tlog.Printf(\"%s:%s\", colName, val)\n\t\t}\n\t}\n\n\t// fetch only 1 row\n\t// in real project you should use LIMIT 0,1\n\t// but there is limited version of method ;)\n\trows2, err := query.FetchLimited(\"SELECT * FROM `example_table`\", 1, db)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tif len(rows2) \u003e 0 {\n\t\tfor colName, val := range rows2[0] {\n\t\t\tlog.Printf(\"%s:%s\", colName, val)\n\t\t}\n\t}\n}\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frogozhka%2Fquery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frogozhka%2Fquery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frogozhka%2Fquery/lists"}