-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow configuring of replicator images
- Loading branch information
Showing
8 changed files
with
129 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
create table | ||
public.images ( | ||
id bigint generated always as identity primary key, | ||
image_name text not null, | ||
is_default boolean not null | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use sqlx::{PgPool, Postgres, Transaction}; | ||
|
||
pub struct Image { | ||
pub id: i64, | ||
pub image_name: String, | ||
pub is_default: bool, | ||
} | ||
|
||
pub async fn create_image( | ||
pool: &PgPool, | ||
image_name: &str, | ||
is_default: bool, | ||
) -> Result<i64, sqlx::Error> { | ||
let mut txn = pool.begin().await?; | ||
let res = create_image_txn(&mut txn, image_name, is_default).await; | ||
txn.commit().await?; | ||
res | ||
} | ||
|
||
pub async fn create_image_txn( | ||
txn: &mut Transaction<'_, Postgres>, | ||
image_name: &str, | ||
is_default: bool, | ||
) -> Result<i64, sqlx::Error> { | ||
let record = sqlx::query!( | ||
r#" | ||
insert into images (image_name, is_default) | ||
values ($1, $2) | ||
returning id | ||
"#, | ||
image_name, | ||
is_default | ||
) | ||
.fetch_one(&mut **txn) | ||
.await?; | ||
|
||
Ok(record.id) | ||
} | ||
|
||
pub async fn read_default_image(pool: &PgPool) -> Result<Option<Image>, sqlx::Error> { | ||
let record = sqlx::query!( | ||
r#" | ||
select id, image_name, is_default | ||
from images | ||
where is_default = true | ||
"#, | ||
) | ||
.fetch_optional(pool) | ||
.await?; | ||
|
||
Ok(record.map(|r| Image { | ||
id: r.id, | ||
image_name: r.image_name, | ||
is_default: r.is_default, | ||
})) | ||
} | ||
|
||
pub async fn read_image_by_replicator_id( | ||
pool: &PgPool, | ||
replicator_id: i64, | ||
) -> Result<Option<Image>, sqlx::Error> { | ||
let record = sqlx::query!( | ||
r#" | ||
select i.id, i.image_name, i.is_default | ||
from images i | ||
join replicators r on i.id = r.image_id | ||
where r.id = $1 | ||
"#, | ||
replicator_id, | ||
) | ||
.fetch_optional(pool) | ||
.await?; | ||
|
||
Ok(record.map(|r| Image { | ||
id: r.id, | ||
image_name: r.image_name, | ||
is_default: r.is_default, | ||
})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ pub mod sinks; | |
pub mod sources; | ||
pub mod tables; | ||
pub mod tenants; | ||
pub mod images; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters