thanks in advance for the help!
I would like to set up a Lisp program that does something when my Postgres database table is updated. I'm using the amazing Postmodern library, which has been absolutely terrific.
As discussed in this question (client side notification on table change in Common Lisp with Postmodern package) I don't want to poll the database (as the OP complains of the answer), but instead want the database to tell my program when to do something.
The person who answered points to the Postmodern function "wait-for-notifications": https://github.com/marijnh/Postmodern/blob/22aab0ec25d5f6affd390e690827a7515aeafd4f/cl-postgres/public.lisp#L358-L370
I am a little concerned about this function because 1. it is internal to Postmodern and therefore (let me know if I'm wrong here) not for public consumption and 2. it takes "database-connection" as an argument, which I can't track down.
So:
- Can anyone point me in the right direction for understanding and working with "database-connection" properly?
- Tell me that I'm barking up the wrong tree here and, if so, point me in the right direction for learning how to get my Lisp program to do something when my table changes?
Thank you so much!
There are different layers,
wait-for-notificationis an exported symbol fromcl-postgrespackage, and defined in a file namedpublic.lisp, so this should be ok to use it directly. Postmodern is at a higher level of abstraction but depending on your needs you are allowed to call directlycl-postgresfunctions.A connection is what you get when you call
open-database. Helper macros likewith-connectionbind the special*database*variable. Usually this is used invisibly byqueryand other commands, which look at the current binding for*database*. However if you want to understand a bit more how it is used, the documentation at https://marijnhaverbeke.nl/postmodern/cl-postgres.html seems quite good.Remark
If you are going to wait for changes in your tables, chances are that you will want to use a dedicated thread. The documentation says that: