{"id":13440409,"url":"https://github.com/anse1/emacs-libpq","last_synced_at":"2025-12-24T23:17:16.626Z","repository":{"id":10381418,"uuid":"65470276","full_name":"anse1/emacs-libpq","owner":"anse1","description":"An Emacs 25 module for accessing postgres via libpq.","archived":false,"fork":false,"pushed_at":"2024-03-19T01:27:41.000Z","size":70,"stargazers_count":22,"open_issues_count":12,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-15T23:29:26.795Z","etag":null,"topics":["emacs-modules","postgresql-driver"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anse1.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":"COPYING","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}},"created_at":"2016-08-11T13:09:27.000Z","updated_at":"2024-03-19T15:29:17.000Z","dependencies_parsed_at":"2024-04-13T14:38:33.876Z","dependency_job_id":null,"html_url":"https://github.com/anse1/emacs-libpq","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anse1%2Femacs-libpq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anse1%2Femacs-libpq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anse1%2Femacs-libpq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anse1%2Femacs-libpq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anse1","download_url":"https://codeload.github.com/anse1/emacs-libpq/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244586034,"owners_count":20476863,"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":["emacs-modules","postgresql-driver"],"created_at":"2024-07-31T03:01:22.508Z","updated_at":"2025-12-24T23:17:11.604Z","avatar_url":"https://github.com/anse1.png","language":"C","readme":"An Emacs 25 module for accessing PostgreSQL via the libpq client library.\n\nUsing libpq for client connections has various advantages over the\nwire-protocol speaking pure elisp implementations.  For example, it\nhas better performance and supports all features of the protocol like\nfull TLS support and new authentication methods like scram-sha-256.\n\nIt doesn't expose many libpq features yet, but what's there should be\ncrash-safe no matter what you do in the lisp world.  I've been using\nit for three years now for reading mail through my custom Gnus backend\nwithout incidents.  If you make it crash, please report.\n\n* Basic usage\n: ELISP\u003e (setq *pq* (pq:connectdb \"dbname=andreas\"))\n: #\u003cuser-ptr ptr=0x55b466c02780 finalizer=0x7f7d50112236\u003e\n: ELISP\u003e (pq:query *pq* \"select version()\")\n: (\"PostgreSQL 9.6.7 on x86_64-pc-linux-gnu, compiled by gcc (Debian 6.3.0-18) 6.3.0 20170516, 64-bit\")\n: ELISP\u003e (pq:query *pq* \"create table local_variables(name text, value text)\")\n: nil\n: ELISP\u003e (dolist (el (buffer-local-variables))\n: \t (pq:query *pq* \"insert into local_variables values ($1, $2)\"\n: \t\t   (car el) (cdr el)))\n: nil\n: ELISP\u003e (pq:query *pq* \"select name, length(value) from local_variables where value ~ 'mode'\")\n: ([\"major-mode\" 24]\n:  [\"change-major-mode-hook\" 86]\n:  [\"hi-lock-mode-major-mode\" 24]\n:  [\"eldoc-mode-major-mode\" 24]\n:  [\"font-lock-major-mode\" 24]\n:  [\"font-lock-mode-major-mode\" 24])\n\n* Error Handling\n=pq= raises SQL errors as error signal =pq:error=.  This provides the\n[[https://www.postgresql.org/docs/current/errcodes-appendix.html][SQLSTATE]] error code in an additional string in the error data list.\nFor example, you can reliably catch unique violations like this:\n\n: (condition-case err (pq:query *pq* \"insert into t values (666)\")\n:   (pq:error\n:    (if (string= \"23505\" (nth 2 err))\n:        (progn\n: \t (message \"Caught a unique violation\"))\n:      ;; re-throw anything else\n:      (signal (car err) (cdr err)))))\n\n* Conversion of data types from SQL to Emacs Lisp\n=pq= converts bigints and numerics your queries return to lisp floats\nbecause they don't fit into a lisp integer.  This looses precision on\nbig values.  If you need the full precision, cast them to =text= and\nuse, e.g., =calc-eval= to do arbitrary precision things with them.\nAll other data types are returned as utf-8 strings.\n\n* Conversion of data types from Emacs Lisp to SQL\nStrings and the query text itself is converted to utf-8 by the module\ninterface.  If this conversion fails, the behavior is undefined by the\nmodule interface.  If you want to send strings that are not valid\nutf-8, you need to work around this.  For example, I'm using code like\nthe following to store raw bytes into a table with a =bytea= column:\n\n:  (pq:query *con*\n:    \"insert into t (blob) values (decode($1, 'base64'))\"\n:    (base64-encode-string my-random-bytes))\n\nAny non-string parameter to pq:query is turned into an emacs string\nusing =prin1-to-string= first.  This works quite well to store\narbitrary lisp data and read it back with =read=.  All other aspects\nof =prin1-to-string= apply too.  For example, when =print-length= or\n=print-level= are set to non-nil, these would be applied as well.\n\n* Notifications\nAfter a [[https://www.postgresql.org/docs/current/sql-listen.html][=LISTEN=]] statement, PostgreSQL will deliver notifications\nasynchronously over the connection.  Since the emacs-module interface\ndoes not allow for asynchronous callbacks, you have to check for these\nperiodically after a =LISTEN= statement by calling =pq:notifies=.\nCalling it will not cause any traffic on the connection itself.\n\nSee the testsuite [[./test.el]] for more implemented features.\n\n[[https://api.travis-ci.org/anse1/emacs-libpq.svg]]\n","funding_links":[],"categories":["C"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanse1%2Femacs-libpq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanse1%2Femacs-libpq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanse1%2Femacs-libpq/lists"}