mirror of
https://github.com/fluencelabs/sqlite-wasm-connector
synced 2025-03-14 22:10:49 +00:00
Merge pull request #10 from fluencelabs/feat/move-set-heap-limit-from-connection
At the moment, soft_heap_limit64 is exported from Connection, although it doesn't really belong to Connection since it sets limit globally for SQLite instance, not as per connection.
This commit is contained in:
commit
69e3f8f7a4
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "marine-sqlite-connector"
|
||||
version = "0.7.0"
|
||||
version = "0.8.0"
|
||||
license = "Apache-2.0/MIT"
|
||||
authors = [
|
||||
"Daniel Dulaney <ddy@vitronic.com>",
|
||||
@ -37,7 +37,8 @@ path = "src/test.rs"
|
||||
|
||||
[dependencies]
|
||||
marine-rs-sdk = "0.7.0"
|
||||
bytesize = "1.2.0"
|
||||
|
||||
[dev-dependencies]
|
||||
temporary = "0.6"
|
||||
marine-rs-sdk-test = "0.2.0"
|
||||
temporary = "0.6"
|
||||
|
@ -55,10 +55,6 @@ impl Connection {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_memory_limit(limit: i64) -> i64 {
|
||||
unsafe { ffi::sqlite3_hard_heap_limit64(limit) }
|
||||
}
|
||||
|
||||
/// Execute a statement without processing the resulting rows if any.
|
||||
#[inline]
|
||||
pub fn execute<T: AsRef<str>>(&self, statement: T) -> Result<()> {
|
||||
|
21
src/lib.rs
21
src/lib.rs
@ -304,3 +304,24 @@ fn last_error(raw: ffi::Sqlite3DbHandle) -> Option<Error> {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// From the SQLite docs:
|
||||
///
|
||||
/// The sqlite3_soft_heap_limit64() interface sets and/or queries the soft limit on the amount of
|
||||
/// heap memory that may be allocated by SQLite. SQLite strives to keep heap memory utilization
|
||||
/// below the soft heap limit by reducing the number of pages held in the page cache as heap memory
|
||||
/// usages approaches the limit. The soft heap limit is "soft" because even though SQLite strives
|
||||
/// to stay below the limit, it will exceed the limit rather than generate an SQLITE_NOMEM error.
|
||||
/// In other words, the soft heap limit is advisory only.
|
||||
pub fn soft_soft_heap_limit64(limit: i64) -> i64 {
|
||||
unsafe { ffi::sqlite3_soft_heap_limit64(limit) }
|
||||
}
|
||||
|
||||
/// From the SQLite docs:
|
||||
///
|
||||
/// This interface sets a hard upper bound of N bytes on the amount of memory that will be
|
||||
/// allocated. The set_hard_heap_limit64 interface is similar to soft_heap_limit64
|
||||
/// except that memory allocations will fail when the hard heap limit is reached.
|
||||
pub fn set_hard_heap_limit64(limit: i64) -> i64 {
|
||||
unsafe { ffi::sqlite3_hard_heap_limit64(limit) }
|
||||
}
|
||||
|
39
src/test.rs
39
src/test.rs
@ -1,5 +1,5 @@
|
||||
use marine_rs_sdk::marine;
|
||||
use marine_sqlite_connector::{version, State, Value};
|
||||
use marine_sqlite_connector::{version, Connection, State, Value};
|
||||
|
||||
pub fn main() {}
|
||||
|
||||
@ -648,3 +648,40 @@ pub fn test12() {
|
||||
assert_eq!(row[4].as_string().unwrap(), "UPDATE");
|
||||
}
|
||||
}
|
||||
|
||||
#[marine]
|
||||
pub fn test13() {
|
||||
fn insert_data(connection: &Connection) -> marine_sqlite_connector::Result<()> {
|
||||
connection
|
||||
.execute("INSERT INTO email VALUES ('Alice', 'How deep is the hole', 'Nobody knows')")
|
||||
}
|
||||
|
||||
let connection = marine_sqlite_connector::open(":memory:").unwrap();
|
||||
|
||||
connection
|
||||
.execute(
|
||||
"
|
||||
CREATE TABLE email(sender, subject, body);
|
||||
",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
for _ in 0..10 {
|
||||
let insert_result = insert_data(&connection);
|
||||
assert!(insert_result.is_ok());
|
||||
}
|
||||
|
||||
marine_sqlite_connector::set_hard_heap_limit64(bytesize::KB as i64);
|
||||
|
||||
for _ in 0..10 {
|
||||
let insert_result = insert_data(&connection);
|
||||
assert!(insert_result.is_err());
|
||||
}
|
||||
|
||||
marine_sqlite_connector::set_hard_heap_limit64(bytesize::MB as i64);
|
||||
|
||||
for _ in 0..10 {
|
||||
let insert_result = insert_data(&connection);
|
||||
assert!(insert_result.is_ok());
|
||||
}
|
||||
}
|
||||
|
@ -76,4 +76,9 @@ mod tests {
|
||||
fn test12(test: marine_test_env::test::ModuleInterface) {
|
||||
test.test12()
|
||||
}
|
||||
|
||||
#[marine_test(config_path = "../Config.toml", modules_dir = "../artifacts/")]
|
||||
fn test13(test: marine_test_env::test::ModuleInterface) {
|
||||
test.test13()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user