An embedded Sedna XML Database for Rust.
sedna-rs is a Rust library that embeds the Sedna XML Database, providing a complete XQuery-capable XML database that runs entirely within your Rust application. No external installation required - the database server binaries are compiled and embedded at build time.
- Fully Embedded: Database server binaries are embedded in your application
- Zero Configuration: Server lifecycle is automatically managed
- XQuery 1.0 Support: Full XQuery implementation for powerful XML querying
- ACID Transactions: Complete transaction support with commit/rollback
- Safe Rust API: Type-safe wrappers around the C FFI layer
- Multiple Instances: Run multiple isolated database servers simultaneously
- Unix/Mac Support: Works on Linux and macOS (no Windows support)
- CMake 2.6 or higher
- C/C++ compiler (GCC or Clang)
- Make
- Unix-like operating system (Linux or macOS)
- No external dependencies
Add to your Cargo.toml:
[dependencies]
sedna-rs = "0.1"use sedna_rs::{SednaServer, Result};
fn main() -> Result<()> {
// Start an embedded Sedna server
let server = SednaServer::new()?;
// Connect to the default database
let mut client = server.connect("testdb", "SYSTEM", "MANAGER")?;
// Begin a transaction
client.begin_transaction()?;
// Load an XML document
client.execute(r#"
CREATE DOCUMENT "book" IN COLLECTION "library"
<book>
<title>The Rust Programming Language</title>
<author>Steve Klabnik</author>
<year>2018</year>
</book>
"#)?;
// Commit the transaction
client.commit_transaction()?;
// Query the document
let mut result = client.execute("doc('book')//title")?;
while let Some(item) = result.next()? {
println!("Title: {}", item);
}
Ok(())
}The SednaServer manages the lifecycle of an embedded Sedna database instance.
// Start server on default port (5050)
let server = SednaServer::new()?;
// Start server on specific port
let server = SednaServer::with_port(5060)?;
// Get the server's port
let port = server.port();
// Connect to a database
let client = server.connect("dbname", "username", "password")?;The server automatically shuts down when dropped.
The SednaClient provides methods for interacting with the database.
// Execute a query
let mut result = client.execute("doc('test')//item")?;
// Transaction management
client.begin_transaction()?;
client.commit_transaction()?;
client.rollback_transaction()?;The QueryResult allows iteration over query results.
// Iterate over results one by one
while let Some(item) = result.next()? {
println!("{}", item);
}
// Collect all results into a vector
let all_results = result.collect_all()?;client.execute(r#"
CREATE DOCUMENT "mydoc" IN COLLECTION "mycollection"
<root>
<item id="1">First</item>
<item id="2">Second</item>
</root>
"#)?;// Simple path expressions
client.execute("doc('mydoc')//item")?;
// With predicates
client.execute("doc('mydoc')//item[@id='1']")?;
// FLWOR expressions
client.execute(r#"
for $item in doc('mydoc')//item
where $item/@id > 1
return $item
"#)?;// Replace a node
client.execute(r#"
UPDATE replace $x in doc('mydoc')//item[@id='1']
with <item id="1">Updated</item>
"#)?;
// Insert a node
client.execute(r#"
UPDATE insert <item id="3">Third</item>
into doc('mydoc')/root
"#)?;
// Delete a node
client.execute(r#"
UPDATE delete $x in doc('mydoc')//item[@id='2']
"#)?;sedna-rs works by:
- Build Time: Compiling the Sedna C library (
libsedna) and full Sedna server using CMake - Embedding: Including the compiled binaries in the Rust library using
include_bytes!() - Runtime: Extracting binaries to a temporary directory when first needed
- Lifecycle: Starting the
se_gov(governor) process and creating databases as needed - Cleanup: Automatically terminating server processes and cleaning up temp files on drop
cargo run --example quickstartcargo testNote: Tests may take some time as each test starts its own embedded database server.
The embedded server starts in approximately 100-200ms on modern hardware. Query performance is equivalent to standalone Sedna installations.
- Unix/Mac only (no Windows support)
- Each
SednaServerinstance runs isolated processes and uses system resources - Port conflicts will occur if multiple servers use the same port
This library embeds and wraps the Sedna XML Database, developed by the Institute for System Programming of the Russian Academy of Sciences (ISP RAS).
Apache-2.0
Contributions welcome! Please ensure tests pass before submitting PRs.