{"id":35038052,"url":"https://github.com/padurean/go-sqlx-postgres-with-migration-example","last_synced_at":"2026-05-06T19:33:58.954Z","repository":{"id":57643664,"uuid":"435941600","full_name":"padurean/go-sqlx-postgres-with-migration-example","owner":"padurean","description":"Go example showing how to use sqlx with PostgreSQL and a very simple way to do database migrations","archived":false,"fork":false,"pushed_at":"2021-12-07T16:20:31.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-06-20T14:28:32.720Z","etag":null,"topics":["database","go","golang","migration","postgresql","sql","sqlx"],"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/padurean.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}},"created_at":"2021-12-07T15:55:41.000Z","updated_at":"2023-08-25T02:38:25.000Z","dependencies_parsed_at":"2022-08-27T20:03:07.195Z","dependency_job_id":null,"html_url":"https://github.com/padurean/go-sqlx-postgres-with-migration-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/padurean/go-sqlx-postgres-with-migration-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padurean%2Fgo-sqlx-postgres-with-migration-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padurean%2Fgo-sqlx-postgres-with-migration-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padurean%2Fgo-sqlx-postgres-with-migration-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padurean%2Fgo-sqlx-postgres-with-migration-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/padurean","download_url":"https://codeload.github.com/padurean/go-sqlx-postgres-with-migration-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padurean%2Fgo-sqlx-postgres-with-migration-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28075695,"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-12-27T02:00:05.897Z","response_time":58,"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":["database","go","golang","migration","postgresql","sql","sqlx"],"created_at":"2025-12-27T08:03:58.781Z","updated_at":"2025-12-27T08:04:06.234Z","avatar_url":"https://github.com/padurean.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-sqlx-postgres-with-migration-example\n\nGo example showing how to use [sqlx](https://github.com/jmoiron/sqlx) with PostgreSQL and a very simple way to do database migrations\n\n## Prerequisites\n\n- a running PostgreSQL server\n- a database and a user:\n```sql\nCREATE DATABASE some_database;\nCREATE USER some_user WITH ENCRYPTED PASSWORD 'some_password';\nGRANT ALL PRIVILEGES ON DATABASE some_database TO some_user;\n```\n:bulb: No need to create the schema as it will be created during the very first run (if it doesn't exist already).\n\n- values in the .env file must match the ones PostgreSQL ones:\n```console\nDB_DRIVER=pgx\nDB_HOST_NAME=localhost\nDB_USER=some_user\nDB_PASSWORD=some_password\nDB_NAME=some_database\nDB_SCHEMA=some_schema\n```\n\n## Run\n\n```console\ngo run ./cmd/server\n```\n\nThe output should look like this:\n```console\n➤ go run ./cmd/server\n2021/12/07 18:08:59 env: {DB:{Driver:pgx HostName:localhost User:some_user Password:some_password Name:some_database Schema:some_schema URL:postgres://some_user:some_password@localhost:5432/some_database}}\n2021/12/07 18:08:59 connecting to database ...\n2021/12/07 18:08:59 migrating database ...\n2021/12/07 18:08:59 executing ledger_stats migration 1 ...\n2021/12/07 18:08:59 executing ledger_stats migration 2 ...\n2021/12/07 18:08:59 executing ledger_stats migration 3 ...\n2021/12/07 18:08:59 inserting some ledger stats ...\n2021/12/07 18:08:59 inserted ledger stats: \u0026{ID:1 Created:2021-12-07 18:08:59.693316 +0200 EET Updated:{Time:0001-01-01 00:00:00 +0000 UTC Valid:false} LedgerID:11 LastInsertionAt:{Time:2021-12-07 18:08:59.690109 +0200 EET Valid:true} ActiveSources:111 NumberOfEntries:1111 TotalSizeInBytes:1024 Tampered:{Time:0001-01-01 00:00:00 +0000 UTC Valid:false}}\n2021/12/07 18:08:59 updating ledger stats ...\n2021/12/07 18:08:59 updated ledger stats: \u0026{ID:1 Created:2021-12-07 18:08:59.693316 +0200 EET Updated:{Time:2021-12-07 18:08:59.703779 +0200 EET Valid:true} LedgerID:11 LastInsertionAt:{Time:2021-12-07 18:08:59.690109 +0200 EET Valid:true} ActiveSources:111 NumberOfEntries:1111 TotalSizeInBytes:1024 Tampered:{Time:2021-12-07 18:08:59.702133 +0200 EET Valid:true}}\n🎉 🥳\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpadurean%2Fgo-sqlx-postgres-with-migration-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpadurean%2Fgo-sqlx-postgres-with-migration-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpadurean%2Fgo-sqlx-postgres-with-migration-example/lists"}