{"id":16589428,"url":"https://github.com/holmusk/postgresql-simple-named","last_synced_at":"2025-09-11T21:06:20.035Z","repository":{"id":35011541,"uuid":"194812768","full_name":"Holmusk/postgresql-simple-named","owner":"Holmusk","description":":question: Implementation of named parameters for `postgresql-simple` library","archived":false,"fork":false,"pushed_at":"2024-10-05T14:05:10.000Z","size":56,"stargazers_count":38,"open_issues_count":4,"forks_count":2,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-05T15:16:22.416Z","etag":null,"topics":["haskell","named-parameters","postgresql"],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Holmusk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2019-07-02T07:36:22.000Z","updated_at":"2024-10-05T16:31:49.000Z","dependencies_parsed_at":"2024-11-25T00:00:33.261Z","dependency_job_id":null,"html_url":"https://github.com/Holmusk/postgresql-simple-named","commit_stats":{"total_commits":36,"total_committers":9,"mean_commits":4.0,"dds":0.7222222222222222,"last_synced_commit":"9b1fd12717a869aebb7e7c34f32b9564a9079701"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Holmusk%2Fpostgresql-simple-named","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Holmusk%2Fpostgresql-simple-named/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Holmusk%2Fpostgresql-simple-named/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Holmusk%2Fpostgresql-simple-named/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Holmusk","download_url":"https://codeload.github.com/Holmusk/postgresql-simple-named/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247618452,"owners_count":20967785,"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":["haskell","named-parameters","postgresql"],"created_at":"2024-10-11T23:08:44.190Z","updated_at":"2025-04-07T08:28:33.227Z","avatar_url":"https://github.com/Holmusk.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# postgresql-simple-named\n\n![Logo](https://user-images.githubusercontent.com/4276606/68105647-408b7c00-fef0-11e9-8d70-d3fbf314a647.png)\n\n[![Build status](https://github.com/Holmusk/postgresql-simple-named/actions/workflows/haskell-ci.yml/badge.svg)](https://github.com/Holmusk/postgresql-simple-named/actions/workflows/haskell-ci.yml)\n[![Hackage](https://img.shields.io/hackage/v/postgresql-simple-named.svg?logo=haskell)](https://hackage.haskell.org/package/postgresql-simple-named)\n[![Stackage Lts](http://stackage.org/package/postgresql-simple-named/badge/lts)](http://stackage.org/lts/package/postgresql-simple-named)\n[![Stackage Nightly](http://stackage.org/package/postgresql-simple-named/badge/nightly)](http://stackage.org/nightly/package/postgresql-simple-named)\n[![MPL-2.0 license](https://img.shields.io/badge/license-MPL--2.0-blue.svg)](LICENSE)\n\nThis library introduces the implementation of named parameters for the\n[`postgresql-simple`][pgs] library. `postgresql-simple-named` is designed to\nbe used along with the [`postgresql-simple`][pgs] library, so you could refer\nthere for the original documentation of primary functions. This package solves\nexclusively one particular problem — gives the ability to use named parameters\ninstead of `?` in quasi-quoter queries and offers essential functions for substituting\nvariables in queries (`queryNamed`, `executeNamed`).\n\n## Example\n\nOperator `=?` binds named parameters with the corresponding values. Named\nparameters inside SQL query start with the '?' character and can contain\nlowercase and uppercase letters, digits and underscore. Below you can find a\nbasic example of how query with named parameters could look like:\n\n```haskell\nqueryNamed dbConnection [sql|\n    SELECT\n        id, name, city\n    FROM users\n    WHERE name = ?nameParam\n      AND age  = ?ageParam\n\n|] [ \"nameParam\" =? \"John\"\n   , \"ageParam\"  =? 42\n   ]\n```\n\nThis feature can be extremely helpful when the query uses some parameters more than once:\n\n```haskell\nquery dbConnection [sql|\n    SELECT\n        col1, col2\n    FROM my_table\n    WHERE id = ?\n      AND (? IS NULL OR id \u003e ? )\n      AND (? IS NULL OR id \u003c ? )\n\n|] (someId, minId, minId, maxId, maxId)\n```\n\nThis is how the query looks like with the `postgresql-simple` library. You can\nrewrite it the following way using the `postgresql-simple-named` library:\n\n```haskell\nqueryNamed dbConnection [sql|\n    SELECT\n        col1, col2\n    FROM my_table\n    WHERE id = ?someId\n      AND (?minId IS NULL OR id \u003e ?minId )\n      AND (?maxId IS NULL OR id \u003c ?maxId )\n\n|] [ \"someId\" =? 42\n   , \"minId\"  =? 1\n   , \"maxId\"  =? 100\n   ]\n```\n\n## How to build\n\nBuild the library with either `cabal new-build` or `stack build`.\n\n## How to test locally\n\n* Run DB in a Docker in a separate terminal window using command:\n  ```bash\n  docker run -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres:15\n  ```\n* Run tests using `cabal new-test` or `stack test`\n\n\n[pgs]: https://hackage.haskell.org/package/postgresql-simple\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fholmusk%2Fpostgresql-simple-named","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fholmusk%2Fpostgresql-simple-named","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fholmusk%2Fpostgresql-simple-named/lists"}