MCPcopy Create free account
hub / github.com/hashintel/hash / create_base_url

Method create_base_url

libs/@local/graph/postgres-store/src/store/postgres/mod.rs:2472–2567  ·  view source on GitHub ↗
(
        &self,
        base_url: &BaseUrl,
        on_conflict: ConflictBehavior,
        location: OntologyLocation,
    )

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 13

ErrInterface · 0.85
OkInterface · 0.85
map_errMethod · 0.80
queryMethod · 0.80
as_clientMethod · 0.80
current_contextMethod · 0.80
getMethod · 0.65
as_strMethod · 0.45
codeMethod · 0.45
change_contextMethod · 0.45
attachMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected