2019-06-29 16:58:41 +02:00
|
|
|
|
|
|
|
|
Following statements are supported:
|
|
|
|
|
|
|
|
|
|
* [SELECT](https://github.com/go-jet/jet/wiki/SELECT)
|
|
|
|
|
* [INSERT](https://github.com/go-jet/jet/wiki/INSERT)
|
|
|
|
|
* [UPDATE](https://github.com/go-jet/jet/wiki/UPDATE)
|
|
|
|
|
* [DELETE](https://github.com/go-jet/jet/wiki/DELETE)
|
|
|
|
|
* [LOCK](https://github.com/go-jet/jet/wiki/LOCK)
|
|
|
|
|
|
|
|
|
|
_This list might be extended with feature Jet releases._
|
|
|
|
|
|
2019-07-15 13:06:06 +02:00
|
|
|
### Executing statements
|
2019-07-05 15:13:00 +02:00
|
|
|
|
2019-07-15 13:06:06 +02:00
|
|
|
Statements can be executed with following methods:
|
|
|
|
|
- `Query(db execution.DB, destination interface{}) error` - executes statements over database connection db and maps
|
|
|
|
|
row result result set to destination.
|
|
|
|
|
- `QueryContext(db execution.DB, context context.Context, destination interface{}) error` - executes statement with a
|
|
|
|
|
context over database connection db and maps row result result set to destination.
|
|
|
|
|
- `Exec(db execution.DB) (sql.Result, error)` - executes statement over db connection and returns `sql.Result`.
|
|
|
|
|
- `ExecContext(db execution.DB, context context.Context) (sql.Result, error)` - executes statement with context over
|
|
|
|
|
db connection and returns `sql.Result`.
|
2019-06-29 16:58:41 +02:00
|
|
|
|
2019-07-05 15:13:00 +02:00
|
|
|
Each execution method first creates parametrized sql query with list of arguments and then initiates query on database connection.
|
|
|
|
|
Exec and ExecContext are just a wrappers around database `Exec` and `ExecContext`.
|
|
|
|
|
|
|
|
|
|
`Query` and `QueryContext` are bit more complex, the are wrappers around database `Query` and `QueryContext`,
|
|
|
|
|
but they also perform grouping of row result to arbitrary `destination` structure.
|
|
|
|
|
|
2019-06-29 16:58:41 +02:00
|
|
|
Database connection can be of any type that implements following interface:
|
|
|
|
|
|
|
|
|
|
```go
|
|
|
|
|
type DB interface {
|
|
|
|
|
Exec(query string, args ...interface{}) (sql.Result, error)
|
|
|
|
|
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
|
|
|
|
|
Query(query string, args ...interface{}) (*sql.Rows, error)
|
|
|
|
|
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
These include but are not limited to:
|
|
|
|
|
- `sql.DB`
|
|
|
|
|
- `sql.Tx`
|
2019-07-15 13:06:06 +02:00
|
|
|
- `sql.Conn`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Debugging statements
|
|
|
|
|
|
|
|
|
|
Statements SQL can be debugged in two ways:
|
|
|
|
|
|
|
|
|
|
- `Sql() (query string, args []interface{}, err error)` - retrieves parametrized sql query with list of arguments
|
|
|
|
|
- `DebugSql() (query string, err error)` - retrieves debug query where every parametrized placeholder is replaced with its argument.
|