mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-13 19:37:30 +01:00
Use transactionally when inserting data into our database with createAll (#708)
This commit is contained in:
parent
6a69228bae
commit
1619d5d123
2 changed files with 5 additions and 5 deletions
|
@ -18,9 +18,9 @@ abstract class CRUDAutoInc[T <: DbRowAutoInc[T]](
|
|||
val query = table
|
||||
.returning(table.map(_.id))
|
||||
.into((t, id) => t.copyWithId(id = id))
|
||||
val actions: Vector[DBIOAction[query.SingleInsertResult, NoStream, Write]] =
|
||||
ts.map(r => query.+=(r))
|
||||
database.runVec(DBIO.sequence(actions))
|
||||
val actions: DBIOAction[query.MultiInsertResult, NoStream, Write] =
|
||||
query.++=(ts)
|
||||
database.runVec(actions)
|
||||
}
|
||||
|
||||
override def findByPrimaryKeys(ids: Vector[Long]): Query[Table[_], T, Seq] = {
|
||||
|
|
|
@ -12,8 +12,8 @@ sealed abstract class SlickUtil {
|
|||
database: SafeDatabase,
|
||||
table: TableQuery[U])(
|
||||
implicit ec: ExecutionContext): Future[Vector[T]] = {
|
||||
val actions = ts.map(t => (table += t).andThen(DBIO.successful(t)))
|
||||
val result = database.run(DBIO.sequence(actions))
|
||||
val actions = (table ++= ts).andThen(DBIO.successful(ts)).transactionally
|
||||
val result = database.run(actions)
|
||||
result
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue