statement

package
v0.0.0-...-9522951 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2017 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package statement provides the ability to parse an SQL statement in the context of a structured type.

This package is under construction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColumnNamer

type ColumnNamer interface {
	ColumnName(fields ...string) string
}

ColumnNamer provides column names based on the structure field name. Multiple field names indicate one or more embedded structures.

type Dialect

type Dialect interface {
	Quote(name string) string
	Placeholder(n int) string
}

Dialect is an interface used to handle differences in SQL dialects.

type Execer

type Execer interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
}

type Queryer

type Queryer interface {
	Query(query string, args ...interface{}) (*sql.Rows, error)
}

type Stmt

type Stmt struct {
	// contains filtered or unexported fields
}

Stmt is a prepared statement. A Stmt is safe for concurrent use by multiple goroutines.

func Prepare

func Prepare(row interface{}, sql string) (*Stmt, error)

Prepare a statement given the row and the sql. If an existing statement exists in the cache it will be reused.

func (*Stmt) Exec

func (stmt *Stmt) Exec(db Execer, dialect Dialect, columnNamer ColumnNamer, row interface{}, args ...interface{}) (int, error)

Exec executes the prepared statement with the given row and optional arguments. It returns the number of rows affected by the statement.

If the statement is an INSERT statement and the row has an auto-increment field, then the row is updated with the value of the auto-increment column as long as the SQL driver supports this functionality.

func (*Stmt) Select

func (stmt *Stmt) Select(db Queryer, dialect Dialect, columnNamer ColumnNamer, rows interface{}, args ...interface{}) (int, error)

Select executes the prepared query statement with the given arguments and returns the query results in rows. If rows is a pointer to a slice of structs then one item is added to the slice for each row returned by the query. If row is a pointer to a struct then that struct is filled with the result of the first row returned by the query. In both cases Select returns the number of rows returned by the query.

Jump to

Keyboard shortcuts

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