Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move fastn_ds::wasm::Store to fastn_wasm::Store #2042

Closed
wants to merge 4 commits into from
Closed
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
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion fastn-ds/src/wasm/exports/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod http;
mod pg;
mod register;
mod sqlite;
4 changes: 2 additions & 2 deletions fastn-ds/src/wasm/exports/pg/batch_execute.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub async fn batch_execute(
mut caller: wasmtime::Caller<'_, fastn_ds::wasm::Store>,
mut caller: wasmtime::Caller<'_, fastn_wasm::Store>,
conn: i32,
ptr: i32,
len: i32,
Expand All @@ -9,7 +9,7 @@ pub async fn batch_execute(
fastn_wasm::helpers::send_json(res, &mut caller).await
}

impl fastn_ds::wasm::Store {
impl fastn_wasm::Store {
pub async fn pg_batch_execute(
&mut self,
conn: i32,
Expand Down
8 changes: 4 additions & 4 deletions fastn-ds/src/wasm/exports/pg/connect.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
pub async fn connect(
mut caller: wasmtime::Caller<'_, fastn_ds::wasm::Store>,
mut caller: wasmtime::Caller<'_, fastn_wasm::Store>,
ptr: i32,
len: i32,
) -> wasmtime::Result<i32> {
let db_url = fastn_wasm::helpers::get_str(ptr, len, &mut caller)?;
caller.data_mut().pg_connect(db_url.as_str()).await
}

impl fastn_ds::wasm::Store {
impl fastn_wasm::Store {
pub async fn pg_connect(&mut self, db_url: &str) -> wasmtime::Result<i32> {
let db_url = if db_url == "default" {
self.db_url.as_str()
Expand All @@ -28,10 +28,10 @@ impl fastn_ds::wasm::Store {

async fn get_client(
pool: &deadpool_postgres::Pool,
clients: &mut Vec<fastn_ds::wasm::Conn>,
clients: &mut Vec<fastn_wasm::Conn>,
) -> wasmtime::Result<i32> {
let client = pool.get().await?;
clients.push(fastn_ds::wasm::Conn { client });
clients.push(fastn_wasm::Conn { client });
Ok(clients.len() as i32 - 1)
}
}
Expand Down
4 changes: 2 additions & 2 deletions fastn-ds/src/wasm/exports/pg/execute.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub async fn execute(
mut caller: wasmtime::Caller<'_, fastn_ds::wasm::Store>,
mut caller: wasmtime::Caller<'_, fastn_wasm::Store>,
conn: i32,
ptr: i32,
len: i32,
Expand All @@ -10,7 +10,7 @@ pub async fn execute(
fastn_wasm::helpers::send_json(res, &mut caller).await
}

impl fastn_ds::wasm::Store {
impl fastn_wasm::Store {
pub async fn pg_execute(
&mut self,
conn: i32,
Expand Down
4 changes: 2 additions & 2 deletions fastn-ds/src/wasm/exports/pg/query.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub async fn query(
mut caller: wasmtime::Caller<'_, fastn_ds::wasm::Store>,
mut caller: wasmtime::Caller<'_, fastn_wasm::Store>,
conn: i32,
ptr: i32,
len: i32,
Expand Down Expand Up @@ -108,7 +108,7 @@ impl PgRow {
}
}

impl fastn_ds::wasm::Store {
impl fastn_wasm::Store {
pub async fn pg_query(
&mut self,
conn: i32,
Expand Down
20 changes: 6 additions & 14 deletions fastn-ds/src/wasm/exports/register.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
impl fastn_ds::wasm::Store {
pub fn register_functions(&self, linker: &mut wasmtime::Linker<fastn_ds::wasm::Store>) {
impl<T: fastn_wasm::StoreExt> fastn_wasm::Store<T> {
pub fn register_functions(&self, linker: &mut wasmtime::Linker<fastn_wasm::Store<T>>) {
// general utility functions
fastn_ds::func2!(linker, "env_print", fastn_wasm::env::print);
fastn_ds::func0ret!(linker, "env_now", fastn_wasm::env::now);
Expand All @@ -11,11 +11,7 @@ impl fastn_ds::wasm::Store {
fastn_ds::func2ret!(linker, "crypto_decrypt", fastn_wasm::crypto::decrypt);

// sqlite
fastn_ds::func2ret!(
linker,
"sqlite_connect",
fastn_ds::wasm::exports::sqlite::connect
);
fastn_ds::func2ret!(linker, "sqlite_connect", fastn_wasm::sqlite::connect);
fastn_ds::func3ret!(
linker,
"sqlite_query",
Expand Down Expand Up @@ -44,16 +40,12 @@ impl fastn_ds::wasm::Store {
);

// request related stuff
fastn_ds::func0ret!(
linker,
"http_get_request",
fastn_ds::wasm::exports::http::get_request
);
fastn_ds::func2ret!(linker, "http_send_request", fastn_wasm::send_request);
fastn_ds::func0ret!(linker, "http_get_request", fastn_wasm::http::get_request);
fastn_ds::func2ret!(linker, "http_send_request", fastn_wasm::http::send_request);
fastn_ds::func2!(
linker,
"http_send_response",
fastn_ds::wasm::exports::http::send_response
fastn_wasm::http::send_response
);

// document store related
Expand Down
4 changes: 2 additions & 2 deletions fastn-ds/src/wasm/exports/sqlite/batch_execute.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::wasm::exports::sqlite::query::rusqlite_to_diesel;

pub async fn batch_execute(
mut caller: wasmtime::Caller<'_, fastn_ds::wasm::Store>,
mut caller: wasmtime::Caller<'_, fastn_wasm::Store>,
ptr: i32,
len: i32,
) -> wasmtime::Result<i32> {
Expand All @@ -10,7 +10,7 @@ pub async fn batch_execute(
fastn_wasm::helpers::send_json(res, &mut caller).await
}

impl fastn_ds::wasm::Store {
impl fastn_wasm::Store {
pub async fn sqlite_batch_execute(
&mut self,
q: String,
Expand Down
14 changes: 2 additions & 12 deletions fastn-ds/src/wasm/exports/sqlite/connect.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
pub async fn connect(
mut caller: wasmtime::Caller<'_, fastn_ds::wasm::Store>,
ptr: i32,
len: i32,
) -> wasmtime::Result<i32> {
let db_url = fastn_wasm::helpers::get_str(ptr, len, &mut caller)?;
println!("sqlite_connect: {db_url}");
caller.data_mut().sqlite_connect(db_url.as_str()).await
}

impl fastn_ds::wasm::Store {
pub async fn sqlite_connect(&mut self, db_url: &str) -> wasmtime::Result<i32> {
impl fastn_wasm::Store {
fn sqlite_connect(&mut self, db_url: &str) -> wasmtime::Result<i32> {
let db = rusqlite::Connection::open(if db_url == "default" {
self.db_url.as_str()
} else {
Expand Down
4 changes: 2 additions & 2 deletions fastn-ds/src/wasm/exports/sqlite/execute.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::wasm::exports::sqlite::query::rusqlite_to_diesel;

pub async fn execute(
mut caller: wasmtime::Caller<'_, fastn_ds::wasm::Store>,
mut caller: wasmtime::Caller<'_, fastn_wasm::Store>,
ptr: i32,
len: i32,
) -> wasmtime::Result<i32> {
Expand All @@ -11,7 +11,7 @@ pub async fn execute(
fastn_wasm::helpers::send_json(res, &mut caller).await
}

impl fastn_ds::wasm::Store {
impl fastn_wasm::Store {
async fn sqlite_execute(
&mut self,
q: fastn_ds::wasm::exports::sqlite::Query,
Expand Down
1 change: 0 additions & 1 deletion fastn-ds/src/wasm/exports/sqlite/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mod connect;
pub use connect::connect;

mod query;
pub use query::query;
Expand Down
4 changes: 2 additions & 2 deletions fastn-ds/src/wasm/exports/sqlite/query.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::os::raw::c_int;

pub async fn query(
mut caller: wasmtime::Caller<'_, fastn_ds::wasm::Store>,
mut caller: wasmtime::Caller<'_, fastn_wasm::Store>,
_conn: i32,
ptr: i32,
len: i32,
Expand Down Expand Up @@ -73,7 +73,7 @@ struct Field {
bytes: Option<Value>,
}

impl fastn_ds::wasm::Store {
impl fastn_wasm::Store {
pub async fn sqlite_query(
&mut self,
q: Query,
Expand Down
5 changes: 2 additions & 3 deletions fastn-ds/src/wasm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
pub mod exports;
pub mod macros;
mod store;

pub use store::{Conn, Store};
pub struct Store;

#[tracing::instrument(skip_all)]
pub async fn process_http_request(
Expand All @@ -12,7 +11,7 @@ pub async fn process_http_request(
db_url: String,
) -> wasmtime::Result<ft_sys_shared::Request> {
let path = req.uri.clone();
let hostn_store = fastn_ds::wasm::Store::new(req, wasm_pg_pools, db_url);
let hostn_store = fastn_wasm::Store::new(req, wasm_pg_pools, db_url, Store);
let mut linker = wasmtime::Linker::new(module.engine());
hostn_store.register_functions(&mut linker);
let wasm_store = wasmtime::Store::new(module.engine(), hostn_store);
Expand Down
Loading
Loading