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],
)
| 5 | /// If this contract app data already existed then the existing full app data is |
| 6 | /// returned, otherwise `None` is returned. |
| 7 | pub 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#" |
| 13 | WITH 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 | ) |
| 21 | SELECT |
| 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 | |
| 36 | pub async fn fetch( |
| 37 | ex: &mut PgConnection, |
no outgoing calls
no test coverage detected