Skip to content

Commit

Permalink
feat(transactions): export transaction types
Browse files Browse the repository at this point in the history
also rename transaction interface
  • Loading branch information
steebchen committed Feb 10, 2024
1 parent 1da5799 commit 2642af4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/pages/docs/reference/client/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if err != nil {
}
```

## IsUniqueConstraintViolation
## IsErrUniqueConstraint

A unique constraint violation happens when a query attempts to insert or update a record with a value that already exists in the database, or in other words, violates a unique constraint.

Expand Down
4 changes: 2 additions & 2 deletions generator/templates/actions/create.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
return &v, nil
}

func (r {{ $result }}) Tx() {{ $name }}UniqueTxResult {
v := New{{ $name }}UniqueTxResult()
func (r {{ $result }}) Tx() {{ $model.Name.GoCase }}UniqueTxResult {
v := new{{ $model.Name.GoCase }}UniqueTxResult()
v.query = r.query
v.query.TxResult = make(chan []byte, 1)
return v
Expand Down
8 changes: 4 additions & 4 deletions generator/templates/actions/find.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@
return &v, nil
}

func (r {{ $updateResult }}) Tx() {{ $name }}{{ $txResult }}TxResult {
v := New{{ $name }}{{ $txResult }}TxResult()
func (r {{ $updateResult }}) Tx() {{ $model.Name.GoCase }}{{ $txResult }}TxResult {
v := new{{ $model.Name.GoCase }}{{ $txResult }}TxResult()
v.query = r.query
v.query.TxResult = make(chan []byte, 1)
return v
Expand Down Expand Up @@ -286,8 +286,8 @@
return &v, nil
}

func (r {{ $deleteResult }}) Tx() {{ $name }}{{ $txResult }}TxResult {
v := New{{ $name }}{{ $txResult }}TxResult()
func (r {{ $deleteResult }}) Tx() {{ $model.Name.GoCase }}{{ $txResult }}TxResult {
v := new{{ $model.Name.GoCase }}{{ $txResult }}TxResult()
v.query = r.query
v.query.TxResult = make(chan []byte, 1)
return v
Expand Down
4 changes: 2 additions & 2 deletions generator/templates/actions/transaction.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

{{ range $model := $.DMMF.Datamodel.Models }}
{{ range $t := $.DMMF.Types }}
{{ $name := print $model.Name.GoLowerCase $t }}
{{ $name := print $model.Name.GoCase $t }}
{{ $modelName := print $model.Name.GoCase "Model" }}

func New{{ $name }}TxResult() {{ $name }}TxResult {
func new{{ $name }}TxResult() {{ $name }}TxResult {
return {{ $name }}TxResult{
result: &transaction.Result{},
}
Expand Down
4 changes: 2 additions & 2 deletions generator/templates/actions/upsert.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@
return &v, nil
}

func (r {{ $result }}) Tx() {{ $name }}UniqueTxResult {
v := New{{ $name }}UniqueTxResult()
func (r {{ $result }}) Tx() {{ $model.Name.GoCase }}UniqueTxResult {
v := new{{ $model.Name.GoCase }}UniqueTxResult()
v.query = r.query
v.query.TxResult = make(chan []byte, 1)
return v
Expand Down
9 changes: 6 additions & 3 deletions runtime/transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@ type TX struct {
Engine engine.Engine
}

type Param interface {
// deprecated: use Transaction instead

Check failure on line 16 in runtime/transaction/transaction.go

View workflow job for this annotation

GitHub Actions / lint

deprecatedComment: use `Deprecated: ` (note the casing) instead of `deprecated: ` (gocritic)
type Param = Transaction

type Transaction interface {
IsTx()
ExtractQuery() builder.Query
}

func (r TX) Transaction(queries ...Param) Exec {
func (r TX) Transaction(queries ...Transaction) Exec {
return Exec{
engine: r.Engine,
queries: queries,
}
}

type Exec struct {
queries []Param
queries []Transaction
engine engine.Engine
requests []protocol.GQLRequest
}
Expand Down

0 comments on commit 2642af4

Please sign in to comment.