Total WIP - try making Db a generic struct instead of a trait

This commit is contained in:
Max Brunsfeld 2022-11-09 19:28:06 -08:00
parent 7e02ac772a
commit bed06346d1
4 changed files with 133 additions and 902 deletions

View file

@ -75,7 +75,7 @@ pub async fn validate_header<B>(mut req: Request<B>, next: Next<B>) -> impl Into
const MAX_ACCESS_TOKENS_TO_STORE: usize = 8;
pub async fn create_access_token(db: &dyn db::Db, user_id: UserId) -> Result<String> {
pub async fn create_access_token(db: &db::DefaultDb, user_id: UserId) -> Result<String> {
let access_token = rpc::auth::random_token();
let access_token_hash =
hash_access_token(&access_token).context("failed to hash access token")?;

File diff suppressed because it is too large Load diff

View file

@ -625,7 +625,7 @@ async fn test_fuzzy_search_users() {
&["rhode-island", "colorado", "oregon"],
);
async fn fuzzy_search_user_names(db: &Arc<dyn Db>, query: &str) -> Vec<String> {
async fn fuzzy_search_user_names(db: &Arc<TestDb>, query: &str) -> Vec<String> {
db.fuzzy_search_users(query, 10)
.await
.unwrap()

View file

@ -13,7 +13,7 @@ use crate::rpc::ResultExt as _;
use anyhow::anyhow;
use axum::{routing::get, Router};
use collab::{Error, Result};
use db::{Db, RealDb};
use db::DefaultDb as Db;
use serde::Deserialize;
use std::{
env::args,
@ -49,14 +49,14 @@ pub struct MigrateConfig {
}
pub struct AppState {
db: Arc<dyn Db>,
db: Arc<Db>,
live_kit_client: Option<Arc<dyn live_kit_server::api::Client>>,
config: Config,
}
impl AppState {
async fn new(config: Config) -> Result<Arc<Self>> {
let db = RealDb::new(&config.database_url, 5).await?;
let db = Db::new(&config.database_url, 5).await?;
let live_kit_client = if let Some(((server, key), secret)) = config
.live_kit_server
.as_ref()
@ -96,7 +96,7 @@ async fn main() -> Result<()> {
}
Some("migrate") => {
let config = envy::from_env::<MigrateConfig>().expect("error loading config");
let db = RealDb::new(&config.database_url, 5).await?;
let db = Db::new(&config.database_url, 5).await?;
let migrations_path = config
.migrations_path