{"id":19164630,"url":"https://github.com/gmhafiz/golang-database-library-orm-example","last_synced_at":"2025-05-07T12:21:32.652Z","repository":{"id":147252089,"uuid":"437762241","full_name":"gmhafiz/golang-database-library-orm-example","owner":"gmhafiz","description":"Examples of using various popular database libraries and ORM in Go.","archived":false,"fork":false,"pushed_at":"2023-02-18T05:28:10.000Z","size":524,"stargazers_count":25,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-19T22:01:59.403Z","etag":null,"topics":["database","ent","golang","gorm","orm","postgresql","sqlboiler","sqlc","sqlx","squirrel"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gmhafiz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2021-12-13T06:34:29.000Z","updated_at":"2024-04-29T14:26:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"0aecd9ce-63ba-4e07-91f4-4354df7acb2a","html_url":"https://github.com/gmhafiz/golang-database-library-orm-example","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/gmhafiz%2Fgolang-database-library-orm-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmhafiz%2Fgolang-database-library-orm-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmhafiz%2Fgolang-database-library-orm-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmhafiz%2Fgolang-database-library-orm-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gmhafiz","download_url":"https://codeload.github.com/gmhafiz/golang-database-library-orm-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252874206,"owners_count":21817780,"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":["database","ent","golang","gorm","orm","postgresql","sqlboiler","sqlc","sqlx","squirrel"],"created_at":"2024-11-09T09:23:09.797Z","updated_at":"2025-05-07T12:21:32.623Z","avatar_url":"https://github.com/gmhafiz.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"#  Introduction\n\nExamples of using various popular database libraries and ORM in Go.\n\n - [sqlx](https://jmoiron.github.io/sqlx/)\n - [sqlc](https://docs.sqlc.dev)\n - [squirrel](https://github.com/Masterminds/squirrel)\n - [Gorm](https://github.com/go-gorm/gorm)\n - [sqlboiler](https://github.com/volatiletech/sqlboiler)\n - [ent](https://entgo.io/docs/getting-started)\n\nThe aim is to demonstrate and compare usage for several operations\n\n 1. Simple CRUD operation\n 2. 1-to-Many queries\n 3. Many-to-many queries\n 4. Dynamic list filter from query parameter \n 5. Transaction\n 6. SQL Injection \n\n# Schema\n\n![Database](db.png)\n\nThere are four tables. The `users` table and `addresses` table are linked by the pivot `user_addresses` table. The `addresses` table contains a foreign key to `countries` to demonstrate 1-to-many relationship.\n\nTo make things interesting, we make `middle_name` an optional field. We also have a 'protected/hidden' field in which we do not want to return in a JSON response, like a password.\n\n\n# Usage\n\n## Setup\n\nSetup postgres database by either running from docker-compose or manually.\n\n    docker-compose up \n\nThis creates both `postgres` database (which this repo uses) and `ent` database which is used by ent ORM.\n\nIf you create the database manually, execute the `database/01-postgres-schema.sql` script.\n\nDefault database credentials are defined in `config/config.go`. These can be overwritten by setting environment variables. For example:\n\n    export DB_NAME=test_db\n\n## Run\n\nRun with\n\n    go run main.go\n\n\nRun examples from `example` folder.\n\n# Blog Posts\n\nThis repository accompanies the blog posts at [https://www.gmhafiz.com/blog/golang-database-library-orm-example-intro/](https://www.gmhafiz.com/blog/golang-database-library-orm-example-intro/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgmhafiz%2Fgolang-database-library-orm-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgmhafiz%2Fgolang-database-library-orm-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgmhafiz%2Fgolang-database-library-orm-example/lists"}