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]]
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",

@ -1 +1 @@
0.2.0
0.2.1

@ -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"]

@ -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<Self> {
pub fn new(engine: &str, path: &str, options: &str) -> Result<Self> {
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, 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].
pub fn run_script(

@ -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());

@ -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]

@ -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.

@ -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(),
};

@ -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"

@ -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);

@ -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

@ -38,12 +38,14 @@ fn get_db(id: i32) -> Option<DbInstance> {
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();

@ -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]

@ -25,9 +25,10 @@ lazy_static! {
}
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);
match DbInstance::new(&kind, &path, Default::default()) {
let options = cx.argument::<JsString>(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();

@ -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"] }

@ -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<Self> {
match DbInstance::new(kind, path, Default::default()) {
fn new(engine: &str, path: &str, options: &str) -> PyResult<Self> {
match DbInstance::new(engine, path, options) {
Ok(db) => Ok(Self { db: Some(db) }),
Err(err) => Err(PyException::new_err(format!("{:?}", err))),
}

@ -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"

@ -13,7 +13,7 @@ mod ffi {
extern "Rust" {
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)]
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 };
match DbInstance::new_with_str(kind, path, options) {
match DbInstance::new_with_str(engine, path, options) {
Ok(db) => Some(db),
Err(err) => {
eprintln!("{}", err);

@ -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

@ -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 {

@ -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"

@ -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| {

Loading…
Cancel
Save