Total WIP - try making Db a generic struct instead of a trait
This commit is contained in:
parent
7e02ac772a
commit
bed06346d1
4 changed files with 133 additions and 902 deletions
|
@ -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;
|
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 = rpc::auth::random_token();
|
||||||
let access_token_hash =
|
let access_token_hash =
|
||||||
hash_access_token(&access_token).context("failed to hash access token")?;
|
hash_access_token(&access_token).context("failed to hash access token")?;
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -625,7 +625,7 @@ async fn test_fuzzy_search_users() {
|
||||||
&["rhode-island", "colorado", "oregon"],
|
&["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)
|
db.fuzzy_search_users(query, 10)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
@ -13,7 +13,7 @@ use crate::rpc::ResultExt as _;
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use axum::{routing::get, Router};
|
use axum::{routing::get, Router};
|
||||||
use collab::{Error, Result};
|
use collab::{Error, Result};
|
||||||
use db::{Db, RealDb};
|
use db::DefaultDb as Db;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{
|
use std::{
|
||||||
env::args,
|
env::args,
|
||||||
|
@ -49,14 +49,14 @@ pub struct MigrateConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
db: Arc<dyn Db>,
|
db: Arc<Db>,
|
||||||
live_kit_client: Option<Arc<dyn live_kit_server::api::Client>>,
|
live_kit_client: Option<Arc<dyn live_kit_server::api::Client>>,
|
||||||
config: Config,
|
config: Config,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppState {
|
impl AppState {
|
||||||
async fn new(config: Config) -> Result<Arc<Self>> {
|
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
|
let live_kit_client = if let Some(((server, key), secret)) = config
|
||||||
.live_kit_server
|
.live_kit_server
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -96,7 +96,7 @@ async fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
Some("migrate") => {
|
Some("migrate") => {
|
||||||
let config = envy::from_env::<MigrateConfig>().expect("error loading config");
|
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
|
let migrations_path = config
|
||||||
.migrations_path
|
.migrations_path
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue