{"id":15041100,"url":"https://github.com/aobt/sqlmapper","last_synced_at":"2026-01-12T00:05:54.119Z","repository":{"id":57485252,"uuid":"130193734","full_name":"aobt/sqlmapper","owner":"aobt","description":"sqlmapper is a light mapper between go-struct and table-rows in db","archived":false,"fork":false,"pushed_at":"2020-09-10T06:14:15.000Z","size":10,"stargazers_count":103,"open_issues_count":3,"forks_count":35,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-28T08:04:30.173Z","etag":null,"topics":["db","go","golang","mapper","mysql","sql","struct","table"],"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/aobt.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-04-19T09:43:24.000Z","updated_at":"2024-09-25T08:35:38.000Z","dependencies_parsed_at":"2022-08-26T12:21:05.391Z","dependency_job_id":null,"html_url":"https://github.com/aobt/sqlmapper","commit_stats":null,"previous_names":["arthas29/sqlmapper"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aobt%2Fsqlmapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aobt%2Fsqlmapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aobt%2Fsqlmapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aobt%2Fsqlmapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aobt","download_url":"https://codeload.github.com/aobt/sqlmapper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248949640,"owners_count":21188115,"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":["db","go","golang","mapper","mysql","sql","struct","table"],"created_at":"2024-09-24T20:45:32.923Z","updated_at":"2026-01-12T00:05:54.111Z","avatar_url":"https://github.com/aobt.png","language":"Go","readme":"##### `sqlmapper` is a light mapper between `golang struct` and `table rows` in db\n\n#### example\nWe need to read/write a table in db, like:\n```sql\nCREATE TABLE `test_table` (\n  `field_key` varchar(64) NOT NULL DEFAULT '',\n  `field_one` varchar(64) DEFAULT NULL,\n  `field_two` tinyint(1) DEFAULT NULL,\n  `field_thr` int(12) DEFAULT NULL,\n  `field_fou` float DEFAULT NULL,\n  PRIMARY KEY (`field_key`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n```\nIn golang, we create a struct corresponding to the table, like:\n```go\n// struct in go such as:\ntype DemoRow struct {\n\tFieldKey string  `sql:\"field_key\"`\n\tFieldOne string  `sql:\"field_one\"`\n\tFieldTwo bool    `sql:\"field_two\"`\n\tFieldThr int64   `sql:\"field_thr\"`\n\tFieldFou float64 `sql:\"field_fou\"`\n}\n```\nThen, we can execute `SELECT`/`INSERT`/`UPDATE`/`DELETE` \nwithout long `Hard-Code` sql string which is easy to make mistakes.\n\n#### sample (follow [fields_map_test.go](https://github.com/arthas29/sqlmapper/blob/master/fields_map_test.go) for more):\n```go\n\n// select single row\n// Query by primary key (field[0])\nfunc QueryByKey(ctx context.Context, tx *sql.Tx, db *sql.DB, fieldKey string) (\n\t*DemoRow, error) {\n\n\tvar row DemoRow\n\trow.FieldKey = fieldKey\n\tfm, err := NewFieldsMap(table, \u0026row)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tobjptr, err := fm.SQLSelectByPriKey(ctx, tx, db)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn objptr.(*DemoRow), nil\n}\n    \n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faobt%2Fsqlmapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faobt%2Fsqlmapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faobt%2Fsqlmapper/lists"}