{"id":31731087,"url":"https://github.com/blakewilliams/dbmap","last_synced_at":"2025-10-09T07:48:16.301Z","repository":{"id":313221286,"uuid":"1050547919","full_name":"BlakeWilliams/dbmap","owner":"BlakeWilliams","description":"a minimalistic db/struct mapper for Go","archived":false,"fork":false,"pushed_at":"2025-09-27T20:56:23.000Z","size":114,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-28T09:55:44.178Z","etag":null,"topics":[],"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/BlakeWilliams.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-04T15:28:20.000Z","updated_at":"2025-09-27T20:56:26.000Z","dependencies_parsed_at":"2025-09-08T17:28:53.136Z","dependency_job_id":null,"html_url":"https://github.com/BlakeWilliams/dbmap","commit_stats":null,"previous_names":["blakewilliams/microrm","blakewilliams/dbmap"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/BlakeWilliams/dbmap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlakeWilliams%2Fdbmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlakeWilliams%2Fdbmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlakeWilliams%2Fdbmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlakeWilliams%2Fdbmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BlakeWilliams","download_url":"https://codeload.github.com/BlakeWilliams/dbmap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlakeWilliams%2Fdbmap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000974,"owners_count":26082974,"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","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-10-09T07:48:12.306Z","updated_at":"2025-10-09T07:48:16.295Z","avatar_url":"https://github.com/BlakeWilliams.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DBmap\n\n`dbmap` is a minimalistic \"ORM\"/database mapper for Go that provides basic utilities for mapping Go structs to database tables with a focus on ease-of-use.\n\n## Example usage\n\nThe primary goal of DBMap is to reduce boilerplate and help developers fall into the \"pit of success\". For example, all queries run through `dbmap` use named parameters to avoid easy-to-make mistakes with positional parameters.\n\ne.g. `WHERE id = $ID` instead of `WHERE id = ?` + positional args.\n\n```go\nconn := sql.Open(\"sqlite3\", \":memory:\")\ndefer conn.Close()\ndb := dbmap.New(conn)\n\ntype User struct {\n    ID   int    `db:\"id\"`\n    Name string `db:\"name\"`\n\n    // Created and Updated at timestamps are automatically updated\n    UpdatedAt time.Time `db:\"updated_at\"`\n    CreatedAt time.Time `db:\"created_at\"`\n}\n\n// By default, table names are pluralized struct names (i.e. \"users\" for User),\n// but you can override this by implementing the TableName method.\nfunc (u *User) TableName() string {\n    return \"my_users\"\n}\n\n// Select a single record\nvar user User\n// dbmap automatically generates the necessary columns and table name\nerr := db.Select(ctx, \u0026user, \"WHERE id = $ID\", dbmap.Args{\"ID\": 1})\n\n// Select multiple records\nvar users []User\nerr = db.Select(ctx, \u0026users, \"WHERE name LIKE $pattern\", dbmap.Args{\"pattern\": \"A%\"})\n\n// Insert a new record\nnewUser := User{Name: \"Alice\"}\nerr = db.Insert(ctx, \u0026newUser)\nfmt.Println(\"New user ID:\", newUser.ID) // ID's are automatically populated after inserts\n\n// Update a specific record by ID\nuser := \u0026User{ID: 1, Name: \"Alice\"}\nerr = db.UpdateRecord(ctx, user, dbmap.Updates{\"name\": \"Alicia\"})\n// The struct is automatically updated in memory\nfmt.Println(\"Updated user name:\", user.Name)\n\n// Update arbitrary rows\nrowsAffected, err := db.Update(ctx, \u0026User{}, \"WHERE name = $name\", dbmap.Args{\"name\": \"Alice\"}, dbmap.Updates{\"name\": \"Alicia\"})\nfmt.Println(\"Updated rows:\", rowsAffected)\n\n// Delete a specific record (uses ID)\nuser := User{ID: 1, Name: \"Alice\"}\nrowsAffected, err = db.DeleteRecord(ctx, \u0026user)\n\n// Delete multiple records (uses ID)\nusers := []*User{\n    {ID: 1, Name: \"Alice\"},\n    {ID: 2, Name: \"Bob\"},\n}\nrowsAffected, err = db.DeleteRecords(ctx, users)\n\n// Delete arbitrary records\nrowsAffected, err = db.Delete(ctx, \u0026User{}, \"WHERE name = $name\", dbmap.Args{\"name\": \"Alicia\"})\nfmt.Println(\"Deleted rows:\", rowsAffected)\n```\n\n### Escaping $\n\nSince `dbmap` uses `$` for named parameters, if you need to use a literal `$` in your SQL (e.g. in a string), you can escape it by using `$$`.\n\n## Features (and to-do)\n\n- [x] Support for `insert`ing structs via `DB.InsertRecord`.\n- [x] Support for `select`ing structs via `DB.Select`.\n- [x] Support for `update`ing data via `DB.Update`.\n- [x] Support for `update`ing specific structs via `DB.UpdateRecord`.\n- [x] Support for `delete`ing data via `DB.Delete`.\n- [x] Support for `delete`ing single structs via `DB.DeleteRecord`.\n- [x] Support for `delete`ing multiple structs via `DB.DeleteRecords`.\n- [x] Support for transactions via `DB.Transaction`\n- [x] Updates `created_at` and `updated_at` fields automatically.\n- [x] Support for standard DB `Exec` with named parameters.\n- [x] Support for standard DB `Query` with named parameters.\n- [x] Pluralize table names by default\n- [x] Support for `Exists`\n- [x] Support for `Count`\n\nNot in scope, but welcome contributions:\n\n- [ ] Support for non-MySQL databases\n\nGot feature requests or suggestions? Please open an issue or a PR!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblakewilliams%2Fdbmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblakewilliams%2Fdbmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblakewilliams%2Fdbmap/lists"}