sql

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Insert

func Insert(colNames []string, conf SQLConfig) string

Insert generates a SQL insert statement for each colName. There are several variations of SQL that need to be produced for each driver. This has been tested with the following: PostgreSQL - github.com/lib/pq MySQL/MariaDB - github.com/go-sql-driver/mysql SQLite - github.com/mattn/go-sqlite3

"Parameter markers" are used to specify placeholders for values scanned by the implementing driver: PostgreSQL accepts "incrementing" markers e.g. $1..$2 While MySQL/MariaDB and SQLite accept ?..?.

func Int64ToBool

func Int64ToBool(c *Column) func(t interface{}) error

Int64ToBool casts an int64 type into a boolean. This is useful for casting columns in SQLite which stores BOOL as INT types natively.

func ReadSQL

func ReadSQL(rows *sql.Rows, conf SQLConfig) (map[string]types.DataSlice, []string, error)

ReadSQL returns a named map of types.DataSlice for consumption by the qframe.New constructor.

Types

type ArgBuilder

type ArgBuilder func(ix index.Int, i int) interface{}

func NewArgBuilder

func NewArgBuilder(col column.Column) (ArgBuilder, error)

type CoerceFunc

type CoerceFunc func(c *Column) func(t interface{}) error

CoerceFunc returns a function that does an explicit type cast from one input type and sets an internal column type.

type Column

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

Column implements the sql.Scanner interface and allows arbitrary data types to be loaded from any database/sql/driver into a QFrame.

func (*Column) Bool

func (c *Column) Bool(b bool)

Bool adds a new bool to the underlying data slice

func (*Column) Data

func (c *Column) Data() interface{}

Data returns the underlying data slice

func (*Column) Float

func (c *Column) Float(f float64)

Float adds a new float to the underlying data slice

func (*Column) Int

func (c *Column) Int(i int)

Int adds a new int to the underlying data slice

func (*Column) Null

func (c *Column) Null() error

Null appends a new Null value to the underlying column data.

func (*Column) Scan

func (c *Column) Scan(t interface{}) error

Scan implements the sql.Scanner interface

func (*Column) String

func (c *Column) String(s string)

String adds a new string to the underlying data slice

type SQLConfig

type SQLConfig struct {
	// Query is a Raw SQL statement which must return
	// appropriate types which can be inferred
	// and loaded into a new QFrame.
	Query string
	// Incrementing indicates the PostgreSQL variant
	// of parameter markers will be used, e.g. $1..$2.
	// The default style is ?..?.
	Incrementing bool
	// Table is the name of the table to be used
	// for generating an INSERT statement.
	Table string
	// EscapeChar is a rune which column and table
	// names will be escaped with. PostgreSQL and SQLite
	// both accept double quotes "" while MariaDB/MySQL
	// only accept backticks.
	EscapeChar rune
	// CoerceMap is a map of columns to perform explicit
	// type coercion on.
	CoerceMap map[string]CoerceFunc
	// Precision specifies how much precision float values
	// should have. 0 has no effect.
	Precision int
}

Jump to

Keyboard shortcuts

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