Skip to content

Commit

Permalink
doc/website: add sql/execquery feature-flag to document (#2453)
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m committed Apr 6, 2022
1 parent 89c3392 commit d92984f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions doc/md/features.md
Expand Up @@ -245,6 +245,37 @@ ORDER BY
`groups`.`id` ASC
```

#### SQL Raw API

The `sql/execquery` option allows executing statements using the `ExecContext`/`QueryContext` methods of the underlying
driver. For full documentation, see: [DB.ExecContext](https://pkg.go.dev/database/sql#DB.ExecContext), and
[DB.QueryContext](https://pkg.go.dev/database/sql#DB.QueryContext).

```go
// From ent.Client.
if _, err := client.ExecContext(ctx, "TRUNCATE t1"); err != nil {
return err
}

// From ent.Tx.
tx, err := client.Tx(ctx)
if err != nil {
return err
}
if err := tx.User.Create().Exec(ctx); err != nil {
return err
}
if _, err := tx.ExecContext("SAVEPOINT user_created"); err != nil {
return err
}
// ...
```

:::warning Note
Statements executed using `ExecContext`/`QueryContext` do not go through Ent, and may skip fundamental layers in your
application such as hooks, privacy (authorization), and validators.
:::

#### Upsert

The `sql/upsert` option lets configure upsert and bulk-upsert logic using the SQL `ON CONFLICT` / `ON DUPLICATE KEY`
Expand Down
1 change: 1 addition & 0 deletions entc/integration/integration_test.go
Expand Up @@ -697,6 +697,7 @@ func ExecQuery(t *testing.T, client *ent.Client) {
require.NoError(err)
count, err := sql.ScanInt(rows)
require.NoError(err)
require.NoError(rows.Close())
require.Equal(1, count)
require.NoError(tx.Commit())
}
Expand Down

0 comments on commit d92984f

Please sign in to comment.