@@ -382,68 +382,8 @@ impl Db for PgDb {
382382 let sortindex = bso. sortindex ;
383383 let ttl = bso. ttl . map_or ( DEFAULT_BSO_TTL , |ttl| ttl) ;
384384
385- // This method is an upsert operation, which allows the update of an existing row
386- // or inserts a new one if it doesn’t exist. Postgres does not have `UPSERT` but
387- // achieves this though `INSERT...ON CONFLICT`.
388- // let q: String = r#"
389- // INSERT INTO bso (user_id, collection_id, bso_id, sortindex, payload, modified, expiry)
390- // VALUES ($1, $2, $3, $4, $5, $6, $7)
391- // ON CONFLICT (user_id, collection_id, bso_id)
392- // DO UPDATE SET
393- // user_id = EXCLUDED.user_id,
394- // collection_id = EXCLUDED.collection_id,
395- // bso_id = EXCLUDED.bso_id,
396- // "#
397- // .to_string();
398-
399- // let q = format!(
400- // "{}{}",
401- // q,
402- // if bso.sortindex.is_some() {
403- // ", sortindex = VALUES(sortindex)"
404- // } else {
405- // ""
406- // },
407- // );
408- // let q = format!(
409- // "{}{}",
410- // q,
411- // if bso.payload.is_some() {
412- // ", payload = VALUES(payload)"
413- // } else {
414- // ""
415- // },
416- // );
417- // let q = format!(
418- // "{}{}",
419- // q,
420- // if bso.ttl.is_some() {
421- // "expiry = VALUES(expiry)"
422- // } else {
423- // ""
424- // },
425- // );
426- // let q = format!(
427- // "{}{}",
428- // q,
429- // if bso.payload.is_some() || bso.sortindex.is_some() {
430- // "modified = VALUES(modified)"
431- // } else {
432- // ""
433- // },
434- // );
435- // sql_query(q)
436- // .bind::<BigInt, _>(user_id as i64) // XXX:
437- // .bind::<Integer, _>(&collection_id)
438- // .bind::<Text, _>(&bso.id)
439- // .bind::<Nullable<Integer>, _>(sortindex)
440- // .bind::<Text, _>(payload)
441- // .bind::<BigInt, _>(timestamp)
442- // .bind::<BigInt, _>(timestamp + (i64::from(ttl) * 1000)) // remember: this is in millis
443- // .execute(&mut self.conn)
444- // .await?;
445-
446- let expiry_ts = SyncTimestamp :: from_i64 ( timestamp + ( i64:: from ( ttl) * 1000 ) ) ?; // remember: original milli conversion
385+ // original required millisecond conversion
386+ let expiry_ts = SyncTimestamp :: from_i64 ( timestamp + ( i64:: from ( ttl) * 1000 ) ) ?;
447387 let modified_ts = SyncTimestamp :: from_i64 ( timestamp) ?;
448388
449389 let expiry_dt = expiry_ts. as_naive_datetime ( ) ?;
@@ -480,8 +420,8 @@ impl Db for PgDb {
480420 bsos:: bso_id. eq ( & bso. id ) ,
481421 bsos:: sortindex. eq ( sortindex) ,
482422 bsos:: payload. eq ( payload) ,
483- bsos:: modified. eq ( modified_ts . as_naive_datetime ( ) ? ) ,
484- bsos:: expiry. eq ( expiry_ts . as_naive_datetime ( ) ? ) ,
423+ bsos:: modified. eq ( modified_dt ) ,
424+ bsos:: expiry. eq ( expiry_dt ) ,
485425 ) )
486426 . on_conflict ( ( bsos:: user_id, bsos:: collection_id, bsos:: bso_id) )
487427 . do_update ( )
0 commit comments