Fixed upsert query

This commit is contained in:
Paul Trudel 2023-08-10 18:07:59 +00:00
parent 3d86f0fd5a
commit 8fcbfcf76e

View File

@ -21,30 +21,17 @@ class AudioCaptionTableDef(tag: Tag) extends Table[AudioCaptionDbModel](tag, Non
object AudioCaptionDAO {
def insertOrUpdateAudioCaption(transcriptId: String, meetingId: String, transcript: String) = {
// DatabaseConnection.db.run(
// TableQuery[AudioCaptionTableDef]
// .filter(_.transcriptId === transcriptId)
// .map(a => a.transcript)
// .update((transcript))
// ).onComplete {
// case Success(rowsAffected) => rowsAffected match {
// case 0 => DatabaseConnection.db.run(
// TableQuery[AudioCaptionTableDef] += AudioCaptionDbModel(transcriptId, meetingId, transcript)
// ).onComplete {
// case Success => DatabaseConnection.logger.debug(s"Inserted new audio caption with ID $transcriptId on AudioCaption table")
// case Failure(e) => DatabaseConnection.logger.debug(s"Error inserting or updating audio caption on AudioCaption: $e")
// }
// case 1 => DatabaseConnection.logger.debug(s"Updated audio caption with ID $transcriptId on AudioCaption table")
// case n => DatabaseConnection.logger.debug(s"Error: Expected to insert or update a single row not $n rows")
// }
// case Failure(e) => DatabaseConnection.logger.debug(s"Error updating audio caption on AudioCaption: $e")
// }
TableQuery[AudioCaptionTableDef].insertOrUpdate(
AudioCaptionDbModel(
transcriptId = transcriptId,
meetingId = meetingId,
transcript = transcript
DatabaseConnection.db.run(
TableQuery[AudioCaptionTableDef].insertOrUpdate(
AudioCaptionDbModel(
transcriptId = transcriptId,
meetingId = meetingId,
transcript = transcript
)
)
)
).onComplete {
case Success(_) => DatabaseConnection.logger.debug(s"Upserted audio caption with ID $transcriptId on AudioCaption table")
case Failure(e) => DatabaseConnection.logger.debug(s"Error upserting audio caption on AudioCaption: $e")
}
}
}