Skip to content

Commit e82310a

Browse files
committed
Impl Deref for database connection enums
1 parent b03457b commit e82310a

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

rust/operator-binary/src/airflow_controller.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,6 @@ pub async fn reconcile_airflow(
414414
.spec
415415
.cluster_config
416416
.metadata_database
417-
.as_sqlalchemy_database_connection()
418417
.sqlalchemy_connection_details_with_templating("METADATA", &templating_mechanism);
419418
let celery_database_connection_details = match &airflow.spec.executor {
420419
AirflowExecutor::CeleryExecutors {
@@ -423,13 +422,11 @@ pub async fn reconcile_airflow(
423422
..
424423
} => {
425424
let celery_result_backend = celery_result_backend
426-
.as_celery_database_connection()
427425
.celery_connection_details_with_templating(
428426
"CELERY_RESULT_BACKEND",
429427
&templating_mechanism,
430428
);
431429
let celery_broker = celery_broker
432-
.as_celery_database_connection()
433430
.celery_connection_details_with_templating("CELERY_BROKER", &templating_mechanism);
434431
Some((celery_result_backend, celery_broker))
435432
}

rust/operator-binary/src/crd/databases.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::ops::Deref;
2+
13
use serde::{Deserialize, Serialize};
24
use stackable_operator::{
35
database_connections::{
@@ -20,8 +22,10 @@ pub enum MetadataDatabaseConnection {
2022
Generic(GenericSqlAlchemyDatabaseConnection),
2123
}
2224

23-
impl MetadataDatabaseConnection {
24-
pub fn as_sqlalchemy_database_connection(&self) -> &dyn SqlAlchemyDatabaseConnection {
25+
impl Deref for MetadataDatabaseConnection {
26+
type Target = dyn SqlAlchemyDatabaseConnection;
27+
28+
fn deref(&self) -> &Self::Target {
2529
match self {
2630
Self::Postgresql(p) => p,
2731
Self::Generic(g) => g,
@@ -39,8 +43,10 @@ pub enum CeleryResultBackendConnection {
3943
Generic(GenericCeleryDatabaseConnection),
4044
}
4145

42-
impl CeleryResultBackendConnection {
43-
pub fn as_celery_database_connection(&self) -> &dyn CeleryDatabaseConnection {
46+
impl Deref for CeleryResultBackendConnection {
47+
type Target = dyn CeleryDatabaseConnection;
48+
49+
fn deref(&self) -> &Self::Target {
4450
match self {
4551
Self::Postgresql(p) => p,
4652
Self::Generic(g) => g,
@@ -58,8 +64,10 @@ pub enum CeleryBrokerConnection {
5864
Generic(GenericCeleryDatabaseConnection),
5965
}
6066

61-
impl CeleryBrokerConnection {
62-
pub fn as_celery_database_connection(&self) -> &dyn CeleryDatabaseConnection {
67+
impl Deref for CeleryBrokerConnection {
68+
type Target = dyn CeleryDatabaseConnection;
69+
70+
fn deref(&self) -> &Self::Target {
6371
match self {
6472
Self::Redis(r) => r,
6573
Self::Generic(g) => g,

0 commit comments

Comments
 (0)