Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion db/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn escape_string_for_pragma(s: &str) -> String {
s.replace("'", "''")
}

fn make_connection(uri: &Path, maybe_encryption_key: Option<&str>) -> rusqlite::Result<rusqlite::Connection> {
pub fn make_connection(uri: &Path, maybe_encryption_key: Option<&str>) -> rusqlite::Result<rusqlite::Connection> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thom didn't make this public for a reason. We should be feature-checking sqlcipher in Store and Stores to handle this, I think.

let conn = match uri.to_string_lossy().len() {
0 => rusqlite::Connection::open_in_memory()?,
_ => rusqlite::Connection::open(uri)?,
Expand Down
1 change: 1 addition & 0 deletions db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub use entids::{
pub use db::{
TypedSQLValue,
new_connection,
make_connection,
};

#[cfg(feature = "sqlcipher")]
Expand Down
11 changes: 9 additions & 2 deletions ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ pub use mentat::{
QueryResults,
RelResult,
Store,
Stores,
Syncable,
TypedValue,
TxObserver,
Expand Down Expand Up @@ -220,7 +221,14 @@ pub unsafe extern "C" fn store_open(uri: *const c_char, error: *mut ExternError)
pub unsafe extern "C" fn store_open_encrypted(uri: *const c_char, key: *const c_char, error: *mut ExternError) -> *mut Store {
let uri = c_char_to_string(uri);
let key = c_char_to_string(key);
translate_result(Store::open_with_key(&uri, &key), error)
translate_result(Stores::open_with_key(&uri, &key), error)
}

/// Variant of store_open that opens a named in-memory database.
#[no_mangle]
pub unsafe extern "C" fn store_open_named_in_memory_store(name: *const c_char, error: *mut ExternError) -> *mut Store {
let name = c_char_to_string(name);
translate_result(Stores::open_named_in_memory_store(name), error)
}

// TODO: open empty
Expand Down Expand Up @@ -1556,7 +1564,6 @@ pub unsafe extern "C" fn typed_value_into_long(typed_value: *mut Binding) -> c_l
pub unsafe extern "C" fn typed_value_into_entid(typed_value: *mut Binding) -> Entid {
assert_not_null!(typed_value);
let typed_value = Box::from_raw(typed_value);
println!("typed value as entid {:?}", typed_value);
unwrap_conversion(typed_value.into_entid(), ValueType::Ref)
}

Expand Down
11 changes: 10 additions & 1 deletion public-traits/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#![allow(dead_code)]

use std; // To refer to std::result::Result.

use std::collections::BTreeSet;
use std::path::PathBuf;

use rusqlite;

Expand Down Expand Up @@ -87,6 +87,15 @@ pub enum MentatError {
#[fail(display = "provided value of type {} doesn't match attribute value type {}", _0, _1)]
ValueTypeMismatch(ValueType, ValueType),

#[fail(display = "Cannot open store {} at path {:?} as it does not match previous store location {:?}", _0, _1, _2)]
StorePathMismatch(String, PathBuf, PathBuf),

#[fail(display = "The Store at {} does not exist or is not yet open.", _0)]
StoreNotFound(String),

#[fail(display = "The Store at {:?} has active connections and cannot be closed.", _0)]
StoresLockPoisoned(String),

#[fail(display = "{}", _0)]
IoError(#[cause] std::io::Error),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class InProgressBuilder extends PointerType {}
class EntityBuilder extends PointerType {}

Store store_open(String dbPath, RustError.ByReference err);
Store store_open_named_in_memory_store(String name, RustError.ByReference err);

void destroy(Pointer obj);
void uuid_destroy(Pointer obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Mentat extends RustObject<JNA.Store> {
private Mentat(JNA.Store rawPointer) { super(rawPointer); }

/**
* Open a connection to an in-memory Mentat Store.
* Open a connection to an anonymous in-memory Store.
*/
public static Mentat open() {
return open("");
Expand All @@ -51,6 +51,16 @@ public static Mentat open(String dbPath) {
return new Mentat(store);
}

/**
* Open a connection to a named in-memory Store.
* @param name The named to be given to the in memory store to open.
* @return An instance of Mentat connected to a named in memory store.
*/
public static Mentat namedInMemoryStore(String name) {
RustError.ByReference err = new RustError.ByReference();
return new Mentat(JNA.INSTANCE.store_open_named_in_memory_store(name, err));
}

/**
* Add an attribute to the cache. The {@link CacheDirection} determines how that attribute can be
* looked up.
Expand Down
Loading