Skip to content

Commit e5257ca

Browse files
committed
Made Ability to register Several TableSchemas
1 parent e6c3293 commit e5257ca

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/my_postgres_builder.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{sync::Arc, time::Duration};
22

3-
use rust_extensions::{date_time::DateTimeAsMicroseconds, StrOrString};
3+
use rust_extensions::{date_time::DateTimeAsMicroseconds, lazy::LazyVec, StrOrString};
44

55
use crate::{
66
table_schema::{PrimaryKeySchema, TableSchema, TableSchemaProvider},
@@ -11,14 +11,14 @@ pub enum MyPostgresBuilder {
1111
AsSettings {
1212
postgres_settings: Arc<dyn PostgresSettings + Sync + Send + 'static>,
1313
app_name: String,
14-
table_schema_data: Option<TableSchema>,
14+
table_schema_data: LazyVec<TableSchema>,
1515
sql_request_timeout: Duration,
1616
#[cfg(feature = "with-logs-and-telemetry")]
1717
logger: Arc<dyn rust_extensions::Logger + Send + Sync + 'static>,
1818
},
1919
AsSharedConnection {
2020
connection: Arc<PostgresConnection>,
21-
table_schema_data: Option<TableSchema>,
21+
table_schema_data: LazyVec<TableSchema>,
2222
sql_request_timeout: Duration,
2323
},
2424
}
@@ -36,7 +36,7 @@ impl MyPostgresBuilder {
3636
Self::AsSettings {
3737
app_name: app_name.to_string(),
3838
postgres_settings,
39-
table_schema_data: None,
39+
table_schema_data: LazyVec::new(),
4040
sql_request_timeout: Duration::from_secs(5),
4141
#[cfg(feature = "with-logs-and-telemetry")]
4242
logger,
@@ -45,7 +45,7 @@ impl MyPostgresBuilder {
4545
pub fn from_connection(connection: Arc<PostgresConnection>) -> Self {
4646
Self::AsSharedConnection {
4747
connection,
48-
table_schema_data: None,
48+
table_schema_data: LazyVec::new(),
4949
sql_request_timeout: Duration::from_secs(5),
5050
}
5151
}
@@ -96,10 +96,10 @@ impl MyPostgresBuilder {
9696
match &mut self {
9797
MyPostgresBuilder::AsSettings {
9898
table_schema_data, ..
99-
} => *table_schema_data = Some(table_schema),
99+
} => table_schema_data.add(table_schema),
100100
MyPostgresBuilder::AsSharedConnection {
101101
table_schema_data, ..
102-
} => *table_schema_data = Some(table_schema),
102+
} => table_schema_data.add(table_schema),
103103
}
104104

105105
self
@@ -110,7 +110,7 @@ impl MyPostgresBuilder {
110110
MyPostgresBuilder::AsSettings {
111111
postgres_settings,
112112
app_name,
113-
mut table_schema_data,
113+
table_schema_data,
114114
sql_request_timeout,
115115
#[cfg(feature = "with-logs-and-telemetry")]
116116
logger,
@@ -125,19 +125,23 @@ impl MyPostgresBuilder {
125125

126126
let connection = Arc::new(PostgresConnection::Single(connection));
127127

128-
if let Some(table_schema) = table_schema_data.take() {
129-
check_table_schema(&connection, table_schema).await;
128+
if let Some(table_schema_data) = table_schema_data.get_result() {
129+
for table_schema in table_schema_data {
130+
check_table_schema(&connection, table_schema).await;
131+
}
130132
}
131133

132134
MyPostgres::create(connection, sql_request_timeout)
133135
}
134136
MyPostgresBuilder::AsSharedConnection {
135137
connection,
136-
mut table_schema_data,
138+
table_schema_data,
137139
sql_request_timeout,
138140
} => {
139-
if let Some(table_schema) = table_schema_data.take() {
140-
check_table_schema(&connection, table_schema).await;
141+
if let Some(table_schema_data) = table_schema_data.get_result() {
142+
for table_schema in table_schema_data {
143+
check_table_schema(&connection, table_schema).await;
144+
}
141145
}
142146
MyPostgres::create(connection, sql_request_timeout)
143147
}

0 commit comments

Comments
 (0)