Skip to content

Commit

Permalink
Merge pull request #5 from second-state/chore/wasi_socket_5
Browse files Browse the repository at this point in the history
Bump wasmedge_wasi_socket to 0.5
  • Loading branch information
juntao authored Jun 6, 2023
2 parents 520f70b + 1fc2a9b commit 69bd545
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 13 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/examples.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: examples

on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'info'
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
runs-on: ubuntu-20.04
steps:
- name: Install WasmEdge
run: curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s
- name: Install Rust
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y
- name: Install Rust target
run: cargo install cargo-wasi
- name: Checkout code
uses: actions/checkout@v2
- name: setup mysql
uses: shogo82148/actions-setup-mysql@v1
with:
mysql-version: '8.0'
user: 'test'
password: 'password'
- name: Create DataBase
run: mysql -utest -h127.0.0.1 -ppassword -e 'CREATE DATABASE db_name'
- name: Build & Run
run: |
cd examples/crud
cargo wasi build
~/.wasmedge/bin/wasmedge --env 'DATABASE_URL=mysql://test:[email protected]:3306/db_name' target/wasm32-wasi/debug/crud.wasm
23 changes: 19 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT/Apache-2.0"
name = "mysql_async_wasi"
readme = "README.md"
repository = "https://github.com/WasmEdge/mysql_async_wasi"
version = "0.31.2"
version = "0.31.3"
exclude = ["test/*"]
edition = "2018"
categories = ["asynchronous", "database"]
Expand Down Expand Up @@ -42,9 +42,17 @@ url = "2.1"
# mio = { version = "0.8.0", features = ["os-poll", "net"] }

[target.'cfg(target_os="wasi")'.dependencies]
tokio_wasi = {version = "1", features = [ "io-util", "fs", "net", "time", "rt", "macros", "sync"] }
tokio_wasi = { version = "1", features = [
"io-util",
"fs",
"net",
"time",
"rt",
"macros",
"sync",
] }
tokio-util_wasi = { version = "0.7.2", features = ["codec", "io"] }
wasmedge_wasi_socket = "0.4.3"
wasmedge_wasi_socket = "0.5"

# [target.'cfg(not(target_os="wasi"))'.dev-dependencies]
# tempfile = "3.1.0"
Expand Down Expand Up @@ -88,7 +96,14 @@ optional = true

[dev-dependencies]
tempfile = "3.1.0"
tokio_wasi = { version = "1", features = [ "io-util", "fs", "net", "time", "rt", "macros"] }
tokio_wasi = { version = "1", features = [
"io-util",
"fs",
"net",
"time",
"rt",
"macros",
] }
rand = "0.8.0"

[features]
Expand Down
12 changes: 3 additions & 9 deletions examples/crud/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use mysql_async::{
prelude::*, Opts, OptsBuilder, Pool, PoolConstraints, PoolOpts, QueryResult, Result,
};
use mysql_async::{prelude::*, Opts, OptsBuilder, Pool, PoolConstraints, PoolOpts, Result};

fn get_url() -> String {
if let Ok(url) = std::env::var("DATABASE_URL") {
Expand All @@ -14,7 +12,7 @@ fn get_url() -> String {
}
url
} else {
"mysql://root:[email protected]:3306/mysql".into()
"mysql://root:[email protected]:3306/test_db".into()
}
}

Expand All @@ -29,7 +27,6 @@ struct Order {
shipping_address: String,
}


impl Order {
fn new(
order_id: i32,
Expand All @@ -52,7 +49,6 @@ impl Order {
}
}


#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
let opts = Opts::from_url(&*get_url()).unwrap();
Expand All @@ -79,7 +75,6 @@ async fn main() -> Result<()> {
r"DELETE FROM orders;".ignore(&mut conn).await?;
}


let orders = vec![
Order::new(1, 12, 2, 56.0, 15.0, 2.0, String::from("Mataderos 2312")),
Order::new(2, 15, 3, 256.0, 30.0, 16.0, String::from("1234 NW Bobcat")),
Expand Down Expand Up @@ -132,7 +127,7 @@ async fn main() -> Result<()> {

// delete some data
let _ = conn
.query_iter("DELETE FROM commerce WHERE OrderID=4;")
.query_iter("DELETE FROM orders WHERE order_id=4;")
.await?;
// query data
let loaded_orders = "SELECT * FROM orders"
Expand Down Expand Up @@ -160,7 +155,6 @@ async fn main() -> Result<()> {
SET shipping_address = '8366 Elizabeth St.'
WHERE order_id = 2;"
.ignore(&mut conn)

.await?;
// query data
let loaded_orders = "SELECT * FROM orders"
Expand Down

0 comments on commit 69bd545

Please sign in to comment.