anse1 / emacs-libpq

An Emacs 25 module for accessing postgres via libpq.
GNU General Public License v3.0
22 stars 4 forks source link
emacs-modules postgresql-driver

An Emacs 25 module for accessing PostgreSQL via the libpq client library.

Using libpq for client connections has various advantages over the wire-protocol speaking pure elisp implementations. For example, it has better performance and supports all features of the protocol like full TLS support and new authentication methods like scram-sha-256.

It doesn't expose many libpq features yet, but what's there should be crash-safe no matter what you do in the lisp world. I've been using it for three years now for reading mail through my custom Gnus backend without incidents. If you make it crash, please report.

: (condition-case err (pq:query pq "insert into t values (666)") : (pq:error : (if (string= "23505" (nth 2 err)) : (progn : (message "Caught a unique violation")) : ;; re-throw anything else : (signal (car err) (cdr err)))))

: (pq:query con : "insert into t (blob) values (decode($1, 'base64'))" : (base64-encode-string my-random-bytes))

Any non-string parameter to pq:query is turned into an emacs string using =prin1-to-string= first. This works quite well to store arbitrary lisp data and read it back with =read=. All other aspects of =prin1-to-string= apply too. For example, when =print-length= or =print-level= are set to non-nil, these would be applied as well.

See the testsuite [[./test.el]] for more implemented features.

[[https://api.travis-ci.org/anse1/emacs-libpq.svg]]