chore: publish clean community baseline
This commit is contained in:
commit
ba29ac7b94
320 files changed
+73936
No files matched your search
@@ -0,0 +1,106 @@
|
||||
use super::*;
|
||||
|
||||
impl PostgresRegistry {
|
||||
pub async fn list_workspace_upstreams(
|
||||
&self,
|
||||
workspace_id: &WorkspaceId,
|
||||
) -> Result<Vec<WorkspaceUpstream>, RegistryError> {
|
||||
let rows = sqlx::query(
|
||||
"select
|
||||
id,
|
||||
workspace_id,
|
||||
name,
|
||||
base_url,
|
||||
static_headers_json,
|
||||
auth_profile_id,
|
||||
created_at,
|
||||
updated_at
|
||||
from workspace_upstreams
|
||||
where workspace_id = $1
|
||||
order by name asc",
|
||||
)
|
||||
.bind(workspace_id.as_str())
|
||||
.fetch_all(&self.pool)
|
||||
.await?;
|
||||
|
||||
rows.into_iter().map(build_workspace_upstream).collect()
|
||||
}
|
||||
|
||||
pub async fn get_workspace_upstream(
|
||||
&self,
|
||||
workspace_id: &WorkspaceId,
|
||||
upstream_id: &crate::WorkspaceUpstreamId,
|
||||
) -> Result<Option<WorkspaceUpstream>, RegistryError> {
|
||||
let row = sqlx::query(
|
||||
"select
|
||||
id,
|
||||
workspace_id,
|
||||
name,
|
||||
base_url,
|
||||
static_headers_json,
|
||||
auth_profile_id,
|
||||
created_at,
|
||||
updated_at
|
||||
from workspace_upstreams
|
||||
where workspace_id = $1 and id = $2",
|
||||
)
|
||||
.bind(workspace_id.as_str())
|
||||
.bind(upstream_id.as_str())
|
||||
.fetch_optional(&self.pool)
|
||||
.await?;
|
||||
|
||||
row.map(build_workspace_upstream).transpose()
|
||||
}
|
||||
|
||||
pub async fn save_workspace_upstream(
|
||||
&self,
|
||||
request: SaveWorkspaceUpstreamRequest<'_>,
|
||||
) -> Result<(), RegistryError> {
|
||||
sqlx::query(
|
||||
"insert into workspace_upstreams (
|
||||
id,
|
||||
workspace_id,
|
||||
name,
|
||||
base_url,
|
||||
static_headers_json,
|
||||
auth_profile_id,
|
||||
created_at,
|
||||
updated_at
|
||||
) values (
|
||||
$1, $2, $3, $4, $5, $6, $7::timestamptz, $8::timestamptz
|
||||
)
|
||||
on conflict(id) do update set
|
||||
workspace_id = excluded.workspace_id,
|
||||
name = excluded.name,
|
||||
base_url = excluded.base_url,
|
||||
static_headers_json = excluded.static_headers_json,
|
||||
auth_profile_id = excluded.auth_profile_id,
|
||||
updated_at = excluded.updated_at",
|
||||
)
|
||||
.bind(request.upstream.id.as_str())
|
||||
.bind(request.upstream.workspace_id.as_str())
|
||||
.bind(&request.upstream.name)
|
||||
.bind(&request.upstream.base_url)
|
||||
.bind(Json(request.upstream.static_headers.clone()))
|
||||
.bind(request.upstream.auth_profile_id.as_deref())
|
||||
.bind(request.upstream.created_at)
|
||||
.bind(request.upstream.updated_at)
|
||||
.execute(&self.pool)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn build_workspace_upstream(row: PgRow) -> Result<WorkspaceUpstream, RegistryError> {
|
||||
Ok(WorkspaceUpstream {
|
||||
id: crate::WorkspaceUpstreamId::new(row.try_get::<String, _>("id")?),
|
||||
workspace_id: WorkspaceId::new(row.try_get::<String, _>("workspace_id")?),
|
||||
name: row.try_get("name")?,
|
||||
base_url: row.try_get("base_url")?,
|
||||
static_headers: row.try_get::<Json<Value>, _>("static_headers_json")?.0,
|
||||
auth_profile_id: row.try_get("auth_profile_id")?,
|
||||
created_at: row.try_get("created_at")?,
|
||||
updated_at: row.try_get("updated_at")?,
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user