@@ -135,25 +135,6 @@ withClient :: forall eff a. ConnectionInfo -> (Client -> Aff (db :: DB | eff) a)
135135Takes a Client from the connection pool, runs the given function with
136136the client and returns the results.
137137
138- #### ` withTransaction `
139-
140- ``` purescript
141- withTransaction :: forall eff a. (Client -> Aff (db :: DB | eff) a) -> Client -> Aff (db :: DB | eff) a
142- ```
143-
144- Runs an asynchronous action in a database transaction. The transaction
145- will be rolled back if the computation fails and committed otherwise.
146-
147- Here the first insert will be rolled back:
148-
149- ``` purescript
150- moneyTransfer :: forall e. (Client -> Aff e Unit) -> Client -> Aff e Unit
151- moneyTransfer = withTransaction $ \c -> do
152- execute_ (Query "insert into accounts ...") c
153- throwError $ error "Something went wrong"
154- execute_ (Query "insert into accounts ...") c
155- ```
156-
157138#### ` end `
158139
159140``` purescript
@@ -215,4 +196,47 @@ instance isSqlValueMaybe :: (IsSqlValue a) => IsSqlValue (Maybe a)
215196
216197
217198
199+ ## Module Database.Postgres.Transaction
200+
201+ #### ` withTransaction `
202+
203+ ``` purescript
204+ withTransaction :: forall eff a. (Client -> Aff (db :: DB | eff) a) -> Client -> Aff (db :: DB | eff) a
205+ ```
206+
207+ Runs an asynchronous action in a database transaction. The transaction
208+ will be rolled back if the computation fails and committed otherwise.
209+
210+ Here the first insert will be rolled back:
211+
212+ ``` purescript
213+ moneyTransfer :: forall e. (Client -> Aff e Unit) -> Client -> Aff e Unit
214+ moneyTransfer = withTransaction $ \c -> do
215+ execute_ (Query "insert into accounts ...") c
216+ throwError $ error "Something went wrong"
217+ execute_ (Query "insert into accounts ...") c
218+ ```
219+
220+ #### ` begin `
221+
222+ ``` purescript
223+ begin :: forall eff. Client -> Aff (db :: DB | eff) Unit
224+ ```
225+
226+
227+ #### ` commit `
228+
229+ ``` purescript
230+ commit :: forall eff. Client -> Aff (db :: DB | eff) Unit
231+ ```
232+
233+
234+ #### ` rollback `
235+
236+ ``` purescript
237+ rollback :: forall eff. Client -> Aff (db :: DB | eff) Unit
238+ ```
239+
240+
241+
218242
0 commit comments