Did you know ... | Search Documentation: |
Packs (add-ons) for SWI-Prolog |
Title: | Document-oriented database for Prolog |
---|---|
Rating: | Not rated. Create the first rating! |
Latest version: | 2.0.2 |
SHA1 sum: | 6b418a6588b573b9e167fa2d87bb60fe9e8ae521 |
Author: | Raivo Laanemets http://rlaanemets.com/ |
Home page: | https://github.com/rla/docstore |
No reviews. Create the first review!.
Version | SHA1 | #Downloads | URL |
---|---|---|---|
0.0.1 | ed7ca9d321531ecded1ea3eb9f3966df926a97f5 | 1 | http://packs.rlaanemets.com/docstore/docstore-0.0.1.tgz |
0.0.2 | c9760609d0ccb6e090d256462df2c2e7665dd26c | 2 | http://packs.rlaanemets.com/docstore/docstore-0.0.2.tgz |
1.0.0 | 879f68afb116e3781fa769bf099ce7324121c7f3 | 4 | http://packs.rlaanemets.com/docstore/docstore-1.0.0.tgz |
1.0.1 | 856a70d1f8e1978d7a8ab330756246af4bacaa9a | 28 | http://packs.rlaanemets.com/docstore/docstore-1.0.1.tgz |
2.0.0 | 29908cb4c5170e35cb55bd44ed3ce86ae570fc7a | 1 | http://packs.rlaanemets.com/docstore/docstore-2.0.0.tgz |
2.0.1 | fca7287b20b6b25e0a99a3a0d95844edd978dddc | 123 | http://packs.rlaanemets.com/docstore/docstore-2.0.1.tgz |
2.0.2 | 6b418a6588b573b9e167fa2d87bb60fe9e8ae521 | 43 | http://packs.rlaanemets.com/docstore/docstore-2.0.2.tgz |
Document-oriented transactional in-memory database for SWI-Prolog. Documents are represented
using dicts and are organized
into collections. Each document is assigned an unique identifier ($id
) that can
be later used to retrieve/update/remove the document.
Data is stored in-memory and database changes are journaled onto the disk. This
works similar to persistency.pl
except that the high-level interface is different (documents vs. predicates) and the library
is thread-safe. The library supports transactions and hooks (before_save
, before_remove
).
![Build Status](https://travis-ci.org/rla/docstore)
Open database:
?- ds_open('test.db'). true.
Insert some data:
?- ds_insert(vehicle{year: 1926, make: chrysler, model: imperial}). ?- ds_insert(vehicle{year: 1953, make: chevrolet, model: corvette}). ?- ds_insert(vehicle{year: 1954, make: cadillac, model: fleetwood}).
Query all documents in a collection:
?- ds_all(vehicle, List). List = [ vehicle{'$id':'f3012622-cacb-4d7f-a22a-c36305274a80', make:chrysler, model:imperial, year:1926}, vehicle{'$id':'23418d47-5835-41ff-a6b8-8748f3b2163e', make:chevrolet, model:corvette, year:1953}, vehicle{'$id':'8c79f80f-d43e-4fad-a1bb-5fca23a195e0', make:cadillac, model:fleetwood, year:1954}].
Query by condition:
?- ds_find(vehicle, year=1953, List). List = [ vehicle{'$id':'23418d47-5835-41ff-a6b8-8748f3b2163e', make:chevrolet, model:corvette, year:1953}].
Update:
?- ds_update(vehicle{'$id':'23418d47-5835-41ff-a6b8-8748f3b2163e', year: 1954}). ?- ds_col_get(vehicle, '23418d47-5835-41ff-a6b8-8748f3b2163e', Vehicle). Vehicle = vehicle{'$id':'23418d47-5835-41ff-a6b8-8748f3b2163e', make:chevrolet, model:corvette, year:1954}.
Remove:
?- ds_col_remove(vehicle, '23418d47-5835-41ff-a6b8-8748f3b2163e'). ?- ds_all(vehicle, List). List = [ vehicle{'$id':'f3012622-cacb-4d7f-a22a-c36305274a80', make:chrysler, model:imperial, year:1926}, vehicle{'$id':'8c79f80f-d43e-4fad-a1bb-5fca23a195e0', make:cadillac, model:fleetwood, year:1954}].
Transactions are built-in to guarantee database consistency. Each predicate that
modifies database (such as ds_insert
) starts implicit transaction. Transactions
can be nested. In that case only the outer transaction has effect. To use explicit
transaction, use ds_transactional/1. Example:
fail_test:- ds_insert(vehicle{year: 1926, make: chrysler, model: imperial}), fail.
Running this through ds_transactional/1 causes no changes made by
ds_insert
to be persisted as the predicate ends with fail
. Same would
happen when the predicate threw an exception.
Two kinds of hooks are supported: before save and before remove. Hooks are registered using the ds_hook/3 predicate. Hook that fails or throws an exception will abort the current transaction. Transactions inside hooks are joined with the currently running transaction.
Requires SWI-Prolog 7.x.
pack_install(docstore).
load_tx_begin
not being a predicate indicator.See http://packs.rlaanemets.com/docstore/doc/.
Enable debugging with debug(docstore)
on the console.
before_save
hooks are only given updated values not whole document. This might change.Please send bug reports/feature request through the GitHub project page.
The MIT License.
Pack contains 7 files holding a total of 44.8K bytes.