-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
try to get wa-sqlite to compile with rust wasm
- Loading branch information
Showing
10 changed files
with
143 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as SQLite from "@xmtp/wa-sqlite"; | ||
import initModule from "@xmtp/wa-sqlite/build"; | ||
|
||
const sqlite3 = SQLite.Factory(module); | ||
|
||
export function sqlite3_result_text(context, value) { | ||
sqlite3.result_text(context, value); | ||
} | ||
|
||
export function sqlite3_result_int(context, value) { | ||
sqlite3.result_int(context, value); | ||
} | ||
|
||
export function sqlite3_result_int64(context, value) { | ||
sqlite3.result_int64(context, value); | ||
} | ||
|
||
export function sqlite3_result_double(context, value) { | ||
sqlite3.result_double(context, value); | ||
} | ||
|
||
export function sqlite3_result_blob(context, value) { | ||
sqlite3.result_blob(context, value); | ||
} | ||
|
||
export function sqlite3_result_null(context) { | ||
sqlite3.result_null(context); | ||
} | ||
|
||
export function establish(database_url) { | ||
try { | ||
console.log("Opening database!"); | ||
return sqlite3.open_v2(database_url); | ||
} catch { | ||
console.log("establish err"); | ||
} | ||
} | ||
|
||
export function batch_execute(database, query) { | ||
try { | ||
sqlite3.exec(database, query); | ||
console.log("Batch exec'ed"); | ||
} catch { | ||
console.log("exec err"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "js-to-rust-test", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@xmtp/wa-sqlite": "^1.0.1", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
"@xmtp/wa-sqlite@^1.0.1": | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/@xmtp/wa-sqlite/-/wa-sqlite-1.0.1.tgz#3ecab8cf3ea15386e3e1d152526d6190898f7529" | ||
integrity sha512-/MVsgo5HG7FVdMMNUKsf5HTIDnOncSK0ljrOBr+xqkfH6qonQwqmUsjcW2Z4GyyCIVvhQlxOSy+1W+7Z/WH0DA== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,33 @@ | ||
use wasm_bindgen::{prelude::*, JsValue}; | ||
|
||
/// Simple Connection | ||
#[wasm_bindgen] | ||
#[wasm_bindgen(module = "/js-to-rust-test/index.js")] | ||
extern "C" { | ||
#[wasm_bindgen(catch)] | ||
pub fn batch_execute(query: &str) -> Result<(), JsValue>; | ||
pub fn batch_execute(database: i32, query: &str) -> Result<(), JsValue>; | ||
|
||
#[wasm_bindgen(catch)] | ||
pub fn establish(database_url: &str) -> Result<(), JsValue>; | ||
pub fn establish(database_url: &str) -> Result<i32, JsValue>; | ||
} | ||
|
||
/// Direct Shim for was-sqlite | ||
#[wasm_bindgen] | ||
/// Direct Shim for wa-sqlite | ||
#[wasm_bindgen(module = "/js-to-rust-test/index.js")] | ||
extern "C" { | ||
#[wasm_bindgen] | ||
pub fn sqlite3_result_text(context: i32, value: String); | ||
|
||
#[wasm_bindgen] | ||
pub fn sqlite3_result_int(context: i32, value: i32); | ||
|
||
#[wasm_bindgen] | ||
pub fn sqlite3_result_int64(context: i32, value: i64); | ||
|
||
#[wasm_bindgen] | ||
pub fn sqlite3_result_double(context: i32, value: f64); | ||
|
||
#[wasm_bindgen] | ||
pub fn sqlite3_result_blob(context: i32, value: Vec<u8>); | ||
|
||
#[wasm_bindgen] | ||
pub fn sqlite3_result_null(context: i32); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters