(
&self,
base_url: &BaseUrl,
on_conflict: ConflictBehavior,
location: OntologyLocation,
)
| 2470 | } |
| 2471 | |
| 2472 | async fn create_base_url( |
| 2473 | &self, |
| 2474 | base_url: &BaseUrl, |
| 2475 | on_conflict: ConflictBehavior, |
| 2476 | location: OntologyLocation, |
| 2477 | ) -> Result<(), Report<InsertionError>> { |
| 2478 | match on_conflict { |
| 2479 | ConflictBehavior::Fail => { |
| 2480 | self.as_client() |
| 2481 | .query( |
| 2482 | "INSERT INTO base_urls (base_url) VALUES ($1);", |
| 2483 | &[&base_url.as_str()], |
| 2484 | ) |
| 2485 | .instrument(tracing::info_span!( |
| 2486 | "INSERT", |
| 2487 | otel.kind = "client", |
| 2488 | db.system = "postgresql", |
| 2489 | peer.service = "Postgres" |
| 2490 | )) |
| 2491 | .await |
| 2492 | .map_err(Report::new) |
| 2493 | .map_err(|report| match report.current_context().code() { |
| 2494 | Some(&SqlState::UNIQUE_VIOLATION) => report |
| 2495 | .change_context(BaseUrlAlreadyExists) |
| 2496 | .attach(base_url.clone()) |
| 2497 | .change_context(InsertionError), |
| 2498 | _ => report |
| 2499 | .change_context(InsertionError) |
| 2500 | .attach(base_url.clone()), |
| 2501 | })?; |
| 2502 | } |
| 2503 | ConflictBehavior::Skip => { |
| 2504 | let created = self |
| 2505 | .as_client() |
| 2506 | .query_opt( |
| 2507 | " |
| 2508 | INSERT INTO base_urls (base_url) VALUES ($1) |
| 2509 | ON CONFLICT DO NOTHING |
| 2510 | RETURNING 1; |
| 2511 | ", |
| 2512 | &[&base_url.as_str()], |
| 2513 | ) |
| 2514 | .instrument(tracing::info_span!( |
| 2515 | "INSERT", |
| 2516 | otel.kind = "client", |
| 2517 | db.system = "postgresql", |
| 2518 | peer.service = "Postgres" |
| 2519 | )) |
| 2520 | .await |
| 2521 | .change_context(InsertionError)? |
| 2522 | .is_some(); |
| 2523 | |
| 2524 | if !created { |
| 2525 | let query = match location { |
| 2526 | OntologyLocation::Owned => { |
| 2527 | " |
| 2528 | SELECT EXISTS (SELECT 1 |
| 2529 | FROM ontology_owned_metadata |
no test coverage detected