Skip to content

Commit

Permalink
update to sqlx 0.7
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed May 23, 2024
1 parent d0fa194 commit c65b8c6
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 152 deletions.
309 changes: 184 additions & 125 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ warp = { version = "0.3.7", features = ["tls"] }
tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread", "signal"] }
futures = "0.3.30"
log = "0.4.21"
sqlx-oldapi = { version = "0.6.20", features = ["runtime-tokio-rustls", "any", "mysql", "sqlite", "postgres"] }
sqlx = { version = "0.7.4", features = ["runtime-tokio-rustls", "any", "mysql", "sqlite", "postgres"] }
dotenvy = "0.15.7"
dashmap = "5.5.3"
once_cell = "1.19.0"
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use clap::builder::Styles;
use clap::Parser;
use derivative::Derivative;
use redis::ConnectionInfo;
use sqlx_oldapi::any::AnyConnectOptions;
use sqlx::any::AnyConnectOptions;
use std::convert::{TryFrom, TryInto};
use std::env::var;
use std::fmt::{Display, Formatter};
Expand Down
6 changes: 3 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ pub enum NextCloudError {
#[derive(Debug, Error, Diagnostic)]
pub enum DatabaseError {
#[error("Failed to connect to database: {0}")]
Connect(#[source] sqlx_oldapi::Error),
Connect(#[source] sqlx::Error),
#[error("Failed to query database: {0}")]
Query(#[source] sqlx_oldapi::Error),
Query(#[source] sqlx::Error),
}

#[derive(Debug, Error, Diagnostic)]
Expand Down Expand Up @@ -97,7 +97,7 @@ pub enum ConfigError {
#[error("Failed to parse log level: {0}")]
LogLevel(#[from] FlexiLoggerError),
#[error("Failed to parse database configuration: {0:#}")]
InvalidDatabase(#[from] sqlx_oldapi::Error),
InvalidDatabase(#[from] sqlx::Error),
}

#[derive(Debug, Error, Diagnostic)]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use futures::future::{select, Either};
use futures::StreamExt;
use futures::{pin_mut, FutureExt};
use smallvec::alloc::sync::Arc;
use sqlx_oldapi::AnyPool;
use sqlx::AnyPool;
use std::convert::Infallible;
use std::fs;
use std::future::Future;
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use tokio::task::spawn;

fn main() -> Result<()> {
miette::set_panic_hook();
sqlx::any::install_default_drivers();
let _ = dotenvy::dotenv();

let opt: Opt = Opt::parse();
Expand Down
4 changes: 2 additions & 2 deletions src/storage_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use dashmap::mapref::one::Ref;
use dashmap::DashMap;
use log::debug;
use rand::{thread_rng, Rng};
use sqlx_oldapi::any::AnyConnectOptions;
use sqlx_oldapi::{query_as, Any, AnyPool, FromRow};
use sqlx::any::AnyConnectOptions;
use sqlx::{query_as, Any, AnyPool, FromRow};
use std::time::Instant;
use tokio::time::Duration;

Expand Down
6 changes: 3 additions & 3 deletions src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use once_cell::race::OnceBox;
use once_cell::sync::Lazy;
use serde::de::{Error, Visitor};
use serde::{Deserialize, Deserializer};
use sqlx_oldapi::database::HasValueRef;
use sqlx_oldapi::error::BoxDynError;
use sqlx_oldapi::{Database, Decode, Type};
use sqlx::database::HasValueRef;
use sqlx::error::BoxDynError;
use sqlx::{Database, Decode, Type};
use std::fmt;
use std::hash::{BuildHasher, Hasher};

Expand Down
35 changes: 19 additions & 16 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use notify_push::{listen_loop, serve, App};
use once_cell::sync::Lazy;
use redis::AsyncCommands;
use smallvec::alloc::sync::Arc;
use sqlx_oldapi::AnyPool;
use sqlx::AnyPool;
use std::net::SocketAddr;
use std::sync::atomic::{AtomicU16, Ordering};
use tokio::net::{TcpListener, TcpStream};
Expand Down Expand Up @@ -51,6 +51,7 @@ static LOG_HANDLE: Lazy<LoggerHandle> =

impl Services {
pub async fn new() -> Self {
sqlx::any::install_default_drivers();
DEBOUNCE_ENABLE.store(false, Ordering::SeqCst);
let redis_tcp = listen_available_port()
.await
Expand All @@ -66,29 +67,31 @@ impl Services {
.local_addr()
.expect("Failed to get nextcloud mock socket address");

let db = AnyPool::connect("sqlite::memory:?cache=shared")
.await
.expect("Failed to connect sqlite database");
// use the port in the db name to prevent collisions
let db = AnyPool::connect(&format!(
"sqlite:file:memory{}?mode=memory&cache=shared",
nextcloud_addr.port()
))
.await
.expect("Failed to connect sqlite database");

sqlx_oldapi::query("CREATE TABLE oc_filecache(fileid BIGINT, path TEXT)")
sqlx::query("CREATE TABLE oc_filecache(fileid BIGINT, path TEXT)")
.execute(&db)
.await
.unwrap();
sqlx_oldapi::query("CREATE INDEX fc_id ON oc_filecache (fileid)")
sqlx::query("CREATE INDEX fc_id ON oc_filecache (fileid)")
.execute(&db)
.await
.unwrap();
sqlx_oldapi::query(
"CREATE TABLE oc_mounts(storage_id BIGINT, root_id BIGINT, user_id TEXT)",
)
.execute(&db)
.await
.unwrap();
sqlx_oldapi::query("CREATE INDEX mount_storage ON oc_mounts (storage_id)")
sqlx::query("CREATE TABLE oc_mounts(storage_id BIGINT, root_id BIGINT, user_id TEXT)")
.execute(&db)
.await
.unwrap();
sqlx::query("CREATE INDEX mount_storage ON oc_mounts (storage_id)")
.execute(&db)
.await
.unwrap();
sqlx_oldapi::query("CREATE INDEX mount_root ON oc_mounts (root_id)")
sqlx::query("CREATE INDEX mount_root ON oc_mounts (root_id)")
.execute(&db)
.await
.unwrap();
Expand Down Expand Up @@ -207,7 +210,7 @@ impl Services {
}

async fn add_storage_mapping(&self, username: &str, storage: u32, root: u32) {
sqlx_oldapi::query("INSERT INTO oc_mounts(storage_id, root_id, user_id) VALUES(?, ?, ?)")
sqlx::query("INSERT INTO oc_mounts(storage_id, root_id, user_id) VALUES(?, ?, ?)")
.bind(storage as i64)
.bind(root as i64)
.bind(username)
Expand All @@ -217,7 +220,7 @@ impl Services {
}

async fn add_filecache_item(&self, fileid: u32, path: &str) {
sqlx_oldapi::query("INSERT INTO oc_filecache(fileid, path) VALUES(?, ?)")
sqlx::query("INSERT INTO oc_filecache(fileid, path) VALUES(?, ?)")
.bind(fileid as i64)
.bind(path)
.execute(&self.db)
Expand Down

0 comments on commit c65b8c6

Please sign in to comment.