{"id":13792546,"url":"https://github.com/tarantool/pg","last_synced_at":"2025-04-14T15:10:55.371Z","repository":{"id":31106101,"uuid":"34665438","full_name":"tarantool/pg","owner":"tarantool","description":"PostgreSQL connector for Tarantool","archived":false,"fork":false,"pushed_at":"2024-03-20T13:43:32.000Z","size":56,"stargazers_count":37,"open_issues_count":15,"forks_count":11,"subscribers_count":41,"default_branch":"master","last_synced_at":"2025-03-28T04:03:28.453Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tarantool.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":"2015-04-27T12:29:47.000Z","updated_at":"2025-02-09T11:32:25.000Z","dependencies_parsed_at":"2022-08-27T01:11:01.138Z","dependency_job_id":null,"html_url":"https://github.com/tarantool/pg","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool%2Fpg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool%2Fpg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool%2Fpg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool%2Fpg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tarantool","download_url":"https://codeload.github.com/tarantool/pg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248904640,"owners_count":21180835,"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-08-03T22:01:13.568Z","updated_at":"2025-04-14T15:10:55.334Z","avatar_url":"https://github.com/tarantool.png","language":"C","funding_links":[],"categories":["Packages"],"sub_categories":["Clients"],"readme":"# pg - PostgreSQL connector for [Tarantool][]\n\n[![Build and Test](https://github.com/tarantool/pg/actions/workflows/test.yml/badge.svg)](https://github.com/tarantool/pg/actions/workflows/test.yml)\n\n## Getting Started\n\n### Prerequisites\n\n * Tarantool 1.6.5+ with header files (tarantool \u0026\u0026 tarantool-dev packages)\n * PostgreSQL 8.1+ header files (libpq-dev package)\n\n### Installation\n\nClone repository and then build it using CMake:\n\n``` bash\ngit clone https://github.com/tarantool/pg.git\ncd pg \u0026\u0026 cmake . -DCMAKE_BUILD_TYPE=RelWithDebugInfo\nmake\nmake install\n```\n\nYou can also use LuaRocks:\n\n``` bash\nluarocks install https://raw.githubusercontent.com/tarantool/pg/master/pg-scm-1.rockspec --local\n```\n\nSee [tarantool/rocks][TarantoolRocks] for LuaRocks configuration details.\n\n### Usage\n\n``` lua\nlocal pg = require('pg')\nlocal conn = pg.connect({host = localhost, user = 'user', pass = 'pass', db = 'db'})\nlocal tuples = conn:execute(\"SELECT $1 AS a, 'xx' AS b\", 42)\nconn:begin()\nconn:execute(\"INSERT INTO test VALUES(1, 2, 3)\")\nconn:commit()\n```\n\n## API Documentation\n\n### `conn = pg:connect(opts = {})`\n\nConnect to a database.\n\n*Options*:\n\n - `host` - a hostname to connect\n - `port` - a port numner to connect\n - `user` - username\n - `pass` or `password` - a password\n - `db` - a database name\n - `conn_string` (mutual exclusive with host, port, user, pass, db) - PostgreSQL\n   [connection string][PQconnstring]\n\n*Returns*:\n\n - `connection ~= nil` on success\n - `error(reason)` on error\n\n### `conn:execute(statement, ...)`\n\nExecute a statement with arguments in the current transaction.\n\n*Returns*:\n - `{ { { column1 = value, column2 = value }, ... }, { {column1 = value, ... }, ...}, ...}, true` on success\n - `error(reason)` on error\n\n*Example*:\n```\ntarantool\u003e conn:execute(\"SELECT $1 AS a, 'xx' AS b\", 42)\n---\n- - - a: 42\n      b: xx\n    ...\n```\n\n### `conn:begin()`\n\nBegin a transaction.\n\n*Returns*: `true`\n\n### `conn:commit()`\n\nCommit current transaction.\n\n*Returns*: `true`\n\n### `conn:rollback()`\n\nRollback current transaction.\n\n*Returns*: `true`\n\n### `conn:ping()`\n\nExecute a dummy statement to check that connection is alive.\n\n*Returns*:\n\n - `true` on success\n - `false` on failure\n\n#### `pool = pg.pool_create(opts = {})`\n\nCreate a connection pool with count of size established connections.\n\n*Options*:\n\n - `host` - hostname to connect to\n - `port` - port number to connect to\n - `user` - username\n - `password` - password\n - `db` - database name\n - `size` - count of connections in pool\n\n*Returns*\n\n - `pool ~=nil` on success\n - `error(reason)` on error\n\n### `conn = pool:get()`\n\nGet a connection from pool. Reset connection before returning it. If connection\nis broken then it will be reestablished. If there is no free connections then\ncalling fiber will sleep until another fiber returns some connection to pool.\n\n*Returns*:\n\n - `conn ~= nil`\n \n### `pool:put(conn)`\n\nReturn a connection to connection pool.\n\n*Options*\n\n - `conn` - a connection\n\n## Comments\n\nAll calls to connections api will be serialized, so it should to be safe to\nuse one connection from some count of fibers. But you should understand,\nthat you can have some unwanted behavior across db calls, for example if\nanother fiber 'injects' some sql between two your calls.\n\n# See Also\n\n * [Tests][]\n * [Tarantool][]\n * [Tarantool Rocks][TarantoolRocks]\n\n[Tarantool]: http://github.com/tarantool/tarantool\n[Tests]: https://github.com/tarantool/pg/tree/master/test\n[PQconnstring]: http://www.postgresql.org/docs/9.4/static/libpq-connect.html#LIBPQ-CONNSTRING\n[TarantoolRocks]: https://github.com/tarantool/rocks\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarantool%2Fpg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftarantool%2Fpg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarantool%2Fpg/lists"}