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

Expose a common interface between Client and Tx #302

Merged
merged 1 commit into from
Mar 12, 2024
Merged

Conversation

lsdch
Copy link
Contributor

@lsdch lsdch commented Mar 12, 2024

This PR introduces the Executor interface which exposes all querying functions that are common to both Client and Tx.
Example use-case:

func CreateItem(db edgedb.Executor, name string) (item Item, err error) {
  query := `select (insert Item { name := $0 }) { name };`
  err = db.QuerySingle(context.Background(), query, &item, name)
  return 
}

// Using Client
client, _ := edgedb.CreateClient(ctx, edgedb.Options{})
CreateItem(client, "Item name")

// Using Tx
client.Tx(context.Background(), func(ctx context.Context, tx *edgedb.Tx) error {
  CreateItem(tx, "Item name")
  // Transaction may then be rolled back, e.g. if this is a unit-test
  return errors.New("Rollback")
})

@edgedb-cla
Copy link

edgedb-cla bot commented Mar 12, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

Copy link
Member

@fmoor fmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks!

@fmoor
Copy link
Member

fmoor commented Mar 12, 2024

You can run the linter locally with make lint & make gendocs-lint.

@lsdch
Copy link
Contributor Author

lsdch commented Mar 12, 2024

Thanks! Linter seems to be happy now 🙂

@fmoor fmoor merged commit 0be826d into edgedb:master Mar 12, 2024
9 checks passed
@fmoor
Copy link
Member

fmoor commented Mar 12, 2024

This change was released in v0.16.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants