Skip to content

Commit

Permalink
Move fastn_ds::wasm::Store to fastn_wasm::Store
Browse files Browse the repository at this point in the history
  • Loading branch information
Arpita-Jaiswal committed Dec 22, 2024
1 parent da6a32e commit 0df9716
Show file tree
Hide file tree
Showing 18 changed files with 1,966 additions and 87 deletions.
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.

8 changes: 1 addition & 7 deletions fastn-ds/src/wasm/exports/http/get_request.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
pub async fn get_request(
mut caller: wasmtime::Caller<'_, fastn_ds::wasm::Store>,
mut caller: wasmtime::Caller<'_, fastn_wasm::Store>,
) -> wasmtime::Result<i32> {
let req = caller.data().to_http();
fastn_wasm::helpers::send_json(req, &mut caller).await
}

impl fastn_ds::wasm::Store {
pub fn to_http(&self) -> ft_sys_shared::Request {
self.req.clone()
}
}
8 changes: 1 addition & 7 deletions fastn-ds/src/wasm/exports/http/send_response.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
pub async fn send_response(
mut caller: wasmtime::Caller<'_, fastn_ds::wasm::Store>,
mut caller: wasmtime::Caller<'_, fastn_wasm::Store>,
ptr: i32,
len: i32,
) -> wasmtime::Result<()> {
let r = fastn_wasm::helpers::get_json(ptr, len, &mut caller)?;
caller.data_mut().store_response(r);
Ok(())
}

impl fastn_ds::wasm::Store {
pub fn store_response(&mut self, r: ft_sys_shared::Request) {
self.response = Some(r);
}
}
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
4 changes: 2 additions & 2 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 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
4 changes: 2 additions & 2 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 fastn_wasm::Store {
pub fn register_functions(&self, linker: &mut wasmtime::Linker<fastn_wasm::Store>) {
// general utility functions
fastn_ds::func2!(linker, "env_print", fastn_wasm::env::print);
fastn_ds::func0ret!(linker, "env_now", fastn_wasm::env::now);
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
4 changes: 2 additions & 2 deletions fastn-ds/src/wasm/exports/sqlite/connect.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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> {
Expand All @@ -8,7 +8,7 @@ pub async fn connect(
caller.data_mut().sqlite_connect(db_url.as_str()).await
}

impl fastn_ds::wasm::Store {
impl fastn_wasm::Store {
pub async 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()
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
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
2 changes: 1 addition & 1 deletion fastn-ds/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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);
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

0 comments on commit 0df9716

Please sign in to comment.