diff --git a/.gitignore b/.gitignore index dab3949d..3be503c9 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ target/ !/examples/greeting/artifacts/*.wasm !/examples/ipfs_node/artifacts/*.wasm !/examples/records/artifacts/*.wasm +!/examples/sqlite/artifacts/sqlite_test.wasm # Allowed Wasm files for test !/fluence-faas/tests/json_wasm_tests/arguments_passing/artifacts/effector.wasm diff --git a/Cargo.lock b/Cargo.lock index 39dbd8b5..bba1b121 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,7 +43,7 @@ checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b" name = "arguments-passing-test" version = "0.1.0" dependencies = [ - "fluence", + "fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)", "safe-transmute", ] @@ -166,7 +166,7 @@ checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" name = "call_parameters" version = "0.1.0" dependencies = [ - "fluence", + "fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)", ] [[package]] @@ -375,7 +375,7 @@ dependencies = [ name = "curl" version = "0.1.0" dependencies = [ - "fluence", + "fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)", "log", ] @@ -619,6 +619,15 @@ dependencies = [ "wasmer-wasi-fl", ] +[[package]] +name = "fce-sqlite-connector" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3931a7a9f133e94246ff2c36a14b66d3ea16e8460e715b982bd8974e56151b7b" +dependencies = [ + "fluence 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "fce-wit-generator" version = "0.1.6" @@ -673,6 +682,16 @@ dependencies = [ "fluence-sdk-main 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)", ] +[[package]] +name = "fluence" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47a382fa3506247e84d799645523c56ebfcb4cdefb45671dd31f8664cfc86007" +dependencies = [ + "fluence-sdk-macro 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fluence-sdk-main 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "fluence-app-service" version = "0.1.6" @@ -1106,7 +1125,7 @@ dependencies = [ name = "inner-records-test" version = "0.1.0" dependencies = [ - "fluence", + "fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)", "safe-transmute", ] @@ -1145,7 +1164,7 @@ dependencies = [ name = "ipfs-effector" version = "0.1.0" dependencies = [ - "fluence", + "fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)", "log", ] @@ -1153,7 +1172,7 @@ dependencies = [ name = "ipfs-pure" version = "0.1.0" dependencies = [ - "fluence", + "fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)", "log", ] @@ -1232,7 +1251,7 @@ checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235" name = "local_storage" version = "0.1.0" dependencies = [ - "fluence", + "fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)", "log", ] @@ -1721,7 +1740,7 @@ dependencies = [ name = "record-effector" version = "0.1.0" dependencies = [ - "fluence", + "fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)", "test-record", ] @@ -1729,7 +1748,7 @@ dependencies = [ name = "record-pure" version = "0.1.0" dependencies = [ - "fluence", + "fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)", "test-record", ] @@ -2014,7 +2033,7 @@ name = "site-storage" version = "0.1.0" dependencies = [ "anyhow", - "fluence", + "fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)", "log", ] @@ -2158,7 +2177,7 @@ dependencies = [ name = "test-record" version = "0.1.0" dependencies = [ - "fluence", + "fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)", ] [[package]] @@ -2593,7 +2612,15 @@ checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307" name = "wasm-greeting" version = "0.1.0" dependencies = [ - "fluence", + "fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)", +] + +[[package]] +name = "wasm-sqlite-test" +version = "0.1.0" +dependencies = [ + "fce-sqlite-connector", + "fluence 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a55a3a8e..0729652c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ members = [ "crates/wit-interfaces", "crates/wit-parser", "engine", + "examples/call_parameters", "examples/greeting", "examples/ipfs-node/effector", "examples/ipfs-node/pure", @@ -13,7 +14,7 @@ members = [ "examples/site-storage/site-storage", "examples/site-storage/curl", "examples/site-storage/local_storage", - "examples/call_parameters", + "examples/sqlite", "fluence-app-service", "fluence-faas", "fluence-faas/tests/json_wasm_tests/arguments_passing", diff --git a/engine/src/module/type_converters.rs b/engine/src/module/type_converters.rs index f9ae60cd..6c1a1730 100644 --- a/engine/src/module/type_converters.rs +++ b/engine/src/module/type_converters.rs @@ -44,7 +44,7 @@ pub(super) fn itype_to_wtype(ty: &IType) -> WType { ty => { eprintln!("trying to convert {:?}", ty); unimplemented!() - }, + } } } diff --git a/examples/sqlite/Cargo.toml b/examples/sqlite/Cargo.toml new file mode 100644 index 00000000..f6ddd7d9 --- /dev/null +++ b/examples/sqlite/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "wasm-sqlite-test" +version = "0.1.0" +authors = ["Fluence Labs"] +edition = "2018" + +[[bin]] +name = "sqlite_test" +path = "src/main.rs" + +[dependencies] +fluence = "0.2.3" +fce-sqlite-connector = "0.1.0" diff --git a/examples/sqlite/Config.toml b/examples/sqlite/Config.toml new file mode 100644 index 00000000..4274a1f5 --- /dev/null +++ b/examples/sqlite/Config.toml @@ -0,0 +1,11 @@ +modules_dir = "artifacts/" + +[[module]] + name = "sqlite3" + mem_pages_count = 100 + logger_enabled = false + +[[module]] +name = "sqlite_test" + mem_pages_count = 1 + logger_enabled = false diff --git a/examples/sqlite/artifacts/sqlite_test.wasm b/examples/sqlite/artifacts/sqlite_test.wasm new file mode 100755 index 00000000..0d280b82 Binary files /dev/null and b/examples/sqlite/artifacts/sqlite_test.wasm differ diff --git a/examples/sqlite/build.sh b/examples/sqlite/build.sh new file mode 100755 index 00000000..60e5c938 --- /dev/null +++ b/examples/sqlite/build.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +# This script builds all subprojects and puts all created Wasm modules in one dir +cargo update +fce build --release + +rm artifacts/* +cp ../../target/wasm32-wasi/release/sqlite_test.wasm artifacts/ +wget https://github.com/fluencelabs/sqlite/releases/download/v0.7.0_w/sqlite3.wasm +mv sqlite3.wasm artifacts/ diff --git a/examples/sqlite/src/main.rs b/examples/sqlite/src/main.rs new file mode 100644 index 00000000..50b86fac --- /dev/null +++ b/examples/sqlite/src/main.rs @@ -0,0 +1,76 @@ +/* + * Copyright 2020 Fluence Labs Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +use fluence::fce; +use fce_sqlite_connector; +use fce_sqlite_connector::State; + +pub fn main() {} + +#[fce] +pub fn test1() { + let connection = fce_sqlite_connector::open(":memory:").unwrap(); + + connection + .execute( + " + CREATE TABLE users (name TEXT, age INTEGER); + INSERT INTO users VALUES ('Alice', 42); + INSERT INTO users VALUES ('Bob', 69); + ", + ) + .unwrap(); + + let mut statement = connection + .prepare("SELECT * FROM users WHERE age > ?") + .unwrap(); + + statement.bind(1, 50).unwrap(); + + while let State::Row = statement.next().unwrap() { + println!("name = {}", statement.read::(0).unwrap()); + println!("age = {}", statement.read::(1).unwrap()); + } +} + +#[fce] +pub fn test2() { + use fce_sqlite_connector::Value; + + let connection = fce_sqlite_connector::open(":memory:").unwrap(); + + connection + .execute( + " + CREATE TABLE users (name TEXT, age INTEGER); + INSERT INTO users VALUES ('Alice', 42); + INSERT INTO users VALUES ('Bob', 69); + ", + ) + .unwrap(); + + let mut cursor = connection + .prepare("SELECT * FROM users WHERE age > ?") + .unwrap() + .cursor(); + + cursor.bind(&[Value::Integer(50)]).unwrap(); + + while let Some(row) = cursor.next().unwrap() { + println!("name = {}", row[0].as_string().unwrap()); + println!("age = {}", row[1].as_integer().unwrap()); + } +}