Documentation
¶
Overview ¶
Package sql provides a database client implementation that uses SQL.
Index ¶
- Constants
- type Client
- func (this *Client) BeginTransaction() error
- func (this *Client) Close() error
- func (this *Client) EndTransaction(err error) error
- func (this *Client) Execute(query string, args ...any) error
- func (this *Client) ExecutePrepare(args ...any) error
- func (this *Client) ExecutePrepareTransaction(args ...any) error
- func (this *Client) ExecuteTransaction(query string, args ...any) error
- func (this *Client) GetDriver() Driver
- func (this *Client) Open(driver Driver, dsn string, maxOpenConnection int) error
- func (this *Client) Query(query string, args ...any) (*sql.Rows, error)
- func (this *Client) QueryPrepare(args ...any) (*sql.Rows, error)
- func (this *Client) QueryPrepareTransaction(args ...any) (*sql.Rows, error)
- func (this *Client) QueryRow(query string, result ...any) error
- func (this *Client) QueryRowPrepare(args ...any) (*sql.Row, error)
- func (this *Client) QueryRowPrepareTransaction(args ...any) (*sql.Row, error)
- func (this *Client) QueryRowTransaction(query string, result ...any) error
- func (this *Client) QueryTransaction(query string, args ...any) (*sql.Rows, error)
- func (this *Client) SetPrepare(query string) error
- func (this *Client) SetPrepareTransaction(query string) error
- type Driver
Constants ¶
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a struct that provides client related methods.
func (*Client) BeginTransaction ¶
BeginTransaction begins a transaction.
finally, you must call EndTransaction.
ex)
err := client.BeginTransaction() err = client.ExecuteTransaction(`...`) err = client.EndTransaction(err)
func (*Client) EndTransaction ¶
EndTransaction ends a transaction.
if the argument is nil, commit is performed; otherwise, rollback is performed.
ex)
err := client.BeginTransaction() err = client.ExecuteTransaction(`...`) err = client.EndTransaction(err)
func (*Client) Execute ¶
Execute executes the query.
ex 1) err := client.Execute(`INSERT INTO ... VALUES(value);`) ex 2) err := client.Execute(`INSERT INTO ... VALUES(?);`, value)
func (*Client) ExecutePrepare ¶
ExecutePrepare executes a prepared statement.
ex)
err := client.SetPrepare(`INSERT INTO ` + table + `(field) VALUE(?);`) err = client.ExecutePrepare(value)
func (*Client) ExecutePrepareTransaction ¶
ExecutePrepareTransaction executes a prepared statement.
ex)
err := client.SetPrepareTransaction(`INSERT INTO ` + table + ` VALUE(field=?);`) err = client.ExecutePrepareTransaction(value)
func (*Client) ExecuteTransaction ¶
ExecuteTransaction executes a query.
ex 1) err := client.ExecuteTransaction(`...`)
ex 2) err := client.ExecuteTransaction(`... WHERE field=?;`, value)
func (*Client) Open ¶
Open opens the database.
ex) err := client.Open(sql.DriverMySQL, `id:password@tcp(address)/table`, 1)
func (*Client) Query ¶
Query executes a query and returns the result rows.
ex)
rows, err := client.Query(`SELECT field ...;`) defer rows.Close() for rows.Next() { field := 0 err := rows.Scan(&field) }
func (*Client) QueryPrepare ¶
QueryPrepare query a prepared statement.
ex)
err := client.SetPrepare(`SELECT field ... WHERE field=?;`) rows, err := client.QueryPrepare(value) defer rows.Close() for rows.Next() { field := 0 err := rows.Scan(&field) }
func (*Client) QueryPrepareTransaction ¶
QueryPrepareTransaction is query a prepared statement.
ex)
err := client.SetPrepareTransaction(`SELECT field ... WHERE field=?;`) rows, err := client.QueryPrepareTransaction(value) defer rows.Close() for rows.Next() { field := 0 err := rows.Scan(&field) }
func (*Client) QueryRow ¶
QueryRow executes a query and copies the values of matched rows.
ex) err := client.QueryRow(`SELECT field FROM ...;`, &field)
func (*Client) QueryRowPrepare ¶
QueryRowPrepare query a prepared statement about row.
ex)
err := client.SetPrepare(`SELECT field ... WHERE field=?;`) row, err := client.QueryRowPrepare(value) field := 0 err := row.Scan(&field)
func (*Client) QueryRowPrepareTransaction ¶
QueryPrepareTransaction query a prepared statement about row.
ex)
err := client.SetPrepareTransaction(`SELECT field ... WHERE field=?;`) row, err := client.QueryRowPrepareTransaction(value) field := 0 err := row.Scan(&field)
func (*Client) QueryRowTransaction ¶
QueryRowTransaction executes a query and copies the values of matched rows.
ex) err := client.QueryRowTransaction(`SELECT field ...;`, &field)
func (*Client) QueryTransaction ¶
QueryTransaction executes a query and returns the result rows.
ex 1) rows, err := client.QueryTransaction(`SELECT field ... WHERE field=value;`) ex 2) rows, err := client.QueryTransaction(`SELECT field ... WHERE field=?;`, "value")
defer rows.Close() for rows.Next() { field := 0 err := rows.Scan(&field) }
func (*Client) SetPrepare ¶
SetPrepare is set prepared statement.
ex)
err := client.SetPrepare(`SELECT field ... WHERE field=?;`) err := client.ExecutePrepare(value)
func (*Client) SetPrepareTransaction ¶
SetPrepareTransaction is set prepared statement.
ex) err := client.SetPrepareTransaction(`SELECT field ... WHERE field=?;`)