MCPcopy Create free account
hub / github.com/cowprotocol/services / insert

Function insert

crates/database/src/app_data.rs:7–34  ·  view source on GitHub ↗

Tries to associate the contract app data with the full app data. If this contract app data already existed then the existing full app data is returned, otherwise `None` is returned.

(
    ex: &mut PgConnection,
    contract_app_data: &AppId,
    full_app_data: &[u8],
)

Source from the content-addressed store, hash-verified

5/// If this contract app data already existed then the existing full app data is
6/// returned, otherwise `None` is returned.
7pub async fn insert(
8 ex: &mut PgConnection,
9 contract_app_data: &AppId,
10 full_app_data: &[u8],
11) -> Result<Option<Vec<u8>>, sqlx::Error> {
12 const QUERY: &str = r#"
13WITH inserted AS (
14 INSERT INTO app_data (contract_app_data, full_app_data)
15 VALUES ($1, $2)
16 -- returns null on conflict
17 ON CONFLICT DO NOTHING
18 -- returns TRUE if the insertion succeeded
19 RETURNING TRUE
20)
21SELECT
22 CASE
23 WHEN (SELECT * FROM inserted) THEN
24 NULL
25 ELSE
26 (SELECT full_app_data FROM app_data WHERE contract_app_data = $1)
27 END
28;"#;
29 sqlx::query_scalar(QUERY)
30 .bind(contract_app_data)
31 .bind(full_app_data)
32 .fetch_one(ex)
33 .await
34}
35
36pub async fn fetch(
37 ex: &mut PgConnection,

Callers 10

postgres_order_app_dataFunction · 0.70
postgres_load_by_idFunction · 0.70
postgres_app_dataFunction · 0.70
save_settlementMethod · 0.50
save_competitionMethod · 0.50
insert_order_app_dataMethod · 0.50
insert_full_app_dataMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected