(
&self,
uid: Option<String>,
owner: &UserId,
object: &Object,
attributes: &Attributes,
tags: &HashSet<String>,
)
| 668 | #[async_trait(?Send)] |
| 669 | impl ObjectsStore for PgPool { |
| 670 | async fn create( |
| 671 | &self, |
| 672 | uid: Option<String>, |
| 673 | owner: &UserId, |
| 674 | object: &Object, |
| 675 | attributes: &Attributes, |
| 676 | tags: &HashSet<String>, |
| 677 | ) -> InterfaceResult<String> { |
| 678 | async fn transact( |
| 679 | tx: &deadpool_postgres::Transaction<'_>, |
| 680 | uid: &str, |
| 681 | owner: &str, |
| 682 | object: &Object, |
| 683 | attributes: &Attributes, |
| 684 | tags: &HashSet<String>, |
| 685 | ) -> DbResult<String> { |
| 686 | let object_json = serde_json::to_string(object).map_err(DbError::from)?; |
| 687 | let attrs_param = Json(attributes); |
| 688 | let state = attributes.state.unwrap_or(State::PreActive).to_string(); |
| 689 | let wrapping_key_id = object.wrapping_key_uid(); |
| 690 | let stmt = tx |
| 691 | .prepare_cached(get_pgsql_query!("insert-objects")) |
| 692 | .await |
| 693 | .map_err(DbError::from)?; |
| 694 | tx.execute( |
| 695 | &stmt, |
| 696 | &[ |
| 697 | &uid, |
| 698 | &object_json, |
| 699 | &attrs_param, |
| 700 | &state, |
| 701 | &owner, |
| 702 | &wrapping_key_id, |
| 703 | ], |
| 704 | ) |
| 705 | .await |
| 706 | .map_err(DbError::from)?; |
| 707 | if !tags.is_empty() { |
| 708 | let transaction_stmt = tx |
| 709 | .prepare_cached(get_pgsql_query!("insert-tags")) |
| 710 | .await |
| 711 | .map_err(DbError::from)?; |
| 712 | for tag in tags { |
| 713 | tx.execute(&transaction_stmt, &[&uid, tag]) |
| 714 | .await |
| 715 | .map_err(DbError::from)?; |
| 716 | } |
| 717 | } |
| 718 | Ok(uid.to_owned()) |
| 719 | } |
| 720 | |
| 721 | let uid = uid.unwrap_or_else(|| Uuid::new_v4().to_string()); |
| 722 | pg_retry_tx!(self.pool, |tx| { |
| 723 | transact(&tx, &uid, owner, object, attributes, tags).await |
| 724 | }) |
| 725 | } |
| 726 | |
| 727 | async fn retrieve(&self, uid: &str) -> InterfaceResult<Option<ObjectWithMetadata>> { |
nothing calls this directly
no outgoing calls
no test coverage detected