* feat: Add proxy connection type * feat: Add proxy database's proxy functions trait. * fix: Remove some unused impl to fix the unit test * test: Create the proxy by empty declaration. * test: Try to genereate query and exec commands. * perf: Add more query debug trait for debugging. * chore: Add the example for wasi + proxy. * chore: Try to read string from wasmtime vm. * chore: Sucks, but how to do without tokio::spawn? * chore: Complete the basic memory read logic. * chore: Abandon the WASI demo, native demo first... * refactor: Use single proxy connection generator to avoid stack overflow * refactor: Rename the inner structs' name * fix: Fix CI clippy and unit test * fix: Rename the example. * chore: Try to embed surrealdb for proxy test. * fix: Transfer the query result correctly. * refactor: Rename the example. * chore: Ready to add example for wasmtime proxy. * feat: Try to compile sea-orm into wasm binary. But it would failed on wasm32-wasi target because of the socket deps. It can be compiled on wasm32-unknown-unknown target. * fix: WASM targets can't use sqlx. * fix: Try to fix CI by remove toml. * fix: Try to fix CI by remove toml. * fix: Move vm to the example's root dir. * fix: Add a pre-build script. * chore: Add README. * fix: Try to fix CI. * feat: Add proxy logic in wasm module. * fix: Try to run the wasi module. But WASI cannot support multi threads.. so the module was run failed. * refactor: Bump wasmtime to 14. * fix: Now we can use async traits on wasmtime. The solution is add the current thread tag to tokio-wasi. * build: Use build.rs instead of dynamic command. * feat: Add the execute result's transfer logic. * fix: Convert sqlx query result for sea-query. * fix: Now we can transfer wasm's query to outside. * refactor: Convert to ProxyRow first. It's the solution to know the type information about the value. * fix: Multiple time library reference. * feat: Add a new proxy example which uses GlueSQL. * test: Add the test cases for three new examples. Just try to run once... * ci: Add wasm component's compiler for unit test. * ci: Add wasi target. * ci: It may needs wasi target twice... * feat: Add more keys for proxy execute result. To transfer the fully information of the execute result. * fix: Use custom id type instead of json value. * fix: Wrong reference type. * fix: Rewrite the transformer. * perf: Add ToString trait for proxy exec result. * revert: Again. Refs: 9bac6e91ca9df04ccd8368906e1613cfc5b96218 * revert: Back to the basic proxy exec result. Refs: e0330dde73a54d461d5f38c69eec5e13bcc928d4 * refactor: Update GlueSQL and SurrealDB examples. (#1980) * refactor: Bump gluesql to 0.15 Relate to https://github.com/gluesql/gluesql/issues/1438 * Use SQLParser to parse and replace placeholders. * Use SQLParser for surrealdb demo. * Transform the query by SQLParser. * Tweaks * Remove wasmtime example. (#2001) * ci: Add additional targets. * Remove proxy wasmtime example. * Format --------- Co-authored-by: 伊欧 <langyo.china@gmail.com> Co-authored-by: 伊欧 <m13776491897@163.com>
82 lines
3.2 KiB
Rust
82 lines
3.2 KiB
Rust
/// Defines the result of executing an operation
|
|
#[derive(Debug)]
|
|
pub struct ExecResult {
|
|
/// The type of result from the execution depending on the feature flag enabled
|
|
/// to choose a database backend
|
|
pub(crate) result: ExecResultHolder,
|
|
}
|
|
|
|
/// Holds a result depending on the database backend chosen by the feature flag
|
|
#[allow(clippy::enum_variant_names)]
|
|
#[derive(Debug)]
|
|
pub(crate) enum ExecResultHolder {
|
|
/// Holds the result of executing an operation on a MySQL database
|
|
#[cfg(feature = "sqlx-mysql")]
|
|
SqlxMySql(sqlx::mysql::MySqlQueryResult),
|
|
/// Holds the result of executing an operation on a PostgreSQL database
|
|
#[cfg(feature = "sqlx-postgres")]
|
|
SqlxPostgres(sqlx::postgres::PgQueryResult),
|
|
/// Holds the result of executing an operation on a SQLite database
|
|
#[cfg(feature = "sqlx-sqlite")]
|
|
SqlxSqlite(sqlx::sqlite::SqliteQueryResult),
|
|
/// Holds the result of executing an operation on the Mock database
|
|
#[cfg(feature = "mock")]
|
|
Mock(crate::MockExecResult),
|
|
/// Holds the result of executing an operation on the Proxy database
|
|
#[cfg(feature = "proxy")]
|
|
Proxy(crate::ProxyExecResult),
|
|
}
|
|
|
|
// ExecResult //
|
|
|
|
impl ExecResult {
|
|
/// Get the last id after `AUTOINCREMENT` is done on the primary key
|
|
///
|
|
/// # Panics
|
|
///
|
|
/// Postgres does not support retrieving last insert id this way except through `RETURNING` clause
|
|
pub fn last_insert_id(&self) -> u64 {
|
|
match &self.result {
|
|
#[cfg(feature = "sqlx-mysql")]
|
|
ExecResultHolder::SqlxMySql(result) => result.last_insert_id(),
|
|
#[cfg(feature = "sqlx-postgres")]
|
|
ExecResultHolder::SqlxPostgres(_) => {
|
|
panic!("Should not retrieve last_insert_id this way")
|
|
}
|
|
#[cfg(feature = "sqlx-sqlite")]
|
|
ExecResultHolder::SqlxSqlite(result) => {
|
|
let last_insert_rowid = result.last_insert_rowid();
|
|
if last_insert_rowid < 0 {
|
|
unreachable!("negative last_insert_rowid")
|
|
} else {
|
|
last_insert_rowid as u64
|
|
}
|
|
}
|
|
#[cfg(feature = "mock")]
|
|
ExecResultHolder::Mock(result) => result.last_insert_id,
|
|
#[cfg(feature = "proxy")]
|
|
ExecResultHolder::Proxy(result) => result.last_insert_id,
|
|
#[allow(unreachable_patterns)]
|
|
_ => unreachable!(),
|
|
}
|
|
}
|
|
|
|
/// Get the number of rows affected by the operation
|
|
pub fn rows_affected(&self) -> u64 {
|
|
match &self.result {
|
|
#[cfg(feature = "sqlx-mysql")]
|
|
ExecResultHolder::SqlxMySql(result) => result.rows_affected(),
|
|
#[cfg(feature = "sqlx-postgres")]
|
|
ExecResultHolder::SqlxPostgres(result) => result.rows_affected(),
|
|
#[cfg(feature = "sqlx-sqlite")]
|
|
ExecResultHolder::SqlxSqlite(result) => result.rows_affected(),
|
|
#[cfg(feature = "mock")]
|
|
ExecResultHolder::Mock(result) => result.rows_affected,
|
|
#[cfg(feature = "proxy")]
|
|
ExecResultHolder::Proxy(result) => result.rows_affected,
|
|
#[allow(unreachable_patterns)]
|
|
_ => unreachable!(),
|
|
}
|
|
}
|
|
}
|