Replies: 1 comment 5 replies
-
I'm generally open to share the relevant code, but that might not be as straightforward as you believe. In the best case it would be possible to share the whole backend implementation, so that you only need to provide a custom connection implementation. That would mean that everything else would "just" work, as you could write The What might be possible is to somehow store all the ffi functions used internally as function pointers in the value type, so that diesel itself could register the libsqlite3 functions there and your wasm connection could register the wasm functions there. That also would require some additional work to store the value pointer itself, although we could maybe just do that as void pointer and cast it later in some shim to the right type? |
Beta Was this translation helpful? Give feedback.
-
Hello All!
For the past ~month, I've been working on an alternative WASM SQLite backend for diesel crate
Interacting with external Clibs from WASM code is tricky. Compiling to
wasm32-unknown-emscripten
and linking with SQLite is possible, but then allwasm-bindgen
support is lost.diesel-wasm-sqlite
implements an alternative solution, where the SQLite WASM module is loaded separately and called from the backend. This can be a temporary solution until compiling the C SQLite dependency withwasm-c-abi
is possible and no longer 'unstable'.(if someone can already do that, please let me know :)
Currently lots of code in the wasm backend is copy-pasted from the diesel-backend and specialized for the
WasmSqlite
backend type. It would be great to share code with the main diesel library in order to avoid duplicating all code in the backend.I propose creating a new feature flag
sqlite-backend
(or whatever name works) that exposes theSqlite
backend type, but does not import thelibsqlite3-sys
library. This would allow my backend to access all commonQueryBuilder
functions, but specialize theWasmSqliteConnection
for a SQLite WASM module in the browser.Another potential solution could be to split the sqlite feature flags into
sqlite-backend
andsqlite
, enablingsqlite-backend
in thesqlite
feature, along with thelibsqlite3-sys
dependency. This has the advantage of lessfeature = ""
declarations on items.Signatures of common code in the backend (some of these are still private):
Essentially anything QueryBuilder-related that isn't tied to the ffi:
all of
insert_with_default_sqlite.rs
impl<Col, Expr> InsertValues<WasmSqlite, Col::Table> for DefaultableColumnInsertValue<ColumnInsertValue<Col, Expr>>
impl QueryFragment<WasmSqlite> for InsertOrIgnore
impl QueryFragment<WasmSqlite> for Replace
impl<T: QueryFragment<Sqlite>> QueryFragment<Sqlite> for ParenthesisWrapper<T>
impl QueryBuilder<WasmSqlite> for SqliteQueryBuilder
impl<Expr> QueryFragment<WasmSqlite, SqliteReturningClause> for ReturningClause<Expr>
impl QueryFragment<WasmSqlite> for LimitOffsetClause<NoLimitClause, NoOffsetClause>
impl<L> QueryFragment<WasmSqlite> for LimitOffsetClause<LimitClause<L>, NoOffsetClause>
impl<O> QueryFragment<WasmSqlite> for LimitOffsetClause<NoLimitClause, OffsetClause<O>>
impl<L, O> QueryFragment<WasmSqlite> for LimitOffsetClause<LimitClause<L>, OffsetClause<O>>
impl<'a> QueryFragment<WasmSqlite> for BoxedLimitOffsetClause<'a, WasmSqlite>
impl<'a> IntoBoxedClause<'a, WasmSqlite> for LimitOffsetClause<NoLimitClause, NoOffsetClause>
impl<'a, L> IntoBoxedClause<'a, WasmSqlite> for LimitOffsetClause<LimitClause<L>, NoOffsetClause>
impl<'a, O> IntoBoxedClause<'a, WasmSqlite> for LimitOffsetClause<NoLimitClause, OffsetClause<O>>
impl<'a, L, O> IntoBoxedClause<'a, WasmSqlite> for LimitOffsetClause<LimitClause<L>, OffsetClause<O>>
All
impl ToSql<$SqlType, Sqlite> for $type
I'd be happy to submit a PR implementing this feature flag, but wanted a go-ahead/discussion from maintainers before then, especially if there's a better way.
Beta Was this translation helpful? Give feedback.
All reactions