Documentation ¶
Overview ¶
Package sqlexp provides interfaces and functions that may be adopted into the database/sql package in the future. All features may change or be removed in the future.
Index ¶
- Constants
- func ReturnMessageEnqueue(ctx context.Context, m *ReturnMessage, raw RawMessage) error
- func ReturnMessageInit(m *ReturnMessage)
- type DriverNamer
- type DriverQuoter
- type DriverSavepointer
- type MsgError
- type MsgLastInsertID
- type MsgNext
- type MsgNextResultSet
- type MsgNotice
- type MsgRowsAffected
- type Namer
- type Querier
- type Quoter
- type RawMessage
- type ReturnMessage
- type Savepointer
- Bugs
Constants ¶
const ( DialectPostgres = "postgres" DialectTSQL = "tsql" DialectMySQL = "mysql" DialectSQLite = "sqlite" DialectOracle = "oracle" )
Variables ¶
This section is empty.
Functions ¶
func ReturnMessageEnqueue ¶
func ReturnMessageEnqueue(ctx context.Context, m *ReturnMessage, raw RawMessage) error
ReturnMessageEnqueue is called by the driver to enqueue the driver. Drivers should not call this until after it returns from Query.
func ReturnMessageInit ¶
func ReturnMessageInit(m *ReturnMessage)
ReturnMessageInit is called by database/sql setup the ReturnMessage internals.
Types ¶
type DriverNamer ¶
DriverNamer may be implemented on the driver.Driver interface. It may need to request information from the server to return the correct information.
type DriverQuoter ¶
DriverQuoter returns a Quoter interface and is suitable for extending the driver.Driver type.
The driver may need to hit the database to determine how it is configured to ensure the correct escaping rules are used.
type DriverSavepointer ¶
type DriverSavepointer interface {
Savepointer() (Savepointer, error)
}
type MsgError ¶
type MsgError struct{ Error error }
MsgError returns SQL errors from the database system (not transport or other system level errors).
type MsgLastInsertID ¶
type MsgLastInsertID struct{ Value interface{} }
MsgLastInsertID returns the value of last inserted row. For many database systems and tables this will return int64. Some databases may return a string or GUID equivalent.
type MsgNext ¶
type MsgNext struct{}
MsgNext indicates the result set ready to be scanned. This message will often be followed with:
for rows.Next() { rows.Scan(&v) }
type MsgNextResultSet ¶
type MsgNextResultSet struct{}
MsgNextResultSet must be checked for. When received, NextResultSet should be called and if false the message loop should be exited.
type MsgRowsAffected ¶
type MsgRowsAffected struct{ Count int64 }
MsgRowsAffected returns the number of rows affected. Not all operations that affect rows return results, thus this message may be received multiple times.
type Namer ¶
type Namer interface { // Name of the database management system. // // Examples: // "posgresql-9.6" // "sqlserver-10.54.32" // "cockroachdb-1.0" Name() string // Dialect of SQL used in the database. Dialect() string }
Namer returns the name of the database and the SQL dialect it uses.
type Querier ¶
type Querier interface { ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row }
Querier is the common interface to execute queries on a DB, Tx, or Conn.
type Quoter ¶
type Quoter interface { // ID quotes identifiers such as schema, table, or column names. // ID does not operate on multipart identifiers such as "public.Table", // it only operates on single identifiers such as "public" and "Table". ID(name string) string // Value quotes database values such as string or []byte types as strings // that are suitable and safe to embed in SQL text. The returned value // of a string will include all surrounding quotes. // // If a value type is not supported it must panic. Value(v interface{}) string }
Quoter returns safe and valid SQL strings to use when building a SQL text.
func QuoterFromDriver ¶
QuoterFromDriver takes a database driver, often obtained through a sql.DB.Driver call or from using it directly to get the quoter interface.
Currently MssqlDriver is hard-coded to also return a valided Quoter.
type ReturnMessage ¶
type ReturnMessage struct {
// contains filtered or unexported fields
}
ReturnMessage may be passed into a Query argument.
Drivers must implement driver.NamedValueChecker, call ReturnMessageInit on it, save it internally, and return driver.ErrOmitArgument to prevent this from appearing in the query arguments.
Queries that recieve this message should also not return SQL errors from the Query method, but wait to return it in a Message.
func (*ReturnMessage) Message ¶
func (m *ReturnMessage) Message(ctx context.Context) RawMessage
Message is called by clients after Query to dequeue messages.
type Savepointer ¶
type Savepointer interface { Release(name string) string Create(name string) string Rollback(name string) string }
func SavepointFromDriver ¶
func SavepointFromDriver(d driver.Driver) (Savepointer, error)
SavepointFromDriver
Notes ¶
Bugs ¶
Both the Quoter and Namer may need to access the server.