2023-11-27 20:11:49 +01:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2023-11-26 22:19:34 +01:00
|
|
|
use async_trait::async_trait;
|
|
|
|
use dagger_sdk::Container;
|
|
|
|
|
|
|
|
use crate::dagger_middleware::DaggerMiddleware;
|
|
|
|
|
2023-11-27 13:52:11 +01:00
|
|
|
use super::RustService;
|
|
|
|
|
2023-11-27 14:15:43 +01:00
|
|
|
pub struct Sqlx {
|
|
|
|
client: dagger_sdk::Query,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Sqlx {
|
|
|
|
pub fn new(client: dagger_sdk::Query) -> Self {
|
|
|
|
Self { client }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-26 22:19:34 +01:00
|
|
|
#[async_trait]
|
|
|
|
impl DaggerMiddleware for Sqlx {
|
|
|
|
async fn handle(&self, container: Container) -> eyre::Result<Container> {
|
2023-11-27 14:15:43 +01:00
|
|
|
let src = self.client.host().directory(".sqlx/");
|
|
|
|
|
|
|
|
Ok(container
|
|
|
|
.with_directory(".sqlx", src)
|
|
|
|
.with_env_variable("SQLX_OFFLINE", "true"))
|
2023-11-26 22:19:34 +01:00
|
|
|
}
|
|
|
|
}
|
2023-11-27 13:52:11 +01:00
|
|
|
|
|
|
|
pub trait SqlxExt {
|
|
|
|
fn with_sqlx(&mut self) -> &mut Self {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SqlxExt for RustService {
|
|
|
|
fn with_sqlx(&mut self) -> &mut Self {
|
2023-11-27 20:11:49 +01:00
|
|
|
self.with_stage(super::RustServiceStage::BeforeBuild(Arc::new(Sqlx::new(
|
2023-11-27 14:15:43 +01:00
|
|
|
self.client.clone(),
|
|
|
|
))));
|
2023-11-27 13:52:11 +01:00
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|