With great trepidation I announce the 0.1 version of the swiplite
pack (add-on). It is not ready but it can already be used; or at least looked at.
The code is available at GitHub - borisvassilev/swiplite: SQLite for SWI-Prolog.
You should be able to clone it and see what is in there. I have tried to document it. There is a README; there is also a DEVELOPMENT readme. If you manage to follow the instructions there you’d be able to access the predicate documentation by starting a local PlDoc server.
If you are brave you can install the pack using the two releases. “Latest” is currently 0.1. You can use for example:
?- pack_install(swiplite,
[url('https://github.com/borisvassilev/swiplite/archive/0.1.zip')]).
I have doubts about everything:
- was such a binding really necessary?
- the license
- names: the pack, the library, the predicates…
- error handling
- documentation style
and so on. Any feedback is greatly appreciated.
One additional note: you might remember this post. There I asked if it is a good idea to embed the full SQLite source code in the source distribution of this pack. In order to avoid this question, I now have, in addition to the main
branch, a branch called sqlite3-amalgamation
which includes the latest SQLite source, instead of using the SQLite installation that CMake finds on your system. This is available as release 0.1.1, so:
?- pack_install(swiplite,
[url('https://github.com/borisvassilev/swiplite/archive/0.1.1.zip')]).
Either way, you should be able to see something along these lines:
?- use_module(library(sqlite)).
true.
?- sqlite_open(foo, DB, [memory(true)]),
sqlite_prepare(DB, "select sqlite_version()", S),
sqlite_eval(S, row(V)),
sqlite_finalize(S),
sqlite_close(DB).
DB = <sqlite_connection>(closed),
S = <sqlite_statement>(finalized),
V = "3.47.1".
As you see, this is very low-level. You should be using setup_call_cleanup/3 anyway. You can look at the tests to get an idea how to use it. I will share any useful higher-level library once I have one.
One final note: This is a hobby project. I don’t believe that this competes, in terms of features, with any of the currently available methods to use SQLite from SWI-Prolog. It is written by me from scratch; but I did read quite a bit of the code I found in SWI-Prolog · GitHub.