{"id":18544720,"url":"https://github.com/131/pg-aa","last_synced_at":"2026-01-03T18:05:04.448Z","repository":{"id":57322514,"uuid":"58267465","full_name":"131/pg-aa","owner":"131","description":"postgres wrapper with ES6 generator API (pg/co)","archived":false,"fork":false,"pushed_at":"2024-05-22T13:05:37.000Z","size":61,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-05T03:18:05.911Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/131.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2016-05-07T13:36:59.000Z","updated_at":"2024-05-22T13:05:40.000Z","dependencies_parsed_at":"2024-05-22T14:29:12.038Z","dependency_job_id":"2ceebf59-4404-422f-b7c6-e972bc83c68e","html_url":"https://github.com/131/pg-aa","commit_stats":null,"previous_names":["131/pg-co"],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Fpg-aa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Fpg-aa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Fpg-aa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Fpg-aa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/131","download_url":"https://codeload.github.com/131/pg-aa/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244159990,"owners_count":20408019,"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-11-06T20:17:24.545Z","updated_at":"2026-01-03T18:05:04.399Z","avatar_url":"https://github.com/131.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"A ES7 wrapper for node-postgres.\r\n\r\n\r\n[![Build Status](https://github.com/131/pg-aa/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/131/pg-aa/actions/workflows/test.yml)\r\n[![Coverage Status](https://coveralls.io/repos/github/131/pg-aa/badge.svg?branch=master)](https://coveralls.io/github/131/pg-aa?branch=master)\r\n[![NPM version](https://img.shields.io/npm/v/pg-aa.svg)](https://www.npmjs.com/package/pg-aa)\r\n[![Code style](https://img.shields.io/badge/code%2fstyle-ivs-green.svg)](https://www.npmjs.com/package/eslint-plugin-ivs)\r\n\r\n\r\n\r\n# Example\r\n```\r\nvar pg  = require('pg-aa');\r\nvar SQL = require('sql-template');\r\n\r\nvar conString = \"postgres://postgres:1234@localhost/postgres\";\r\n\r\nvar client = new pg(conString);\r\n\r\n(async function(){\r\n  var line;\r\n  line = await client.row(SQL`SELECT * FROM users WHERE id=${22}`);\r\n  // same line = await client.row('users', {id:22});\r\n  if(!line)\r\n    throw \"Missing user\";\r\n\r\n  await client.insert(\"users_log\", {\r\n    user_id : 22,\r\n    time    : Date.now(),\r\n  });\r\n})();\r\n```\r\n\r\n# API\r\n\r\n## await client.select(table [,condition = true [, columns = * [, extra ]]])\r\n## await client.select(PG_TEMPLATED_QUERY)\r\n  Select stuffs ? what did you expect ...\r\n\r\n```\r\nvar line = await client.select(SQL`SELECT * FROM users WHERE parentId=${22}`);\r\n=\u003e [ {id:1, name : \"John doe\", parentId:22}, {id:2, name : \"Jane doe\", parentId:22}]\r\n```\r\n\r\n\r\n\r\n## await client.row(table [,condition = true [, columns = * [, extra = LIMIT 1 ]]])\r\n## await client.row(PG_TEMPLATED_QUERY)\r\n  return a single row, and a falsy value if no match (see example below)\r\n\r\n```\r\nvar line = await client.row(SQL`SELECT * FROM users WHERE id=${22}`);\r\n=\u003e { id : 22, name : \"John doe\" }\r\n```\r\n\r\n\r\n## await client.col(table [,condition = true [, column = * [, extra = '']]])\r\n## await client.col(PG_TEMPLATED_QUERY)\r\n  return an array of values from a single column\r\n\r\n```\r\nvar line = await client.col('users', true, 'user_id');\r\n=\u003e [22, 1, 25, 55]\r\n```\r\n\r\n\r\n## await client.insert(table, values)\r\nInsert values in table...\r\n\r\n```\r\nawait client.insert(\"users_log\", {\r\n  user_id : 22,\r\n  time    : Date.now(),\r\n});\r\n```\r\n\r\n\r\n## await client.update(table, values[, where])\r\nUpdate values in a table...\r\n\r\n```\r\nawait client.insert(\"users_log\", {\r\n  time    : Date.now(),\r\n}, {\r\n  user_id : 22,\r\n});\r\n```\r\n\r\n\r\n## await client.delete(table[, where])\r\nDelete rows in a table...\r\n\r\n```\r\nawait client.delete(\"users_log\", \"log_weight \u003c 51\");\r\n```\r\n\r\n\r\n## await client.replace(table, values[, where])\r\nReplace values in a table... (lock select using * postgresql FOR UPDATE)\r\n\r\n```\r\nawait client.replace(\"users_log\", {\r\n  time    : Date.now(),\r\n}, {\r\n  user_id : 22,\r\n});\r\n```\r\n\r\n\r\n\r\n\r\n## await client.query(queryString);\r\n```\r\nawait client.query(\"TRUNCATE TABLE donttruncatemeplznooooo\");\r\n```\r\n\r\n\r\n## await client.truncate(tableName);\r\n```\r\nawait client.truncate(\"donttruncatemeplznooooo\");\r\n```\r\n\r\n\r\n\r\n\r\n## await client.begin() =\u003e transaction token\r\n## await client.commit(transaction token)\r\n## await client.rollback(transaction token)\r\nStart/commit/rollback a transaction (or a savepoint, if nested)\r\n\r\n```\r\nvar transaction_token = await client.begin();\r\nif(Math.random() \u003c 0.5)\r\n  await client.commit(transaction_token);\r\nelse  await client.rollback(transaction_token);\r\n```\r\n\r\n\r\n\r\n# Recommended template string engine\r\n* [sql-template](https://github.com/131/sql-template)\r\n\r\n# Not invented here / key features\r\n* Supported nested transaction (through savepoints)\r\n* Sane API = sane implementation (whole lib is \u003c 150 lines)\r\n\r\n\r\n# Credits\r\n* [131](https://github.com/131)\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F131%2Fpg-aa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F131%2Fpg-aa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F131%2Fpg-aa/lists"}