Skip to content

Commit

Permalink
bump mysql_async / sqlx versions
Browse files Browse the repository at this point in the history
  • Loading branch information
andrieshiemstra committed May 13, 2024
1 parent 6adfdb0 commit 0f59802
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ cached = "0.43"
reqwest = {version = "0.11", features=["rustls-tls", "cookies", "gzip", "deflate", "multipart", "blocking"], optional = true, default-features = false}
gpio-cdev = {git = "https://github.com/rust-embedded/gpio-cdev", optional = true, features = ["async-tokio", "futures"]}
futures = {version = "0.3"}
mysql_lib = {package="mysql_async", version = "0.33.0", optional = true}
sqlx_lib = {package="sqlx", version = "0.7.3", features = ["mysql", "postgres", "runtime-tokio", "time", "chrono", "uuid"], optional = true}
mysql_lib = {package="mysql_async", version = "0.34.1", optional = true}
sqlx_lib = {package="sqlx", version = "0.7.4", features = ["mysql", "postgres", "runtime-tokio", "time", "chrono", "uuid"], optional = true}
lru = {version = "0.12.1", optional = true}
csv = {version = "1.1.6", optional = true}
uuid = {version="1", features=["v4", "serde"], optional = true}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/db/mysql/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ pub fn get_con_pool_wrapper(
) -> Result<PoolWrapper, JsError> {
let con_str = if let Some(db) = db_opt {
format!(
"mysql://{user}:{pass}@{host}:{port}/{db}?conn_ttl=600&stmt_cache_size=128&wait_timeout=28800"
"mysql://{user}:{pass}@{host}:{port}/{db}?conn_ttl=300&stmt_cache_size=128&wait_timeout=3600&abs_conn_ttl=1800&abs_conn_ttl_jitter=600"
)
} else {
format!(
"mysql://{user}:{pass}@{host}:{port}?conn_ttl=600&stmt_cache_size=128&wait_timeout=28800"
"mysql://{user}:{pass}@{host}:{port}?conn_ttl=300&stmt_cache_size=128&wait_timeout=3600&abs_conn_ttl=1800&abs_conn_ttl_jitter=600"
)
};

Expand Down
2 changes: 1 addition & 1 deletion src/modules/db/mysql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ pub mod tests {

//#[test]
fn _test_params() {
//simple_logging::log_to_stderr(log::LevelFilter::Info);
simple_logging::log_to_stderr(log::LevelFilter::Info);

let builder = QuickJsRuntimeBuilder::new();
let builder = crate::init_greco_rt(builder);
Expand Down
36 changes: 26 additions & 10 deletions src/modules/db/sqlx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ impl SqlxConnection {
.idle_timeout(Duration::from_secs(600))
.max_lifetime(Duration::from_secs(3600))
.max_connections(100)
.min_connections(0)
.connect_lazy(con_str.as_str())
.map_err(|e| JsError::new_string(format!("{e}")))?;
Ok(SqlxConnection::MySqlConnection {
Expand All @@ -677,6 +678,7 @@ impl SqlxConnection {
.idle_timeout(Duration::from_secs(600))
.max_lifetime(Duration::from_secs(3600))
.max_connections(100)
.min_connections(0)
.connect_lazy(con_str.as_str())
.map_err(|e| JsError::new_string(format!("{e}")))?;
Ok(SqlxConnection::PostgresConnection {
Expand Down Expand Up @@ -1629,7 +1631,6 @@ unsafe extern "C" fn fn_transaction_commit(
#[cfg(test)]
pub mod tests {
use backtrace::Backtrace;
use log::LevelFilter;
use std::panic;
//use log::LevelFilter;
use quickjs_runtime::builder::QuickJsRuntimeBuilder;
Expand All @@ -1647,9 +1648,9 @@ pub mod tests {
);
}));

simple_logging::log_to_file("grecort.log", LevelFilter::Info)
.ok()
.expect("could not init logger");
//simple_logging::log_to_file("grecort.log", LevelFilter::Info)
// .ok()
// .expect("could not init logger");

//simple_logging::log_to_stderr(log::LevelFilter::Info);

Expand Down Expand Up @@ -1768,7 +1769,11 @@ pub mod tests {
} catch(ex) {
console.log("Pg fail: %s", ex);
console.error(ex);
await tx.rollback();
try {
await tx.rollback();
} catch(ex) {
// care
}
} finally {
await tx.close();
}
Expand Down Expand Up @@ -1871,13 +1876,18 @@ pub mod tests {
}
let htmlDoc = parser.parseFromString(`<html><body>${ps.join("\n")}</body></html>`);
for (let y = 0; y < 10; y++) {
for (let y = 0; y < 50; y++) {
console.log("starting y %s", y);
const bytes = htmlDoc.encodeHTML();
let tx = await con.transaction();
let tx = null;
console.log("got tx");
try {
tx = await con.transaction();
await tx.execute(`
INSERT INTO test(\`test\`, \`uuid\`, \`when\`, \`blob\`) VALUES('hi1', '0000-0000-0000-00000000-000000000000', CURDATE(), :data) ON DUPLICATE KEY UPDATE \`blob\` = :data, \`when\` = CURDATE()
`, {data: bytes});
Expand All @@ -1889,12 +1899,18 @@ pub mod tests {
console.log("got data %s c=%s l-%s", typeof returnData, returnData?.constructor?.name, returnData.length);
await tx.commit();
console.log("comitted");
} catch(ex) {
console.log("MySql fail: %s", ex);
console.error(ex);
await tx.rollback();
try {
await tx?.rollback();
} catch(ex) {
// care
}
} finally {
await tx.close();
await tx?.close();
}
}
Expand All @@ -1904,7 +1920,7 @@ pub mod tests {
async function test(){
await testPg();
//await testPg();
await testMySql();
Expand Down

0 comments on commit 0f59802

Please sign in to comment.