{"id":47210599,"url":"https://github.com/segfaultmedaddy/pgxephemeraltest","last_synced_at":"2026-03-13T15:45:31.103Z","repository":{"id":328042485,"uuid":"1082185394","full_name":"segfaultmedaddy/pgxephemeraltest","owner":"segfaultmedaddy","description":"Run pgx/v5 tests in isolated database environment","archived":false,"fork":false,"pushed_at":"2026-01-20T17:16:58.000Z","size":67,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-21T02:24:36.408Z","etag":null,"topics":["go","pgx","postgres","test"],"latest_commit_sha":null,"homepage":"https://segfaultmedaddy.com/p/pgxephemeraltest","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/segfaultmedaddy.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-10-23T21:28:26.000Z","updated_at":"2026-01-20T17:17:17.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/segfaultmedaddy/pgxephemeraltest","commit_stats":null,"previous_names":["segfaultmedaddy/pgxephemeraltest"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/segfaultmedaddy/pgxephemeraltest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segfaultmedaddy%2Fpgxephemeraltest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segfaultmedaddy%2Fpgxephemeraltest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segfaultmedaddy%2Fpgxephemeraltest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segfaultmedaddy%2Fpgxephemeraltest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/segfaultmedaddy","download_url":"https://codeload.github.com/segfaultmedaddy/pgxephemeraltest/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segfaultmedaddy%2Fpgxephemeraltest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30469392,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-13T11:00:43.441Z","status":"ssl_error","status_checked_at":"2026-03-13T11:00:23.173Z","response_time":60,"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":["go","pgx","postgres","test"],"created_at":"2026-03-13T15:45:29.808Z","updated_at":"2026-03-13T15:45:31.073Z","avatar_url":"https://github.com/segfaultmedaddy.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pgxephemeraltest\n\nIsolated database testing for Go using ephemeral transactions and databases.\n\npgxephemeraltest provides isolated test environments for database-backed functionality in Go. It exposes wrappers around two common testing patterns:\n\n- **Ephemeral transactions**: Tests run in transactions that are rolled back after completion\n- **Ephemeral databases**: Tests run in fully isolated databases created from templates\n\nWhen using ephemeral databases, the package leverages PostgreSQL [templates](https://www.postgresql.org/docs/current/manage-ag-templatedbs.html) for a quick initialization of a new database.\n\n## Usage\n\n```sh\n$ go get go.segfaultmedaddy.com/pgxephemeraltest\n```\n\n### 1. Define your migrator\n\n```go\ntype migrator struct{}\n\nfunc (migrator) Migrate(ctx context.Context, conn *pgx.Conn) error {\n    _, err := conn.Exec(ctx, `\n        CREATE TABLE users (\n            id SERIAL PRIMARY KEY,\n            name TEXT NOT NULL\n        )\n    `)\n    return err\n}\n\nfunc (migrator) Hash() string { return \"v1\" }\n```\n\n### 2. Initialize the factory\n\n```go\nvar factory *pgxephemeraltest.PoolFactory\n\nfunc TestMain(m *testing.M) {\n    ctx := context.Background()\n\n    connString, ok := os.LookupEnv(\"TEST_DATABASE_URL\")\n    if !ok {\n        panic(\"TEST_DATABASE_URL environment variable not set\")\n    }\n\n    var err error\n    factory, err = pgxephemeraltest.NewPoolFactoryFromConnString(ctx, connString, \u0026migrator{})\n    if err != nil {\n        panic(err)\n    }\n\n    os.Exit(m.Run())\n}\n```\n\n### 3. Write isolated tests\n\n```go\nfunc TestUsers(t *testing.T) {\n    t.Parallel()\n\n    ctx := context.Background()\n    pool := factory.Pool(t) // a pool connected to a newly created fully isolated database\n\n    _, err := pool.Exec(ctx, `INSERT INTO users (name) VALUES ($1)`, \"Alice\")\n    require.NoError(t, err)\n\n    var name string\n    err = pool.QueryRow(ctx, `SELECT name FROM users WHERE name = $1`, \"Alice\").Scan(\u0026name)\n    require.NoError(t, err)\n    require.Equal(t, \"Alice\", name)\n}\n```\n\nFor more usage examples, check out the `examples` directory in the root of this repository.\n\n## How It Works\n\nBoth approaches provide isolation, with different trade-offs:\n\n- Transactions are faster but share the same database\n- Separate databases provide complete isolation but are slightly slower\n\nFor a deeper dive, check out [segfaultmedaddy.com/p/pgxephemeraltest](https://segfaultmedaddy.com/p/pgxephemeraltest) for detailed information on the design and usage of this package.\n\n\u003e The package is deliberately built on top of the [pgx](https://github.com/jackc/pgx) driver and does not support the standard `database/sql` interface.\n\u003e If you need support for the standard `database/sql` interface, consider using [pgtestdb](https://github.com/peterldowns/pgtestdb).\n\n## License\n\nMIT Licensed\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsegfaultmedaddy%2Fpgxephemeraltest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsegfaultmedaddy%2Fpgxephemeraltest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsegfaultmedaddy%2Fpgxephemeraltest/lists"}