diff --git a/server/Cargo.toml b/server/Cargo.toml index fb1a4573..b4955ca7 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -10,10 +10,15 @@ SPARQL server based on Oxigraph """ edition = "2018" +[features] +sled = ["oxigraph/sled"] +rocksdb = ["oxigraph/rocksdb"] +default = ["rocksdb"] + [dependencies] argh = "0.1" async-std = { version = "1", features = ["attributes"] } async-h1 = "2" http-types = "2" -oxigraph = { version = "0.1", path="../lib", features = ["rocksdb", "http_client"] } +oxigraph = { version = "0.1", path="../lib", features = ["http_client"] } url = "2" diff --git a/server/src/main.rs b/server/src/main.rs index 5b22878d..fe39139f 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -19,11 +19,15 @@ use http_types::{headers, Body, Error, Method, Mime, Request, Response, Result, use oxigraph::io::{DatasetFormat, GraphFormat}; use oxigraph::model::{GraphName, NamedNode}; use oxigraph::sparql::{Query, QueryOptions, QueryResults, QueryResultsFormat, Update}; -use oxigraph::RocksDbStore; use std::io::BufReader; use std::str::FromStr; use url::form_urlencoded; +#[cfg(feature = "rocksdb")] +use oxigraph::RocksDbStore as Store; +#[cfg(all(feature = "sled", not(feature = "rocksdb")))] +use oxigraph::SledStore as Store; + const MAX_SPARQL_BODY_SIZE: u64 = 1_048_576; const HTML_ROOT_PAGE: &str = include_str!("../templates/query.html"); const LOGO: &str = include_str!("../../logo.svg"); @@ -44,7 +48,7 @@ struct Args { #[async_std::main] pub async fn main() -> Result<()> { let args: Args = argh::from_env(); - let store = RocksDbStore::open(args.file)?; + let store = Store::open(args.file)?; println!("Listening for requests at http://{}", &args.bind); http_server(&args.bind, move |request| { @@ -53,7 +57,7 @@ pub async fn main() -> Result<()> { .await } -async fn handle_request(request: Request, store: RocksDbStore) -> Result { +async fn handle_request(request: Request, store: Store) -> Result { let mut response = match (request.url().path(), request.method()) { ("/", Method::Get) => { let mut response = Response::new(StatusCode::Ok); @@ -187,7 +191,7 @@ fn simple_response(status: StatusCode, body: impl Into) -> Response { } async fn evaluate_urlencoded_sparql_query( - store: RocksDbStore, + store: Store, encoded: Vec, request: Request, ) -> Result { @@ -218,7 +222,7 @@ async fn evaluate_urlencoded_sparql_query( } async fn evaluate_sparql_query( - store: RocksDbStore, + store: Store, query: String, default_graph_uris: Vec, named_graph_uris: Vec, @@ -286,10 +290,7 @@ async fn evaluate_sparql_query( .await } -async fn evaluate_urlencoded_sparql_update( - store: RocksDbStore, - encoded: Vec, -) -> Result { +async fn evaluate_urlencoded_sparql_update(store: Store, encoded: Vec) -> Result { let mut update = None; let mut default_graph_uris = Vec::new(); let mut named_graph_uris = Vec::new(); @@ -317,7 +318,7 @@ async fn evaluate_urlencoded_sparql_update( } async fn evaluate_sparql_update( - store: RocksDbStore, + store: Store, update: String, default_graph_uris: Vec, named_graph_uris: Vec, @@ -438,10 +439,10 @@ impl std::io::Read for SyncAsyncReader { #[cfg(test)] mod tests { + use super::Store; use crate::handle_request; use async_std::task::block_on; use http_types::{Method, Request, StatusCode, Url}; - use oxigraph::RocksDbStore; use std::collections::hash_map::DefaultHasher; use std::env::temp_dir; use std::fs::remove_dir_all; @@ -570,7 +571,7 @@ mod tests { format!("{:?}", request).hash(&mut s); path.push(&s.finish().to_string()); - let store = RocksDbStore::open(&path).unwrap(); + let store = Store::open(&path).unwrap(); let (code, message) = match block_on(handle_request(request, store)) { Ok(r) => (r.status(), "".to_string()), Err(e) => (e.status(), e.to_string()),