{"id":13693888,"url":"https://github.com/samonzeweb/godb","last_synced_at":"2026-02-02T01:36:23.055Z","repository":{"id":49033818,"uuid":"76179893","full_name":"samonzeweb/godb","owner":"samonzeweb","description":"A Go SQL query builder and struct mapper.","archived":false,"fork":false,"pushed_at":"2023-12-18T22:50:04.000Z","size":368,"stargazers_count":731,"open_issues_count":3,"forks_count":25,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-05-03T00:39:11.752Z","etag":null,"topics":["database","go","golang","orm","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/samonzeweb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2016-12-11T14:37:06.000Z","updated_at":"2025-04-04T01:24:12.000Z","dependencies_parsed_at":"2024-06-18T14:15:26.158Z","dependency_job_id":null,"html_url":"https://github.com/samonzeweb/godb","commit_stats":{"total_commits":170,"total_committers":8,"mean_commits":21.25,"dds":"0.12352941176470589","last_synced_commit":"66f103ce63eadc49cfdbd87915173b3ae255a65f"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/samonzeweb/godb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samonzeweb%2Fgodb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samonzeweb%2Fgodb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samonzeweb%2Fgodb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samonzeweb%2Fgodb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samonzeweb","download_url":"https://codeload.github.com/samonzeweb/godb/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samonzeweb%2Fgodb/sbom","scorecard":{"id":797858,"data":{"date":"2025-08-11","repo":{"name":"github.com/samonzeweb/godb","commit":"66f103ce63eadc49cfdbd87915173b3ae255a65f"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.8,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":3,"reason":"Found 11/30 approved changesets -- score normalized to 3","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/test-godb.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-godb.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/samonzeweb/godb/test-godb.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-godb.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/samonzeweb/godb/test-godb.yml/master?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Info: FSF or OSI recognized license: MIT License: LICENSE.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 13 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":7,"reason":"3 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GO-2023-2402 / GHSA-45x7-px36-x8w8","Warn: Project is vulnerable to: GO-2024-3321 / GHSA-v778-237x-gjrc","Warn: Project is vulnerable to: GO-2025-3487 / GHSA-hcg3-q754-cr77"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-23T09:33:24.591Z","repository_id":49033818,"created_at":"2025-08-23T09:33:24.591Z","updated_at":"2025-08-23T09:33:24.591Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28999917,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-02T01:32:03.847Z","status":"ssl_error","status_checked_at":"2026-02-02T01:32:03.458Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["database","go","golang","orm","sql"],"created_at":"2024-08-02T17:01:19.837Z","updated_at":"2026-02-02T01:36:23.015Z","avatar_url":"https://github.com/samonzeweb.png","language":"Go","readme":"# godb - a Go query builder and struct mapper\n\n![CI Status](https://github.com/samonzeweb/godb/actions/workflows/test-godb.yml/badge.svg) [![GoDoc](https://godoc.org/github.com/samonzeweb/godb?status.svg)](https://godoc.org/github.com/samonzeweb/godb)\n\ngodb is a simple Go query builder and struct mapper, not a full-featured ORM. godb does not manage relationships.\n\nInitially, godb was a learning project. The goal was to improve my Go skills by doing some useful things. But more and more features have been added and godb has become a serious project that can be used by others.\n\ngodb is a project that is still young and evolving. The API is almost stable, but it can still change slightly from one version to another. Each new version is associated with a tag, so it is possible to target a particular one if necessary.\n\n## Features\n\n- Queries builder.\n- Mapping between structs and tables (or views).\n- Mapping with nested structs.\n- Execution of custom SELECT, INSERT, UPDATE and DELETE queries with structs and slices.\n- Optional execution of SELECT queries with an iterator to limit memory consumption if needed (e.g. batches).\n- Execution of raw queries, mapping rows to structs.\n- Optimistic Locking\n- SQL queries and durations logs.\n- Two adjustable prepared statements caches (with/without transaction).\n- `RETURNING` support for PostgreSQL.\n- `OUTPUT` support for SQL Server.\n- Optional common db errors handling for backend databases.(`db.UseErrorParser()`)\n- Define your own logger (should have `Println(...)` method)\n- Define model struct name to db table naming with `db.SetDefaultTableNamer(yourFn)`. Supported types are: Plural,Snake,SnakePlural. You can also define `TableName() string` method to for your struct and return whatever table name will be.\n- BlackListing or WhiteListing columns for struct based inserts and updates.\n- Could by used with\n  - SQLite\n  - PostgreSQL\n  - MySQL / MariaDB\n  - MS SQL Server\n  - other compatible database if you write an adapter.\n\nI made tests of godb on differents architectures and operating systems : OSX, Windows, Linux, ARM (Cortex A7) and Intel x64.\n\nThe current version of godb is compatible from Go 1.13 to 1.19. Older versions through 1.10 to 1.12 are supported by the [v1.0.14 tag](https://github.com/samonzeweb/godb/tree/v1.0.14) .\n\n## Documentation\n\nThere are three forms of documentation :\n\n- This README with the example presented below, which gives an overview of what godb allows.\n- The tests in `dbtests/common`, which are run on the different databases supported.\n- Detailed documentation on GoDoc: https://godoc.org/github.com/samonzeweb/godb\n\n## Install\n\n```\ngo get github.com/samonzeweb/godb\n```\n\nInstall the required driver (see tests). You cas use multiple databases if needed.\n\nOf course you can also use a dependency management tool like `dep`.\n\n## Running Tests\n\ngodb tests use GoConvey and at least SQLite :\n\n```\ngo get github.com/smartystreets/goconvey\ngo get github.com/mattn/go-sqlite3\n```\n\nTo run tests, go into the godb directory and executes `go test ./...`\n\nSQLite tests are done with in memory database, it's fast. You can run tests with others databases, see below.\n\nWith the exception of SQLite, all drivers are _pure Go_ code, and does not require external dependencies.\n\n### Test with PostgreSQL\n\nInstall the driver and set the `GODB_POSTGRESQL` environment variable with the PostgreSQL connection string.\n\n```\ngo get github.com/lib/pq\nGODB_POSTGRESQL=\"your connection string\" go test ./...\n```\n\n### Test with MySQL / MariaDB\n\nInstall the driver and set the `GODB_MYSQL` environment variable with the MySQL connection string.\n\n```\ngo get github.com/go-sql-driver/mysql\nGODB_MYSQL=\"your connection string\" go test ./...\n```\n\n### Test with MS SQL Server\n\nInstall the driver and set the `GODB_MSSQL` environment variable with the SQL Server connection string.\n\n```\ngo get github.com/denisenkom/go-mssqldb\nGODB_MSSQL=\"your connection string\" go test ./...\n```\n\n### Test all with Docker\n\nUsing Docker you can test with SQLite, PostgreSQL, MariaDB and SQL Server with the `testallwithdocker.sh` shell script.\n\nSQL Server is greedy, on OSX allow at least 4Go to Docker.\n\n## Example\n\nThe example below illustrates the main features of godb.\n\nYou can copy the code into an `example.go` file and run it. You need to create the database and the `books` table as explained in the code.\n\n```go\npackage main\n\nimport (\n\t\"database/sql\"\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/samonzeweb/godb\"\n\t\"github.com/samonzeweb/godb/adapters/sqlite\"\n\t\"log\"\n\t\"os\"\n)\n\n/*\n  To run this example, initialize a SQLite3 DB called 'library.db' and add\n  a 'books' table like this :\n\n  create table books (\n  \tid        integer not null primary key autoincrement,\n  \ttitle     text    not null,\n  \tauthor    text    not null,\n  \tpublished date    not null);\n*/\n\n// Struct and its mapping\ntype Book struct {\n\tId        int       `db:\"id,key,auto\"`\n\tTitle     string    `db:\"title\"`\n\tAuthor    string    `db:\"author\"`\n\tPublished time.Time `db:\"published\"`\n}\n\n// Optional, default if the struct name (Book)\nfunc (*Book) TableName() string {\n\treturn \"books\"\n}\n\n// See \"group by\" example\ntype CountByAuthor struct {\n\tAuthor string `db:\"author\"`\n\tCount  int    `db:\"count\"`\n}\n\nfunc main() {\n\t// Examples fixtures\n\tvar authorTolkien = \"J.R.R. tolkien\"\n\n\tvar bookTheHobbit = Book{\n\t\tTitle:     \"The Hobbit\",\n\t\tAuthor:    authorTolkien,\n\t\tPublished: time.Date(1937, 9, 21, 0, 0, 0, 0, time.UTC),\n\t}\n\n\tvar bookTheFellowshipOfTheRing = Book{\n\t\tTitle:     \"The Fellowship of the Ring\",\n\t\tAuthor:    authorTolkien,\n\t\tPublished: time.Date(1954, 7, 29, 0, 0, 0, 0, time.UTC),\n\t}\n\n\tvar bookTheTwoTowers = Book{\n\t\tTitle:     \"The Two Towers\",\n\t\tAuthor:    authorTolkien,\n\t\tPublished: time.Date(1954, 11, 11, 0, 0, 0, 0, time.UTC),\n\t}\n\n\tvar bookTheReturnOfTheKing = Book{\n\t\tTitle:     \"The Return of the King\",\n\t\tAuthor:    authorTolkien,\n\t\tPublished: time.Date(1955, 10, 20, 0, 0, 0, 0, time.UTC),\n\t}\n\n\tvar setTheLordOfTheRing = []Book{\n\t\tbookTheFellowshipOfTheRing,\n\t\tbookTheTwoTowers,\n\t\tbookTheReturnOfTheKing,\n\t}\n\n\t// Connect to the DB\n\tdb, err := godb.Open(sqlite.Adapter, \"./library.db\")\n\tpanicIfErr(err)\n\t// OPTIONAL: Set logger to show SQL execution logs\n\tdb.SetLogger(log.New(os.Stderr, \"\", 0))\n\t// OPTIONAL: Set default table name building style from struct's name(if active struct doesn't have TableName() method)\n\tdb.SetDefaultTableNamer(tablenamer.Plural())\n\t// Single insert (id will be updated)\n\terr = db.Insert(\u0026bookTheHobbit).Do()\n\tpanicIfErr(err)\n\n\t// Multiple insert\n\t// Warning : BulkInsert only update ids with PostgreSQL and SQL Server!\n\terr = db.BulkInsert(\u0026setTheLordOfTheRing).Do()\n\tpanicIfErr(err)\n\n\t// Count\n\tcount, err := db.SelectFrom(\"books\").Count()\n\tpanicIfErr(err)\n\tfmt.Println(\"Books count : \", count)\n\n\t// Custom select\n\tcountByAuthor := make([]CountByAuthor, 0, 0)\n\terr = db.SelectFrom(\"books\").\n\t\tColumns(\"author\", \"count(*) as count\").\n\t\tGroupBy(\"author\").\n\t\tHaving(\"count(*) \u003e 3\").\n\t\tDo(\u0026countByAuthor)\n\tfmt.Println(\"Count by authors : \", countByAuthor)\n\n\t// Select single object\n\tsingleBook := Book{}\n\terr = db.Select(\u0026singleBook).\n\t\tWhere(\"title = ?\", bookTheHobbit.Title).\n\t\tDo()\n\tif err == sql.ErrNoRows {\n\t\t// sql.ErrNoRows is only returned when the target is a single instance\n\t\tfmt.Println(\"Book not found !\")\n\t} else {\n\t\tpanicIfErr(err)\n\t}\n\n\t// Select single record values\n\tauthorName := \"\"\n\ttitle := \"\"\n\terr = db.SelectFrom(\"books\").\n\t\tWhere(\"title = ?\", bookTheHobbit.Title).\n\t\tColumns(\"author\", \"title\").\n\t\tScanx(\u0026authorName, \u0026title)\n\tif err == sql.ErrNoRows {\n\t\t// sql.ErrNoRows is only returned when the target is a single instance\n\t\tfmt.Println(\"Book not found !\")\n\t} else {\n\t\tpanicIfErr(err)\n\t}\n\n\t// Select multiple objects\n\tmultipleBooks := make([]Book, 0, 0)\n\terr = db.Select(\u0026multipleBooks).Do()\n\tpanicIfErr(err)\n\tfmt.Println(\"Books found : \", len(multipleBooks))\n\n\t// Iterator\n\titer, err := db.SelectFrom(\"books\").\n\t\tColumns(\"id\", \"title\", \"author\", \"published\").\n\t\tDoWithIterator()\n\tpanicIfErr(err)\n\tfor iter.Next() {\n\t\tbook := Book{}\n\t\terr := iter.Scan(\u0026book)\n\t\tpanicIfErr(err)\n\t\tfmt.Println(book)\n\t}\n\tpanicIfErr(iter.Err())\n\tpanicIfErr(iter.Close())\n\n\t// Raw query\n\tsubQuery := godb.NewSQLBuffer(0, 0). // sizes are indicative\n\t\t\t\t\t\tWrite(\"select author \").\n\t\t\t\t\t\tWrite(\"from books \").\n\t\t\t\t\t\tWriteCondition(godb.Q(\"where title = ?\", bookTheHobbit.Title))\n\n\tqueryBuffer := godb.NewSQLBuffer(64, 0).\n\t\tWrite(\"select * \").\n\t\tWrite(\"from books \").\n\t\tWrite(\"where author in (\").\n\t\tAppend(subQuery).\n\t\tWrite(\")\")\n\n\tpanicIfErr(queryBuffer.Err())\n\n\tbooks := make([]Book, 0, 0)\n\terr = db.RawSQL(queryBuffer.SQL(), queryBuffer.Arguments()...).Do(\u0026books)\n\tpanicIfErr(err)\n\tfmt.Printf(\"Raw query found %d books\\n\", len(books))\n\n\t// Update and transactions\n\terr = db.Begin()\n\tpanicIfErr(err)\n\n\tupdated, err := db.UpdateTable(\"books\").Set(\"author\", \"Tolkien\").Do()\n\tpanicIfErr(err)\n\tfmt.Println(\"Books updated : \", updated)\n\n\tbookTheHobbit.Author = \"Tolkien\"\n\terr = db.Update(\u0026bookTheHobbit).Do()\n\tpanicIfErr(err)\n\tfmt.Println(\"Books updated : \", updated)\n\n\terr = db.Rollback()\n\tpanicIfErr(err)\n\n\t// Delete\n\tdeleted, err := db.Delete(\u0026bookTheHobbit).Do()\n\tpanicIfErr(err)\n\tfmt.Println(\"Books deleted : \", deleted)\n\n\tdeleted, err = db.DeleteFrom(\"books\").\n\t\tWhereQ(godb.Or(\n\t\t\tgodb.Q(\"author = ?\", authorTolkien),\n\t\t\tgodb.Q(\"author = ?\", \"Georged Orwell\"),\n\t\t)).\n\t\tDo()\n\tpanicIfErr(err)\n\tfmt.Println(\"Books deleted : \", deleted)\n\n\t// Bye\n\terr = db.Close()\n\tpanicIfErr(err)\n}\n\n// It's just an example, what did you expect ? (never do that in real code)\nfunc panicIfErr(err error) {\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\n# Licence\n\nReleased under the MIT License, see LICENSE.txt for more informations.\n","funding_links":[],"categories":["开源类库","Open source library","Repositories","Libraries"],"sub_categories":["数据库","Database"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamonzeweb%2Fgodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamonzeweb%2Fgodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamonzeweb%2Fgodb/lists"}