bump version and update API

main
Ziyang Hu 2 years ago
parent 6673bc5931
commit 8f2e918f91

16
Cargo.lock generated

@ -492,7 +492,7 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
[[package]] [[package]]
name = "cozo" name = "cozo"
version = "0.2.0" version = "0.2.1"
dependencies = [ dependencies = [
"approx", "approx",
"base64", "base64",
@ -541,7 +541,7 @@ dependencies = [
[[package]] [[package]]
name = "cozo-lib-wasm" name = "cozo-lib-wasm"
version = "0.2.0" version = "0.2.1"
dependencies = [ dependencies = [
"console_error_panic_hook", "console_error_panic_hook",
"cozo", "cozo",
@ -552,7 +552,7 @@ dependencies = [
[[package]] [[package]]
name = "cozo-node" name = "cozo-node"
version = "0.2.0" version = "0.2.1"
dependencies = [ dependencies = [
"cozo", "cozo",
"lazy_static", "lazy_static",
@ -561,7 +561,7 @@ dependencies = [
[[package]] [[package]]
name = "cozo-swift" name = "cozo-swift"
version = "0.2.0" version = "0.2.1"
dependencies = [ dependencies = [
"cozo", "cozo",
"swift-bridge", "swift-bridge",
@ -570,7 +570,7 @@ dependencies = [
[[package]] [[package]]
name = "cozo_c" name = "cozo_c"
version = "0.2.0" version = "0.2.1"
dependencies = [ dependencies = [
"cbindgen", "cbindgen",
"cozo", "cozo",
@ -579,7 +579,7 @@ dependencies = [
[[package]] [[package]]
name = "cozo_java" name = "cozo_java"
version = "0.2.0" version = "0.2.1"
dependencies = [ dependencies = [
"cozo", "cozo",
"jni", "jni",
@ -588,7 +588,7 @@ dependencies = [
[[package]] [[package]]
name = "cozo_py" name = "cozo_py"
version = "0.2.0" version = "0.2.1"
dependencies = [ dependencies = [
"cozo", "cozo",
"pyo3", "pyo3",
@ -611,7 +611,7 @@ dependencies = [
[[package]] [[package]]
name = "cozoserver" name = "cozoserver"
version = "0.2.0" version = "0.2.1"
dependencies = [ dependencies = [
"chrono", "chrono",
"clap 4.0.26", "clap 4.0.26",

@ -1 +1 @@
0.2.0 0.2.1

@ -1,6 +1,6 @@
[package] [package]
name = "cozo" name = "cozo"
version = "0.2.0" version = "0.2.1"
edition = "2021" edition = "2021"
description = "A general-purpose, transactional, relational database that uses Datalog and focuses on graph data and algorithms" description = "A general-purpose, transactional, relational database that uses Datalog and focuses on graph data and algorithms"
authors = ["Ziyang Hu"] authors = ["Ziyang Hu"]

@ -98,7 +98,7 @@ pub enum DbInstance {
impl DbInstance { impl DbInstance {
/// Create a DbInstance, which is a dispatcher for various concrete implementations. /// Create a DbInstance, which is a dispatcher for various concrete implementations.
/// The valid kinds are: /// The valid engines are:
/// ///
/// * `mem` /// * `mem`
/// * `sqlite` /// * `sqlite`
@ -107,14 +107,14 @@ impl DbInstance {
/// * `tikv` /// * `tikv`
/// ///
/// assuming all features are enabled during compilation. Otherwise only /// 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. /// `path` is ignored for `mem` and `tikv` engines.
/// `options` is ignored for every kind except `tikv`. /// `options` is ignored for every engine except `tikv`.
#[allow(unused_variables)] #[allow(unused_variables)]
pub fn new(kind: &str, path: &str, options: &str) -> Result<Self> { pub fn new(engine: &str, path: &str, options: &str) -> Result<Self> {
let options = if options.is_empty() { "{}" } else { options }; let options = if options.is_empty() { "{}" } else { options };
Ok(match kind { Ok(match engine {
"mem" => Self::Mem(new_cozo_mem()?), "mem" => Self::Mem(new_cozo_mem()?),
#[cfg(feature = "storage-sqlite")] #[cfg(feature = "storage-sqlite")]
"sqlite" => Self::Sqlite(new_cozo_sqlite(path.to_string())?), "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()?; let opts: TiKvOpts = serde_json::from_str(options).into_diagnostic()?;
Self::TiKv(new_cozo_tikv(opts.end_points.clone(), opts.optimistic)?) Self::TiKv(new_cozo_tikv(opts.end_points.clone(), opts.optimistic)?)
} }
kind => bail!( k => bail!(
"database kind '{}' not supported (maybe not compiled in)", "database engine '{}' not supported (maybe not compiled in)",
kind k
), ),
}) })
} }
/// Same as [Self::new], but inputs and error messages are all in strings /// Same as [Self::new], but inputs and error messages are all in strings
pub fn new_with_str( pub fn new_with_str(
kind: &str, engine: &str,
path: &str, path: &str,
options: &str, options: &str,
) -> std::result::Result<Self, String> { ) -> std::result::Result<Self, String> {
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]. /// Dispatcher method. See [crate::Db::run_script].
pub fn run_script( pub fn run_script(

@ -25,7 +25,7 @@ lazy_static! {
let path = "_test_air_routes"; let path = "_test_air_routes";
_ = std::fs::remove_file(path); _ = std::fs::remove_file(path);
_ = std::fs::remove_dir_all(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(); let db = DbInstance::new(&db_kind, path, Default::default()).unwrap();
dbg!(creation.elapsed()); dbg!(creation.elapsed());

@ -1,6 +1,6 @@
[package] [package]
name = "cozo_c" name = "cozo_c"
version = "0.2.0" version = "0.2.1"
edition = "2021" edition = "2021"
license = "MPL-2.0" license = "MPL-2.0"
homepage = "https://github.com/cozodb/cozo" 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 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [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" lazy_static = "1.4.0"
[build-dependencies] [build-dependencies]

@ -17,15 +17,16 @@ extern "C" {
/** /**
* Open a database. * Open a database.
* *
* `engine`: Which storage engine to use, can be "mem", "sqlite" or "rocksdb". * `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. * `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. * `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, * When the function is successful, null pointer is returned,
* otherwise a pointer to a C-string containing the error message will be 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`. * 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. * Close a database.

@ -31,9 +31,10 @@ lazy_static! {
/// Open a database. /// Open a database.
/// ///
/// `engine`: Which storage engine to use, can be "mem", "sqlite" or "rocksdb". /// `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. /// `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. /// `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, /// When the function is successful, null pointer is returned,
/// otherwise a pointer to a C-string containing the error message will be 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( pub unsafe extern "C" fn cozo_open_db(
engine: *const c_char, engine: *const c_char,
path: *const c_char, path: *const c_char,
options: *const c_char,
db_id: &mut i32, db_id: &mut i32,
) -> *mut c_char { ) -> *mut c_char {
let engine = match CStr::from_ptr(engine).to_str() { 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(), 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, Ok(db) => db,
Err(err) => return CString::new(err).unwrap().into_raw(), Err(err) => return CString::new(err).unwrap().into_raw(),
}; };

@ -1,6 +1,6 @@
[package] [package]
name = "cozo_java" name = "cozo_java"
version = "0.2.0" version = "0.2.1"
edition = "2021" edition = "2021"
license = "MPL-2.0" license = "MPL-2.0"
homepage = "https://github.com/cozodb/cozo" homepage = "https://github.com/cozodb/cozo"
@ -21,5 +21,5 @@ io-uring = ["cozo/io-uring"]
[dependencies] [dependencies]
jni = "0.20.0" jni = "0.20.0"
# , features = ["compact"] # , 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" lazy_static = "1.4.0"

@ -1,7 +1,7 @@
package org.cozodb; package org.cozodb;
public class CozoJavaBridge { 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 boolean closeDb(int id);
private static native String runQuery(int id, String script, String params); private static native String runQuery(int id, String script, String params);
private static native String exportRelations(int id, String rel); private static native String exportRelations(int id, String rel);

@ -10,10 +10,10 @@ extern "C" {
/* /*
* Class: org_cozodb_CozoJavaBridge * Class: org_cozodb_CozoJavaBridge
* Method: openDb * 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 JNIEXPORT jint JNICALL Java_org_cozodb_CozoJavaBridge_openDb
(JNIEnv *, jclass, jstring, jstring); (JNIEnv *, jclass, jstring, jstring, jstring);
/* /*
* Class: org_cozodb_CozoJavaBridge * Class: org_cozodb_CozoJavaBridge

@ -38,12 +38,14 @@ fn get_db(id: i32) -> Option<DbInstance> {
pub extern "system" fn Java_org_cozodb_CozoJavaBridge_openDb( pub extern "system" fn Java_org_cozodb_CozoJavaBridge_openDb(
env: JNIEnv, env: JNIEnv,
_class: JClass, _class: JClass,
kind: JString, engine: JString,
path: JString, path: JString,
options: JString,
) -> jint { ) -> 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 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) => { Ok(db) => {
let id = HANDLES.current.fetch_add(1, Ordering::AcqRel); let id = HANDLES.current.fetch_add(1, Ordering::AcqRel);
let mut dbs = HANDLES.dbs.lock().unwrap(); let mut dbs = HANDLES.dbs.lock().unwrap();

@ -1,6 +1,6 @@
[package] [package]
name = "cozo-node" name = "cozo-node"
version = "0.2.0" version = "0.2.1"
description = "Cozo database for NodeJS" description = "Cozo database for NodeJS"
authors = ["Ziyang Hu"] authors = ["Ziyang Hu"]
license = "MPL-2.0" 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 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [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" lazy_static = "1.4.0"
[dependencies.neon] [dependencies.neon]

@ -25,9 +25,10 @@ lazy_static! {
} }
fn open_db(mut cx: FunctionContext) -> JsResult<JsNumber> { fn open_db(mut cx: FunctionContext) -> JsResult<JsNumber> {
let kind = cx.argument::<JsString>(0)?.value(&mut cx); let engine = cx.argument::<JsString>(0)?.value(&mut cx);
let path = cx.argument::<JsString>(1)?.value(&mut cx); let path = cx.argument::<JsString>(1)?.value(&mut cx);
match DbInstance::new(&kind, &path, Default::default()) { let options = cx.argument::<JsString>(2)?.value(&mut cx);
match DbInstance::new(&engine, &path, &options) {
Ok(db) => { Ok(db) => {
let id = HANDLES.current.fetch_add(1, Ordering::AcqRel); let id = HANDLES.current.fetch_add(1, Ordering::AcqRel);
let mut dbs = HANDLES.dbs.lock().unwrap(); let mut dbs = HANDLES.dbs.lock().unwrap();

@ -1,6 +1,6 @@
[package] [package]
name = "cozo_py" name = "cozo_py"
version = "0.2.0" version = "0.2.1"
edition = "2021" edition = "2021"
description = "Cozo database for python" description = "Cozo database for python"
authors = ["Ziyang Hu"] authors = ["Ziyang Hu"]
@ -45,5 +45,5 @@ nothread = ["cozo/nothread"]
[dependencies] [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"] } pyo3 = { version = "0.17.1", features = ["extension-module", "abi3", "abi3-py37"] }

@ -21,8 +21,8 @@ const DB_CLOSED_MSG: &str = r##"{"ok":false,"message":"database closed"}"##;
#[pymethods] #[pymethods]
impl CozoDbPy { impl CozoDbPy {
#[new] #[new]
fn new(kind: &str, path: &str) -> PyResult<Self> { fn new(engine: &str, path: &str, options: &str) -> PyResult<Self> {
match DbInstance::new(kind, path, Default::default()) { match DbInstance::new(engine, path, options) {
Ok(db) => Ok(Self { db: Some(db) }), Ok(db) => Ok(Self { db: Some(db) }),
Err(err) => Err(PyException::new_err(format!("{:?}", err))), Err(err) => Err(PyException::new_err(format!("{:?}", err))),
} }

@ -1,6 +1,6 @@
[package] [package]
name = "cozo-swift" name = "cozo-swift"
version = "0.2.0" version = "0.2.1"
edition = "2021" edition = "2021"
description = "Cozo database for Swift" description = "Cozo database for Swift"
authors = ["Ziyang Hu"] authors = ["Ziyang Hu"]
@ -23,5 +23,5 @@ io-uring = ["cozo/io-uring"]
swift-bridge-build = "0.1.41" swift-bridge-build = "0.1.41"
[dependencies] [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" swift-bridge = "0.1.41"

@ -13,7 +13,7 @@ mod ffi {
extern "Rust" { extern "Rust" {
type DbInstance; type DbInstance;
fn new_db(kind: &str, path: &str, options: &str) -> Option<DbInstance>; fn new_db(engine: &str, path: &str, options: &str) -> Option<DbInstance>;
#[swift_bridge(associated_to = DbInstance)] #[swift_bridge(associated_to = DbInstance)]
fn run_script_str(&self, payload: &str, params: &str) -> String; 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<DbInstance> { fn new_db(engine: &str, path: &str, options: &str) -> Option<DbInstance> {
let options = if options.is_empty() { "{}" } else { options }; 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), Ok(db) => Some(db),
Err(err) => { Err(err) => {
eprintln!("{}", err); eprintln!("{}", err);

@ -1,6 +1,6 @@
[package] [package]
name = "cozo-lib-wasm" name = "cozo-lib-wasm"
version = "0.2.0" version = "0.2.1"
edition = "2021" edition = "2021"
description = "Cozo database for WASM" description = "Cozo database for WASM"
authors = ["Ziyang Hu"] authors = ["Ziyang Hu"]
@ -17,7 +17,7 @@ default = ["console_error_panic_hook"]
[dependencies] [dependencies]
wasm-bindgen = "0.2.63" 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 # The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires # logging them with `console.error`. This is great for development, but requires

@ -32,7 +32,7 @@ pub struct CozoDb {
impl CozoDb { impl CozoDb {
pub fn new() -> Self { pub fn new() -> Self {
utils::set_panic_hook(); utils::set_panic_hook();
let db = DbInstance::new("mem", "", Default::default()).unwrap(); let db = DbInstance::new("mem", "", "").unwrap();
Self { db } Self { db }
} }
pub fn run(&self, script: &str, params: &str) -> String { pub fn run(&self, script: &str, params: &str) -> String {

@ -1,6 +1,6 @@
[package] [package]
name = "cozoserver" name = "cozoserver"
version = "0.2.0" version = "0.2.1"
edition = "2021" edition = "2021"
license = "MPL-2.0" license = "MPL-2.0"
description = "Standalone Cozo database" 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 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [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"] } clap = { version = "4.0.26", features = ["derive"] }
rouille = "3.5.0" rouille = "3.5.0"
env_logger = "0.9.3" env_logger = "0.9.3"

@ -24,9 +24,9 @@ use cozo::*;
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[clap(version, about, long_about = None)] #[clap(version, about, long_about = None)]
struct Args { 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"))] #[clap(short, long, default_value_t = String::from("mem"))]
kind: String, engine: String,
/// Path to the directory to store the database /// Path to the directory to store the database
#[clap(short, long, default_value_t = String::from("cozo.db"))] #[clap(short, long, default_value_t = String::from("cozo.db"))]
@ -69,13 +69,13 @@ fn main() {
eprintln!("{}", SECURITY_WARNING); 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 { if let Some(restore_path) = &args.restore {
db.restore_backup(restore_path).unwrap(); 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) { let auth_guard = match fs::read_to_string(&conf_path) {
Ok(s) => s.trim().to_string(), Ok(s) => s.trim().to_string(),
Err(_) => { Err(_) => {
@ -96,7 +96,7 @@ fn main() {
}; };
println!( println!(
"Database ({} backend) web API running at http://{}", "Database ({} backend) web API running at http://{}",
args.kind, addr args.engine, addr
); );
println!("The auth file is at {}", conf_path); println!("The auth file is at {}", conf_path);
rouille::start_server(addr, move |request| { rouille::start_server(addr, move |request| {

Loading…
Cancel
Save