{"id":15996115,"url":"https://github.com/dhui/pqerrors","last_synced_at":"2025-04-05T00:43:17.427Z","repository":{"id":57571213,"uuid":"147996155","full_name":"dhui/pqerrors","owner":"dhui","description":null,"archived":false,"fork":false,"pushed_at":"2018-12-08T05:52:31.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-10T09:13:05.747Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dhui.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}},"created_at":"2018-09-09T05:33:04.000Z","updated_at":"2018-12-08T05:52:33.000Z","dependencies_parsed_at":"2022-09-17T15:42:01.927Z","dependency_job_id":null,"html_url":"https://github.com/dhui/pqerrors","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhui%2Fpqerrors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhui%2Fpqerrors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhui%2Fpqerrors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhui%2Fpqerrors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dhui","download_url":"https://codeload.github.com/dhui/pqerrors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247271491,"owners_count":20911586,"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":[],"created_at":"2024-10-08T07:23:06.202Z","updated_at":"2025-04-05T00:43:17.390Z","avatar_url":"https://github.com/dhui.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pqerrors\n\n[![Build Status](https://img.shields.io/travis/dhui/pqerrors/master.svg)](https://travis-ci.org/dhui/pqerrors)\n[![GoDoc](https://godoc.org/github.com/dhui/pqerrors?status.svg)](https://godoc.org/github.com/dhui/pqerrors)\n![Supported Go Versions](https://img.shields.io/badge/Go-1.11-lightgrey.svg)\n[![Go Report Card](https://goreportcard.com/badge/github.com/dhui/pqerrors)](https://goreportcard.com/report/github.com/dhui/pqerrors)\n[![GitHub Release](https://img.shields.io/github/release/dhui/pqerrors.svg)](https://github.com/dhui/pqerrors/releases)\n\npqerrors is a Go library that provides constants to make handling [pq](https://github.com/lib/pq) errors easier\n\n## Example Usage:\n\n### Error Classes\n\n```golang\n    var err error // err from database/sql\n    if e, ok := err.(pq.Error); ok {\n        switch e.Code.Class() {\n        case pqerrcls.NoData:\n             // Handle error\n        case pqerrcls.IntegrityConstraintViolation:\n             // Handle error\n        default:\n            // Handle unexpected error\n        }\n    }\n```\n\n### Error Codes\n\n```golang\n    var err error // err from database/sql\n    if e, ok := err.(pq.Error); ok {\n        switch e.Code {\n        case pqerrcode.DataExceptionNullValueNotAllowed:\n             // Handle error\n        case pqerrcode.IntegrityConstraintViolationUniqueViolation:\n             // Handle error\n        default:\n            // Handle unexpected error\n        }\n    }\n```\n\n\n\n## How to update error class and code constants:\n1. Copy the [table of Postgres errors](https://www.postgresql.org/docs/current/static/errcodes-appendix.html) into `errors_table.txt`\n1. Run `go generate`\n1. Ensure that tests still pass: `go test -v`\n1. Commit the changes\n1. [Open a PR](https://github.com/dhui/pqerrors/pulls)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhui%2Fpqerrors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdhui%2Fpqerrors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhui%2Fpqerrors/lists"}