mirror of
https://github.com/fluencelabs/marine.git
synced 2024-12-12 06:45:32 +00:00
add sqlite example
This commit is contained in:
parent
ba13ba360f
commit
8296486eaa
1
.gitignore
vendored
1
.gitignore
vendored
@ -16,6 +16,7 @@ target/
|
|||||||
!/examples/greeting/artifacts/*.wasm
|
!/examples/greeting/artifacts/*.wasm
|
||||||
!/examples/ipfs_node/artifacts/*.wasm
|
!/examples/ipfs_node/artifacts/*.wasm
|
||||||
!/examples/records/artifacts/*.wasm
|
!/examples/records/artifacts/*.wasm
|
||||||
|
!/examples/sqlite/artifacts/sqlite_test.wasm
|
||||||
|
|
||||||
# Allowed Wasm files for test
|
# Allowed Wasm files for test
|
||||||
!/fluence-faas/tests/json_wasm_tests/arguments_passing/artifacts/effector.wasm
|
!/fluence-faas/tests/json_wasm_tests/arguments_passing/artifacts/effector.wasm
|
||||||
|
51
Cargo.lock
generated
51
Cargo.lock
generated
@ -43,7 +43,7 @@ checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b"
|
|||||||
name = "arguments-passing-test"
|
name = "arguments-passing-test"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence",
|
"fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||||
"safe-transmute",
|
"safe-transmute",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38"
|
|||||||
name = "call_parameters"
|
name = "call_parameters"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence",
|
"fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -375,7 +375,7 @@ dependencies = [
|
|||||||
name = "curl"
|
name = "curl"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence",
|
"fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||||
"log",
|
"log",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -619,6 +619,15 @@ dependencies = [
|
|||||||
"wasmer-wasi-fl",
|
"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]]
|
[[package]]
|
||||||
name = "fce-wit-generator"
|
name = "fce-wit-generator"
|
||||||
version = "0.1.6"
|
version = "0.1.6"
|
||||||
@ -673,6 +682,16 @@ dependencies = [
|
|||||||
"fluence-sdk-main 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)",
|
"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]]
|
[[package]]
|
||||||
name = "fluence-app-service"
|
name = "fluence-app-service"
|
||||||
version = "0.1.6"
|
version = "0.1.6"
|
||||||
@ -1106,7 +1125,7 @@ dependencies = [
|
|||||||
name = "inner-records-test"
|
name = "inner-records-test"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence",
|
"fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||||
"safe-transmute",
|
"safe-transmute",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1145,7 +1164,7 @@ dependencies = [
|
|||||||
name = "ipfs-effector"
|
name = "ipfs-effector"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence",
|
"fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||||
"log",
|
"log",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1153,7 +1172,7 @@ dependencies = [
|
|||||||
name = "ipfs-pure"
|
name = "ipfs-pure"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence",
|
"fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||||
"log",
|
"log",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1232,7 +1251,7 @@ checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235"
|
|||||||
name = "local_storage"
|
name = "local_storage"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence",
|
"fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||||
"log",
|
"log",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1721,7 +1740,7 @@ dependencies = [
|
|||||||
name = "record-effector"
|
name = "record-effector"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence",
|
"fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||||
"test-record",
|
"test-record",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1729,7 +1748,7 @@ dependencies = [
|
|||||||
name = "record-pure"
|
name = "record-pure"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence",
|
"fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||||
"test-record",
|
"test-record",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -2014,7 +2033,7 @@ name = "site-storage"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"fluence",
|
"fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||||
"log",
|
"log",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -2158,7 +2177,7 @@ dependencies = [
|
|||||||
name = "test-record"
|
name = "test-record"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence",
|
"fluence 0.2.3 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2593,7 +2612,15 @@ checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307"
|
|||||||
name = "wasm-greeting"
|
name = "wasm-greeting"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
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]]
|
[[package]]
|
||||||
|
@ -4,6 +4,7 @@ members = [
|
|||||||
"crates/wit-interfaces",
|
"crates/wit-interfaces",
|
||||||
"crates/wit-parser",
|
"crates/wit-parser",
|
||||||
"engine",
|
"engine",
|
||||||
|
"examples/call_parameters",
|
||||||
"examples/greeting",
|
"examples/greeting",
|
||||||
"examples/ipfs-node/effector",
|
"examples/ipfs-node/effector",
|
||||||
"examples/ipfs-node/pure",
|
"examples/ipfs-node/pure",
|
||||||
@ -13,7 +14,7 @@ members = [
|
|||||||
"examples/site-storage/site-storage",
|
"examples/site-storage/site-storage",
|
||||||
"examples/site-storage/curl",
|
"examples/site-storage/curl",
|
||||||
"examples/site-storage/local_storage",
|
"examples/site-storage/local_storage",
|
||||||
"examples/call_parameters",
|
"examples/sqlite",
|
||||||
"fluence-app-service",
|
"fluence-app-service",
|
||||||
"fluence-faas",
|
"fluence-faas",
|
||||||
"fluence-faas/tests/json_wasm_tests/arguments_passing",
|
"fluence-faas/tests/json_wasm_tests/arguments_passing",
|
||||||
|
@ -44,7 +44,7 @@ pub(super) fn itype_to_wtype(ty: &IType) -> WType {
|
|||||||
ty => {
|
ty => {
|
||||||
eprintln!("trying to convert {:?}", ty);
|
eprintln!("trying to convert {:?}", ty);
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
examples/sqlite/Cargo.toml
Normal file
13
examples/sqlite/Cargo.toml
Normal file
@ -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"
|
11
examples/sqlite/Config.toml
Normal file
11
examples/sqlite/Config.toml
Normal file
@ -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
|
BIN
examples/sqlite/artifacts/sqlite_test.wasm
Executable file
BIN
examples/sqlite/artifacts/sqlite_test.wasm
Executable file
Binary file not shown.
10
examples/sqlite/build.sh
Executable file
10
examples/sqlite/build.sh
Executable file
@ -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/
|
76
examples/sqlite/src/main.rs
Normal file
76
examples/sqlite/src/main.rs
Normal file
@ -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::<String>(0).unwrap());
|
||||||
|
println!("age = {}", statement.read::<i64>(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());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user