Nemo Agoni
Nemo Agoni

Reputation: 83

How to use PostgreSQL transaction in vapor

I used the vapor in the postgresql ,I want to save a lot of data at once ,but I don't how to use postgresql transaction,Who can give an example.

Upvotes: 1

Views: 406

Answers (1)

tobygriffin
tobygriffin

Reputation: 5421

If you are using Fluent (Vapor's database ORM with support for PostgresQL) then you simply use:

drop.database?.transaction { conn in
  try modelToSave.makeQuery(conn).save()
  try nextModelToSave.makeQuery(conn).save()
}

Upvotes: 2

Related Questions