From 8f2e918f912073b3c273799daf3cfb5cb7029352 Mon Sep 17 00:00:00 2001 From: Ziyang Hu Date: Fri, 25 Nov 2022 21:37:48 +0800 Subject: [PATCH] bump version and update API --- Cargo.lock | 16 ++++++++-------- VERSION | 2 +- cozo-core/Cargo.toml | 2 +- cozo-core/src/lib.rs | 22 +++++++++++----------- cozo-core/tests/air_routes.rs | 2 +- cozo-lib-c/Cargo.toml | 4 ++-- cozo-lib-c/cozo_c.h | 9 +++++---- cozo-lib-c/src/lib.rs | 15 +++++++++++---- cozo-lib-java/Cargo.toml | 4 ++-- cozo-lib-java/CozoJavaBridge.java | 2 +- cozo-lib-java/org_cozodb_CozoJavaBridge.h | 4 ++-- cozo-lib-java/src/lib.rs | 8 +++++--- cozo-lib-nodejs/Cargo.toml | 4 ++-- cozo-lib-nodejs/src/lib.rs | 5 +++-- cozo-lib-python/Cargo.toml | 4 ++-- cozo-lib-python/src/lib.rs | 4 ++-- cozo-lib-swift/Cargo.toml | 4 ++-- cozo-lib-swift/src/lib.rs | 6 +++--- cozo-lib-wasm/Cargo.toml | 4 ++-- cozo-lib-wasm/src/lib.rs | 2 +- cozoserver/Cargo.toml | 4 ++-- cozoserver/src/main.rs | 10 +++++----- 22 files changed, 74 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 49228a09..9cbda885 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -492,7 +492,7 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "cozo" -version = "0.2.0" +version = "0.2.1" dependencies = [ "approx", "base64", @@ -541,7 +541,7 @@ dependencies = [ [[package]] name = "cozo-lib-wasm" -version = "0.2.0" +version = "0.2.1" dependencies = [ "console_error_panic_hook", "cozo", @@ -552,7 +552,7 @@ dependencies = [ [[package]] name = "cozo-node" -version = "0.2.0" +version = "0.2.1" dependencies = [ "cozo", "lazy_static", @@ -561,7 +561,7 @@ dependencies = [ [[package]] name = "cozo-swift" -version = "0.2.0" +version = "0.2.1" dependencies = [ "cozo", "swift-bridge", @@ -570,7 +570,7 @@ dependencies = [ [[package]] name = "cozo_c" -version = "0.2.0" +version = "0.2.1" dependencies = [ "cbindgen", "cozo", @@ -579,7 +579,7 @@ dependencies = [ [[package]] name = "cozo_java" -version = "0.2.0" +version = "0.2.1" dependencies = [ "cozo", "jni", @@ -588,7 +588,7 @@ dependencies = [ [[package]] name = "cozo_py" -version = "0.2.0" +version = "0.2.1" dependencies = [ "cozo", "pyo3", @@ -611,7 +611,7 @@ dependencies = [ [[package]] name = "cozoserver" -version = "0.2.0" +version = "0.2.1" dependencies = [ "chrono", "clap 4.0.26", diff --git a/VERSION b/VERSION index 341cf11f..7dff5b89 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.0 \ No newline at end of file +0.2.1 \ No newline at end of file diff --git a/cozo-core/Cargo.toml b/cozo-core/Cargo.toml index 0c61aefc..fc1f10c6 100644 --- a/cozo-core/Cargo.toml +++ b/cozo-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cozo" -version = "0.2.0" +version = "0.2.1" edition = "2021" description = "A general-purpose, transactional, relational database that uses Datalog and focuses on graph data and algorithms" authors = ["Ziyang Hu"] diff --git a/cozo-core/src/lib.rs b/cozo-core/src/lib.rs index 34224b70..c7235dbd 100644 --- a/cozo-core/src/lib.rs +++ b/cozo-core/src/lib.rs @@ -98,7 +98,7 @@ pub enum DbInstance { impl DbInstance { /// Create a DbInstance, which is a dispatcher for various concrete implementations. - /// The valid kinds are: + /// The valid engines are: /// /// * `mem` /// * `sqlite` @@ -107,14 +107,14 @@ impl DbInstance { /// * `tikv` /// /// assuming all features are enabled during compilation. Otherwise only - /// some of the kinds are available. The `mem` kind is always available. + /// some of the engines are available. The `mem` kind is always available. /// - /// `path` is ignored for `mem` and `tikv` kinds. - /// `options` is ignored for every kind except `tikv`. + /// `path` is ignored for `mem` and `tikv` engines. + /// `options` is ignored for every engine except `tikv`. #[allow(unused_variables)] - pub fn new(kind: &str, path: &str, options: &str) -> Result { + pub fn new(engine: &str, path: &str, options: &str) -> Result { let options = if options.is_empty() { "{}" } else { options }; - Ok(match kind { + Ok(match engine { "mem" => Self::Mem(new_cozo_mem()?), #[cfg(feature = "storage-sqlite")] "sqlite" => Self::Sqlite(new_cozo_sqlite(path.to_string())?), @@ -133,19 +133,19 @@ impl DbInstance { let opts: TiKvOpts = serde_json::from_str(options).into_diagnostic()?; Self::TiKv(new_cozo_tikv(opts.end_points.clone(), opts.optimistic)?) } - kind => bail!( - "database kind '{}' not supported (maybe not compiled in)", - kind + k => bail!( + "database engine '{}' not supported (maybe not compiled in)", + k ), }) } /// Same as [Self::new], but inputs and error messages are all in strings pub fn new_with_str( - kind: &str, + engine: &str, path: &str, options: &str, ) -> std::result::Result { - Self::new(kind, path, options).map_err(|err| err.to_string()) + Self::new(engine, path, options).map_err(|err| err.to_string()) } /// Dispatcher method. See [crate::Db::run_script]. pub fn run_script( diff --git a/cozo-core/tests/air_routes.rs b/cozo-core/tests/air_routes.rs index 1e81bf51..f7553a64 100644 --- a/cozo-core/tests/air_routes.rs +++ b/cozo-core/tests/air_routes.rs @@ -25,7 +25,7 @@ lazy_static! { let path = "_test_air_routes"; _ = std::fs::remove_file(path); _ = std::fs::remove_dir_all(path); - let db_kind = env::var("COZO_TEST_DB_KIND").unwrap_or("mem".to_string()); + let db_kind = env::var("COZO_TEST_DB_ENGINE").unwrap_or("mem".to_string()); let db = DbInstance::new(&db_kind, path, Default::default()).unwrap(); dbg!(creation.elapsed()); diff --git a/cozo-lib-c/Cargo.toml b/cozo-lib-c/Cargo.toml index 9b599650..f2169b59 100644 --- a/cozo-lib-c/Cargo.toml +++ b/cozo-lib-c/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cozo_c" -version = "0.2.0" +version = "0.2.1" edition = "2021" license = "MPL-2.0" homepage = "https://github.com/cozodb/cozo" @@ -42,7 +42,7 @@ nothread = ["cozo/nothread"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cozo = { version = "0.2.0", path = "../cozo-core", default_features = false } +cozo = { version = "0.2.1", path = "../cozo-core", default_features = false } lazy_static = "1.4.0" [build-dependencies] diff --git a/cozo-lib-c/cozo_c.h b/cozo-lib-c/cozo_c.h index 85cf336e..bbf5870d 100644 --- a/cozo-lib-c/cozo_c.h +++ b/cozo-lib-c/cozo_c.h @@ -17,15 +17,16 @@ extern "C" { /** * Open a database. * - * `engine`: Which storage engine to use, can be "mem", "sqlite" or "rocksdb". - * `path`: should contain the UTF-8 encoded path name as a null-terminated C-string. - * `db_id`: will contain the id of the database opened. + * `engine`: which storage engine to use, can be "mem", "sqlite" or "rocksdb". + * `path`: should contain the UTF-8 encoded path name as a null-terminated C-string. + * `db_id`: will contain the id of the database opened. + * `options`: options for the DB constructor: engine dependent. * * When the function is successful, null pointer is returned, * otherwise a pointer to a C-string containing the error message will be returned. * The returned C-string must be freed with `cozo_free_str`. */ -char *cozo_open_db(const char *engine, const char *path, int32_t *db_id); +char *cozo_open_db(const char *engine, const char *path, const char *options, int32_t *db_id); /** * Close a database. diff --git a/cozo-lib-c/src/lib.rs b/cozo-lib-c/src/lib.rs index af30dd0b..a1cef6ad 100644 --- a/cozo-lib-c/src/lib.rs +++ b/cozo-lib-c/src/lib.rs @@ -31,9 +31,10 @@ lazy_static! { /// Open a database. /// -/// `engine`: Which storage engine to use, can be "mem", "sqlite" or "rocksdb". -/// `path`: should contain the UTF-8 encoded path name as a null-terminated C-string. -/// `db_id`: will contain the id of the database opened. +/// `engine`: which storage engine to use, can be "mem", "sqlite" or "rocksdb". +/// `path`: should contain the UTF-8 encoded path name as a null-terminated C-string. +/// `db_id`: will contain the id of the database opened. +/// `options`: options for the DB constructor: engine dependent. /// /// When the function is successful, null pointer is returned, /// otherwise a pointer to a C-string containing the error message will be returned. @@ -42,6 +43,7 @@ lazy_static! { pub unsafe extern "C" fn cozo_open_db( engine: *const c_char, path: *const c_char, + options: *const c_char, db_id: &mut i32, ) -> *mut c_char { let engine = match CStr::from_ptr(engine).to_str() { @@ -54,7 +56,12 @@ pub unsafe extern "C" fn cozo_open_db( Err(err) => return CString::new(format!("{}", err)).unwrap().into_raw(), }; - let db = match DbInstance::new_with_str(engine, path, "{}") { + let options = match CStr::from_ptr(options).to_str() { + Ok(p) => p, + Err(err) => return CString::new(format!("{}", err)).unwrap().into_raw(), + }; + + let db = match DbInstance::new_with_str(engine, path, options) { Ok(db) => db, Err(err) => return CString::new(err).unwrap().into_raw(), }; diff --git a/cozo-lib-java/Cargo.toml b/cozo-lib-java/Cargo.toml index c5181752..a83c4cf7 100644 --- a/cozo-lib-java/Cargo.toml +++ b/cozo-lib-java/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cozo_java" -version = "0.2.0" +version = "0.2.1" edition = "2021" license = "MPL-2.0" homepage = "https://github.com/cozodb/cozo" @@ -21,5 +21,5 @@ io-uring = ["cozo/io-uring"] [dependencies] jni = "0.20.0" # , features = ["compact"] -cozo = { version = "0.2.0", path = "../cozo-core", default_features = false, features = ["compact"] } +cozo = { version = "0.2.1", path = "../cozo-core", default_features = false, features = ["compact"] } lazy_static = "1.4.0" diff --git a/cozo-lib-java/CozoJavaBridge.java b/cozo-lib-java/CozoJavaBridge.java index fb3b37eb..47b2c203 100644 --- a/cozo-lib-java/CozoJavaBridge.java +++ b/cozo-lib-java/CozoJavaBridge.java @@ -1,7 +1,7 @@ package org.cozodb; public class CozoJavaBridge { - private static native int openDb(String kind, String path); + private static native int openDb(String engine, String path, String options); private static native boolean closeDb(int id); private static native String runQuery(int id, String script, String params); private static native String exportRelations(int id, String rel); diff --git a/cozo-lib-java/org_cozodb_CozoJavaBridge.h b/cozo-lib-java/org_cozodb_CozoJavaBridge.h index 018f6bb4..c2b5d1bc 100644 --- a/cozo-lib-java/org_cozodb_CozoJavaBridge.h +++ b/cozo-lib-java/org_cozodb_CozoJavaBridge.h @@ -10,10 +10,10 @@ extern "C" { /* * Class: org_cozodb_CozoJavaBridge * Method: openDb - * Signature: (Ljava/lang/String;Ljava/lang/String;)I + * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I */ JNIEXPORT jint JNICALL Java_org_cozodb_CozoJavaBridge_openDb - (JNIEnv *, jclass, jstring, jstring); + (JNIEnv *, jclass, jstring, jstring, jstring); /* * Class: org_cozodb_CozoJavaBridge diff --git a/cozo-lib-java/src/lib.rs b/cozo-lib-java/src/lib.rs index 5feb4396..0a75b309 100644 --- a/cozo-lib-java/src/lib.rs +++ b/cozo-lib-java/src/lib.rs @@ -38,12 +38,14 @@ fn get_db(id: i32) -> Option { pub extern "system" fn Java_org_cozodb_CozoJavaBridge_openDb( env: JNIEnv, _class: JClass, - kind: JString, + engine: JString, path: JString, + options: JString, ) -> jint { - let kind: String = env.get_string(kind).unwrap().into(); + let engine: String = env.get_string(engine).unwrap().into(); let path: String = env.get_string(path).unwrap().into(); - let id = match DbInstance::new(&kind, &path, Default::default()) { + let options: String = env.get_string(options).unwrap().into(); + let id = match DbInstance::new(&engine, &path, &options) { Ok(db) => { let id = HANDLES.current.fetch_add(1, Ordering::AcqRel); let mut dbs = HANDLES.dbs.lock().unwrap(); diff --git a/cozo-lib-nodejs/Cargo.toml b/cozo-lib-nodejs/Cargo.toml index f77f819a..6482260b 100644 --- a/cozo-lib-nodejs/Cargo.toml +++ b/cozo-lib-nodejs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cozo-node" -version = "0.2.0" +version = "0.2.1" description = "Cozo database for NodeJS" authors = ["Ziyang Hu"] license = "MPL-2.0" @@ -44,7 +44,7 @@ nothread = ["cozo/nothread"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cozo = { version = "0.2.0", path = "../cozo-core", default-features = false } +cozo = { version = "0.2.1", path = "../cozo-core", default-features = false } lazy_static = "1.4.0" [dependencies.neon] diff --git a/cozo-lib-nodejs/src/lib.rs b/cozo-lib-nodejs/src/lib.rs index da7ce44c..1b8f4a05 100644 --- a/cozo-lib-nodejs/src/lib.rs +++ b/cozo-lib-nodejs/src/lib.rs @@ -25,9 +25,10 @@ lazy_static! { } fn open_db(mut cx: FunctionContext) -> JsResult { - let kind = cx.argument::(0)?.value(&mut cx); + let engine = cx.argument::(0)?.value(&mut cx); let path = cx.argument::(1)?.value(&mut cx); - match DbInstance::new(&kind, &path, Default::default()) { + let options = cx.argument::(2)?.value(&mut cx); + match DbInstance::new(&engine, &path, &options) { Ok(db) => { let id = HANDLES.current.fetch_add(1, Ordering::AcqRel); let mut dbs = HANDLES.dbs.lock().unwrap(); diff --git a/cozo-lib-python/Cargo.toml b/cozo-lib-python/Cargo.toml index 549f3dac..860294dc 100644 --- a/cozo-lib-python/Cargo.toml +++ b/cozo-lib-python/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cozo_py" -version = "0.2.0" +version = "0.2.1" edition = "2021" description = "Cozo database for python" authors = ["Ziyang Hu"] @@ -45,5 +45,5 @@ nothread = ["cozo/nothread"] [dependencies] -cozo = { version = "0.2.0", path = "../cozo-core", default-features = false } +cozo = { version = "0.2.1", path = "../cozo-core", default-features = false } pyo3 = { version = "0.17.1", features = ["extension-module", "abi3", "abi3-py37"] } diff --git a/cozo-lib-python/src/lib.rs b/cozo-lib-python/src/lib.rs index 385c82a0..bb55e6a6 100644 --- a/cozo-lib-python/src/lib.rs +++ b/cozo-lib-python/src/lib.rs @@ -21,8 +21,8 @@ const DB_CLOSED_MSG: &str = r##"{"ok":false,"message":"database closed"}"##; #[pymethods] impl CozoDbPy { #[new] - fn new(kind: &str, path: &str) -> PyResult { - match DbInstance::new(kind, path, Default::default()) { + fn new(engine: &str, path: &str, options: &str) -> PyResult { + match DbInstance::new(engine, path, options) { Ok(db) => Ok(Self { db: Some(db) }), Err(err) => Err(PyException::new_err(format!("{:?}", err))), } diff --git a/cozo-lib-swift/Cargo.toml b/cozo-lib-swift/Cargo.toml index 955778a0..aafd2f69 100644 --- a/cozo-lib-swift/Cargo.toml +++ b/cozo-lib-swift/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cozo-swift" -version = "0.2.0" +version = "0.2.1" edition = "2021" description = "Cozo database for Swift" authors = ["Ziyang Hu"] @@ -23,5 +23,5 @@ io-uring = ["cozo/io-uring"] swift-bridge-build = "0.1.41" [dependencies] -cozo = { version = "0.2.0", path = "../cozo-core", default-features = false, features = ["compact"] } +cozo = { version = "0.2.1", path = "../cozo-core", default-features = false, features = ["compact"] } swift-bridge = "0.1.41" diff --git a/cozo-lib-swift/src/lib.rs b/cozo-lib-swift/src/lib.rs index 9ea3859d..c500e5e0 100644 --- a/cozo-lib-swift/src/lib.rs +++ b/cozo-lib-swift/src/lib.rs @@ -13,7 +13,7 @@ mod ffi { extern "Rust" { type DbInstance; - fn new_db(kind: &str, path: &str, options: &str) -> Option; + fn new_db(engine: &str, path: &str, options: &str) -> Option; #[swift_bridge(associated_to = DbInstance)] fn run_script_str(&self, payload: &str, params: &str) -> String; @@ -25,9 +25,9 @@ mod ffi { } } -fn new_db(kind: &str, path: &str, options: &str) -> Option { +fn new_db(engine: &str, path: &str, options: &str) -> Option { let options = if options.is_empty() { "{}" } else { options }; - match DbInstance::new_with_str(kind, path, options) { + match DbInstance::new_with_str(engine, path, options) { Ok(db) => Some(db), Err(err) => { eprintln!("{}", err); diff --git a/cozo-lib-wasm/Cargo.toml b/cozo-lib-wasm/Cargo.toml index f9b3d3f8..89252a00 100644 --- a/cozo-lib-wasm/Cargo.toml +++ b/cozo-lib-wasm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cozo-lib-wasm" -version = "0.2.0" +version = "0.2.1" edition = "2021" description = "Cozo database for WASM" authors = ["Ziyang Hu"] @@ -17,7 +17,7 @@ default = ["console_error_panic_hook"] [dependencies] wasm-bindgen = "0.2.63" -cozo = { version = "0.2.0", path = "../cozo-core", default-features = false, features = ["wasm", "graph-algo", "nothread"] } +cozo = { version = "0.2.1", path = "../cozo-core", default-features = false, features = ["wasm", "graph-algo", "nothread"] } # The `console_error_panic_hook` crate provides better debugging of panics by # logging them with `console.error`. This is great for development, but requires diff --git a/cozo-lib-wasm/src/lib.rs b/cozo-lib-wasm/src/lib.rs index 059553dd..0d6826b6 100644 --- a/cozo-lib-wasm/src/lib.rs +++ b/cozo-lib-wasm/src/lib.rs @@ -32,7 +32,7 @@ pub struct CozoDb { impl CozoDb { pub fn new() -> Self { utils::set_panic_hook(); - let db = DbInstance::new("mem", "", Default::default()).unwrap(); + let db = DbInstance::new("mem", "", "").unwrap(); Self { db } } pub fn run(&self, script: &str, params: &str) -> String { diff --git a/cozoserver/Cargo.toml b/cozoserver/Cargo.toml index 8b351428..22d34350 100644 --- a/cozoserver/Cargo.toml +++ b/cozoserver/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cozoserver" -version = "0.2.0" +version = "0.2.1" edition = "2021" license = "MPL-2.0" description = "Standalone Cozo database" @@ -46,7 +46,7 @@ storage-tikv = ["cozo/storage-tikv"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cozo = { version = "0.2.0", path = "../cozo-core", default-features = false } +cozo = { version = "0.2.1", path = "../cozo-core", default-features = false } clap = { version = "4.0.26", features = ["derive"] } rouille = "3.5.0" env_logger = "0.9.3" diff --git a/cozoserver/src/main.rs b/cozoserver/src/main.rs index c0114c75..bdfb5e9e 100644 --- a/cozoserver/src/main.rs +++ b/cozoserver/src/main.rs @@ -24,9 +24,9 @@ use cozo::*; #[derive(Parser, Debug)] #[clap(version, about, long_about = None)] struct Args { - /// Database kind, can be `mem`, `sqlite`, `rocksdb` and others. + /// Database engine, can be `mem`, `sqlite`, `rocksdb` and others. #[clap(short, long, default_value_t = String::from("mem"))] - kind: String, + engine: String, /// Path to the directory to store the database #[clap(short, long, default_value_t = String::from("cozo.db"))] @@ -69,13 +69,13 @@ fn main() { eprintln!("{}", SECURITY_WARNING); } - let db = DbInstance::new(args.kind.as_str(), args.path.as_str(), &args.config.clone()).unwrap(); + let db = DbInstance::new(args.engine.as_str(), args.path.as_str(), &args.config.clone()).unwrap(); if let Some(restore_path) = &args.restore { db.restore_backup(restore_path).unwrap(); } - let conf_path = format!("{}.{}.cozo_auth", args.path, args.kind); + let conf_path = format!("{}.{}.cozo_auth", args.path, args.engine); let auth_guard = match fs::read_to_string(&conf_path) { Ok(s) => s.trim().to_string(), Err(_) => { @@ -96,7 +96,7 @@ fn main() { }; println!( "Database ({} backend) web API running at http://{}", - args.kind, addr + args.engine, addr ); println!("The auth file is at {}", conf_path); rouille::start_server(addr, move |request| {