Fork me on GitHub

Not sure how to work the api with a reference to db (instead of conn):

(d/with-conn [conn "/pbdb"]
    (assert (d/db? (d/db conn)))
    ;(pp/pprint (d/stat conn))
    ;(d/copy (d/db conn) "/pbdb-backup")
    ;(d/copy conn "/pbdb-backup")
both the stat and copy functions seem to work on a "db" instance, but not sure how to concoct a db from a connection or a directory-path to the db-files... Error message in stack trace not too helpful: "No implementation of method: :copy of protocol: #'datalevin.lmdb/ILMDB found for class: datalevin.db.DB", :at [clojure.core$cacheprotocol_fn invokeStatic "core_deftype.clj" 583]}],


copy takes a key-value db, not a datalog db


the error message is very clear on that


to get a LMDB instance of the datalog db, you can try (.-lmdb (.-store db))


I expect people to use dtlv command line tool to do database backup, so the API is not really designed for people to do this programmatically. It’s doable, but not as convenient as it could be.


i can update the doc-string to make it clear that copy expect a key-value db.


actually, I will do better, I will release a version to allow datalog db to be copied programmatically easily, just like the code you tried.


Thanks! That would make integration easier. It’s a little confusing that datalevin has the concepts of those different dbs that all are build off the same db-files… and the docs do not really distinguish those. Most users will happily use datalevin without ever having to know about those details - guess I’m the lucky one ;-)


An easy programmatic way to copy the datalevin db would be nice. Also because using dtlv to do that while the datalevin java-runtime is still active in another process made me wonder if that could cause issues. (?)


it’s not a problem to copy a db file that is being used by another process. LMDB handles that correctly. Just copy away.


Ok… the following seems to work: (when-not data-mdb (d/with-conn [conn "/pbdb"] (let [dl-db (d/db conn) lmdb-db (.-lmdb (.-store dl-db))] (assert (d/db? dl-db)) (pp/pprint (d/stat lmdb-db)) (d/copy lmdb-db "/pbdb-backup") ))) Which yields a single data.mdb file in the newly created /pbdb-backup dir - so no lock.mdb file - is that expected?


the lock file will be created when you open the db

👍 1