dagger-components/crates/cuddle-ci/src/rust_service/sqlx.rs

46 lines
924 B
Rust
Raw Normal View History

use std::sync::Arc;
use async_trait::async_trait;
use dagger_sdk::Container;
use crate::dagger_middleware::DaggerMiddleware;
use super::RustService;
pub struct Sqlx {
client: dagger_sdk::Query,
}
impl Sqlx {
pub fn new(client: dagger_sdk::Query) -> Self {
Self { client }
}
}
#[async_trait]
impl DaggerMiddleware for Sqlx {
async fn handle(&self, container: Container) -> eyre::Result<Container> {
let src = self.client.host().directory(".sqlx/");
Ok(container
.with_directory(".sqlx", src)
.with_env_variable("SQLX_OFFLINE", "true"))
}
}
pub trait SqlxExt {
fn with_sqlx(&mut self) -> &mut Self {
self
}
}
impl SqlxExt for RustService {
fn with_sqlx(&mut self) -> &mut Self {
self.with_stage(super::RustServiceStage::BeforeBuild(Arc::new(Sqlx::new(
self.client.clone(),
))));
self
}
}