How to open and close a database connection with http_unix_daemon?

I want to open a connection to Postgresql with ODBC when I fire up a http server using something like

swipl --port=3030

and close it when I do kill $(cat

Would this work?

:- use_module(library(http/http_unix_daemon)).
:- initialization(run, main).

run :-
        odbc_connect(dbname, _, [alias(dbname)]),

That probably works. Alternatively use at_halt/1. Iā€™d assume it is not too critical. The OS will close the network connection and the DB will disconnect. That may take some time. As the HTTP server is probably supposed to live long that is unlikely to cause any problems.

1 Like