sqlexp

package module
Version: v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2022 License: BSD-3-Clause Imports: 7 Imported by: 6

README

golang-sql exp

https://godoc.org/github.com/golang-sql/sqlexp

All contributions must have a valid golang CLA.

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

View Source
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

type DriverNamer interface {
	Namer(ctx context.Context) (Namer, error)
}

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

type DriverQuoter interface {
	Quoter(ctx context.Context) (Quoter, error)
}

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 MsgNotice

type MsgNotice struct{ Message fmt.Stringer }

MsgNotice is raised from the SQL text and is only informational.

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.

func NamerFromDriver

func NamerFromDriver(d driver.Driver, ctx context.Context) (Namer, error)

NamerFromDriver returns the DriverNamer from the DB if it is implemented.

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

func QuoterFromDriver(d driver.Driver, ctx context.Context) (Quoter, error)

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 RawMessage

type RawMessage interface{}

RawMessage is returned from RowsMessage.

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.

Directories

Path Synopsis
package nest supports nested transactions allowing a common querier to be defined.
package nest supports nested transactions allowing a common querier to be defined.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL