Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(transactions): export transaction types #1180

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading