| 115 | |
| 116 | #[instrument(skip_all)] |
| 117 | pub async fn insert(ex: &mut PgConnection, jit_orders: &[JitOrder]) -> Result<(), sqlx::Error> { |
| 118 | if jit_orders.is_empty() { |
| 119 | return Ok(()); |
| 120 | } |
| 121 | |
| 122 | let mut query_builder = QueryBuilder::new( |
| 123 | r#" |
| 124 | INSERT INTO jit_orders ( |
| 125 | block_number, |
| 126 | log_index, |
| 127 | uid, |
| 128 | owner, |
| 129 | creation_timestamp, |
| 130 | sell_token, |
| 131 | buy_token, |
| 132 | sell_amount, |
| 133 | buy_amount, |
| 134 | valid_to, |
| 135 | app_data, |
| 136 | fee_amount, |
| 137 | kind, |
| 138 | partially_fillable, |
| 139 | signature, |
| 140 | receiver, |
| 141 | signing_scheme, |
| 142 | sell_token_balance, |
| 143 | buy_token_balance |
| 144 | ) |
| 145 | "#, |
| 146 | ); |
| 147 | |
| 148 | query_builder.push_values(jit_orders.iter(), |mut builder, jit_order| { |
| 149 | builder |
| 150 | .push_bind(jit_order.block_number) |
| 151 | .push_bind(jit_order.log_index) |
| 152 | .push_bind(jit_order.uid) |
| 153 | .push_bind(jit_order.owner) |
| 154 | .push_bind(jit_order.creation_timestamp) |
| 155 | .push_bind(jit_order.sell_token) |
| 156 | .push_bind(jit_order.buy_token) |
| 157 | .push_bind(jit_order.sell_amount.clone()) |
| 158 | .push_bind(jit_order.buy_amount.clone()) |
| 159 | .push_bind(jit_order.valid_to) |
| 160 | .push_bind(jit_order.app_data) |
| 161 | .push_bind(jit_order.fee_amount.clone()) |
| 162 | .push_bind(jit_order.kind) |
| 163 | .push_bind(jit_order.partially_fillable) |
| 164 | .push_bind(jit_order.signature.clone()) |
| 165 | .push_bind(jit_order.receiver) |
| 166 | .push_bind(jit_order.signing_scheme) |
| 167 | .push_bind(jit_order.sell_token_balance) |
| 168 | .push_bind(jit_order.buy_token_balance); |
| 169 | }); |
| 170 | |
| 171 | query_builder.push( |
| 172 | r#" |
| 173 | ON CONFLICT DO NOTHING"#, |
| 174 | ); |