{"id":36583659,"url":"https://github.com/mickamy/mtc","last_synced_at":"2026-01-12T08:00:00.839Z","repository":{"id":321012934,"uuid":"1084103473","full_name":"mickamy/mtc","owner":"mickamy","description":"Go library that automatically applies tenant-scoped context values (like app.tenant_id) to PostgreSQL connections using Row-Level Security (RLS).","archived":false,"fork":false,"pushed_at":"2025-10-27T08:36:44.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-27T10:29:31.294Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/mickamy.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-27T08:19:57.000Z","updated_at":"2025-10-27T09:24:25.000Z","dependencies_parsed_at":"2025-10-27T10:29:39.735Z","dependency_job_id":"3c4e5e02-5b95-462d-8f1c-aa527bd9ef64","html_url":"https://github.com/mickamy/mtc","commit_stats":null,"previous_names":["mickamy/mtc"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/mickamy/mtc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mickamy%2Fmtc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mickamy%2Fmtc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mickamy%2Fmtc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mickamy%2Fmtc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mickamy","download_url":"https://codeload.github.com/mickamy/mtc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mickamy%2Fmtc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28336957,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T06:09:07.588Z","status":"ssl_error","status_checked_at":"2026-01-12T06:05:18.301Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":[],"created_at":"2026-01-12T08:00:00.183Z","updated_at":"2026-01-12T08:00:00.834Z","avatar_url":"https://github.com/mickamy.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mtc — Multi-Tenant Connector for Go (RLS + Context)\n\n`mtc` is a lightweight Go library that automatically applies tenant-scoped\ncontext values (like `app.tenant_id`) to PostgreSQL connections using\nRow-Level Security (RLS).\n\n## Features\n\n- Propagates tenant IDs from `context.Context` into PostgreSQL GUCs.\n- Applies the tenant both for explicit transactions (`BeginTx`) and autocommit statements (`QueryContext`,\n  `ExecContext`) by bracketing each query with `set_config(..., false)` / `RESET`.\n- Works with any `database/sql` driver; pgx is supported out of the box.\n- Validates tenant setting name to avoid SQL injection (`reset setting` safety).\n- Keeps session state clean by resetting the tenant setting on pooled connections.\n\n## Installation\n\n```bash\ngo get github.com/mickamy/mtc\n```\n\n## Quick Start\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"database/sql\"\n\t\"fmt\"\n\n\t\"github.com/jackc/pgx/v5/stdlib\"\n\t\"github.com/mickamy/mtc\"\n)\n\ntype tenantKey struct{}\n\nfunc tenantFromContext(ctx context.Context) (string, error) {\n\tif v, ok := ctx.Value(tenantKey{}).(string); ok \u0026\u0026 v != \"\" {\n\t\treturn v, nil\n\t}\n\treturn \"\", nil\n}\n\nfunc main() {\n\tconnector := mtc.New(\n\t\tstdlib.GetDefaultDriver(),\n\t\t\"postgres://user:pass@localhost:5432/app?sslmode=disable\",\n\t\ttenantFromContext,\n\t\tmtc.WithSettingName(\"app.tenant_id\"),\n\t)\n\n\tdb := sql.OpenDB(connector)\n\tdefer db.Close()\n\n\tctx := context.WithValue(context.Background(), tenantKey{}, \"tenant-123\")\n\n\tvar tenant string\n\tif err := db.QueryRowContext(ctx, \"select current_setting('app.tenant_id', true)\").Scan(\u0026tenant); err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(\"tenant:\", tenant)\n\n\ttx, err := db.BeginTx(ctx, nil)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer tx.Rollback()\n\n\t// Within this transaction the tenant is visible via current_setting as well.\n}\n```\n\n`mtc` plays nicely with PostgreSQL RLS policies that depend on\n`current_setting('app.tenant_id', true)`.\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmickamy%2Fmtc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmickamy%2Fmtc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmickamy%2Fmtc/lists"}