{"id":20533488,"url":"https://github.com/joeychilson/pghook","last_synced_at":"2026-04-17T15:02:31.046Z","repository":{"id":151693744,"uuid":"614818216","full_name":"joeychilson/pghook","owner":"joeychilson","description":"A Go library for executing hooks on insert, update, and delete events in PostgreSQL.","archived":false,"fork":false,"pushed_at":"2024-11-15T06:43:02.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-06T03:14:10.323Z","etag":null,"topics":["events","go","golang","hooks","postgres","postgresql","pubsub"],"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/joeychilson.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}},"created_at":"2023-03-16T11:38:56.000Z","updated_at":"2024-11-15T06:43:06.000Z","dependencies_parsed_at":"2024-11-03T14:26:17.240Z","dependency_job_id":"61470b58-bf66-4d43-82c1-0ee0578d02bd","html_url":"https://github.com/joeychilson/pghook","commit_stats":null,"previous_names":["joeychilson/pghook"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/joeychilson/pghook","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeychilson%2Fpghook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeychilson%2Fpghook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeychilson%2Fpghook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeychilson%2Fpghook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joeychilson","download_url":"https://codeload.github.com/joeychilson/pghook/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeychilson%2Fpghook/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266094064,"owners_count":23875565,"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":["events","go","golang","hooks","postgres","postgresql","pubsub"],"created_at":"2024-11-16T00:21:44.272Z","updated_at":"2026-04-17T15:02:23.998Z","avatar_url":"https://github.com/joeychilson.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pghook\n\nA Go library for executing hooks on insert, update, and delete events in PostgreSQL.\n\n## Installation\n\n```bash\ngo get github.com/joeychilson/pghook\n```\n\n## Example\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\t\"log/slog\"\n\t\"os\"\n\n\t\"github.com/jackc/pgx/v5/pgxpool\"\n\n\t\"github.com/joeychilson/pghook\"\n)\n\nfunc main() {\n\tctx := context.Background()\n\n\tlogger := slog.New(slog.NewTextHandler(os.Stdout, \u0026slog.HandlerOptions{\n\t\tLevel: slog.LevelDebug,\n\t}))\n\n\tpool, err := pgxpool.New(ctx, os.Getenv(\"DATABASE_URL\"))\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\ttype User struct {\n\t\tID        int    `json:\"id\"`\n\t\tName      string `json:\"name\"`\n\t\tCreatedAt string `json:\"created_at\"`\n\t}\n\n\thook := pghook.New[User](pool, pghook.WithLogger(logger))\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\thook.OnInsert(\"users\", func(ctx context.Context, e pghook.InsertPayload[User]) error {\n\t\tfmt.Println(\"inserted\", e.Row)\n\t\treturn nil\n\t})\n\n\thook.OnUpdate(\"users\", func(ctx context.Context, e pghook.UpdatePayload[User]) error {\n\t\tfmt.Println(\"updated\", e.OldRow, e.NewRow)\n\t\treturn nil\n\t})\n\n\thook.OnDelete(\"users\", func(ctx context.Context, e pghook.DeletePayload[User]) error {\n\t\tfmt.Println(\"deleted\", e.Row)\n\t\treturn nil\n\t})\n\n\tif err := hook.Listen(ctx); err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoeychilson%2Fpghook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoeychilson%2Fpghook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoeychilson%2Fpghook/lists"}