A simple (and very early) Scala wrapper to access eXist DB
Store and retrieve XML and binary objects:
val db = XmlDb() // defaults: server="localhost", port=8080, user="guest", pass="guest"
db.putXml(<some><xml>element</xml></some>, collectionId, xmlDocId)
db.putBin("data".getBytes, collectionId, binDocId)
val xml: Option[List[Elem]] = db.getXml(collectionId)
val bin: Option[List[Array[Byte]]] = db.getBin(collectionId)
Query a Lucene index, e.g. if you set up your eXist DB to index note
elements and their type
attributes and you store data like this:
db.putXml(<p><note type="quick">text1</note></p>, "test", "query-test-1")
db.putXml(<p><note type="quick">text2</note></p>, "test", "query-test-2")
You can query with XQuery and Lucene query syntax:
val res = db.query("test", "for $m in //note[ft:query(., 'text?')]/ancestor::p return $m")
Full sample usage (includes index setup and queries on attributes) can be found in the XmlDbSpec.
Some background and details can be found in this blog post.
git clone git://github.com/fsteeg/sinist.git
; cd sinist
; sbt
To run the tests, have an eXist DB running via startup.sh
at localhost:7777
(or change port in XmlDbSpec
).
Building with SBT:
- update
- test
- package
This will fetch dependencies, run the tests, and create a jar in the sinist/target
directory.