Skip to content

Commit

Permalink
fix: rebase and update Cargo.toml of the macro
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Oct 28, 2021
1 parent f83f0f3 commit e101bef
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
5 changes: 5 additions & 0 deletions api/rust/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
name = "suborbital-macro"
version = "0.1.0"
edition = "2021"
authors = ["cohix <[email protected]>", "Florian Fromm <[email protected]>"]
description = "Macro for setting up a Runnable"
license = "Apache-2.0"
repository = "https://github.com/suborbital/reactr"
homepage = "https://suborbital.dev"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
Expand Down
10 changes: 4 additions & 6 deletions api/rust/suborbital/src/db.rs → api/rust/core/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::STATE;

use query::{QueryArg, QueryType};

extern {
extern "C" {
fn db_exec(query_type: i32, name_ptr: *const u8, name_size: i32, ident: i32) -> i32;
}

Expand All @@ -16,8 +16,7 @@ extern {
// the return value is the inserted auto-increment ID from the query result, if any,
// formatted as JSON with the key `lastInsertID`
pub fn insert(name: &str, args: Vec<QueryArg>) -> Result<Vec<u8>, runnable::HostErr> {
args.iter()
.for_each(|arg| ffi::add_var(&arg.name, &arg.value));
args.iter().for_each(|arg| ffi::add_var(&arg.name, &arg.value));

let result_size = unsafe { db_exec(QueryType::INSERT.into(), name.as_ptr(), name.len() as i32, STATE.ident) };

Expand All @@ -30,11 +29,10 @@ pub fn insert(name: &str, args: Vec<QueryArg>) -> Result<Vec<u8>, runnable::Host
//
// the return value is the query result formatted as JSON, with each column name as a top-level key
pub fn select(name: &str, args: Vec<QueryArg>) -> Result<Vec<u8>, runnable::HostErr> {
args.iter()
.for_each(|arg| ffi::add_var(&arg.name, &arg.value));
args.iter().for_each(|arg| ffi::add_var(&arg.name, &arg.value));

let result_size = unsafe { db_exec(QueryType::SELECT.into(), name.as_ptr(), name.len() as i32, STATE.ident) };

// retreive the result from the host and return it
ffi::result(result_size)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

pub struct QueryArg {
pub name: String,
pub value: String
pub value: String,
}

impl QueryArg {
pub fn new(name: &str, value: &str) -> Self{
QueryArg{
pub fn new(name: &str, value: &str) -> Self {
QueryArg {
name: String::from(name),
value: String::from(value),
}
Expand All @@ -25,4 +24,4 @@ impl From<QueryType> for i32 {
QueryType::SELECT => 1,
}
}
}
}
12 changes: 9 additions & 3 deletions api/rust/core/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::runnable::HostErr;
use crate::util;
use crate::STATE;

extern {
extern "C" {
fn get_ffi_result(pointer: *const u8, ident: i32) -> i32;
fn add_ffi_var(name_ptr: *const u8, name_len: i32, val_ptr: *const u8, val_len: i32, ident: i32) -> i32;
}
Expand Down Expand Up @@ -44,6 +44,12 @@ pub(crate) fn result(size: i32) -> Result<Vec<u8>, HostErr> {

pub(crate) fn add_var(name: &str, value: &str) {
unsafe {
add_ffi_var(name.as_ptr(), name.len() as i32, value.as_ptr(), value.len() as i32, STATE.ident);
add_ffi_var(
name.as_ptr(),
name.len() as i32,
value.as_ptr(),
value.len() as i32,
STATE.ident,
);
}
}
}
8 changes: 4 additions & 4 deletions api/rust/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
pub mod runnable;
pub mod db;
pub mod graphql;
pub mod http;
pub mod cache;
pub mod db;
pub mod ffi;
pub mod file;
pub mod graphql;
pub mod graphql;
pub mod http;
pub mod http;
pub mod log;
pub mod req;
pub mod resp;
pub mod runnable;
pub mod runnable;
pub mod util;

/// This file represents the Rust "API" for Reactr Wasm runnables. The functions defined herein are used to exchange
Expand Down

0 comments on commit e101bef

Please sign in to comment.