sol

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2017 License: MIT Imports: 15 Imported by: 3

README

Sol

GoDoc Build Status Gitter

A SQL toolkit for Go - in the style of Python's SQLAlchemy Core:

  • Build complete database schemas
  • Create reusable and cross-dialect SQL statements
  • Allow struct instances and slices to be directly populated by the database
  • Support for MySQL, PostGres, and SQLite3

Quickstart

package main

import (
	"log"

	"github.com/aodin/sol"
	_ "github.com/aodin/sol/sqlite3"
	"github.com/aodin/sol/types"
)

// Database schemas are created using sol's Table function
var Users = sol.Table("users",
	sol.Column("id", types.Integer().NotNull()),
	sol.Column("name", types.Varchar().Limit(32).NotNull()),
	sol.Column("password", types.Varchar().Limit(128).NotNull()),
	sol.PrimaryKey("id"),
)

// Structs can be used to send and receive values
type User struct {
	ID       int64
	Name     string
	Password string
}

func main() {
	// Create a connection pool for an in-memory sqlite3 instance
	conn, err := sol.Open("sqlite3", ":memory:")
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	// Test the connection
	if err := conn.Ping(); err != nil {
		log.Fatalf("Failed to open a database connection: %v", err)
	}

	// Create the users table
	conn.Query(Users.Create())

	// Insert a user by struct
	admin := User{ID: 1, Name: "admin", Password: "secret"}
	conn.Query(Users.Insert().Values(admin))

	// Select a user - query methods must be given a pointer receiver!
	var user User
	conn.Query(Users.Select(), &user)
	log.Println(user)
}

Install

go get -u github.com/aodin/sol

Usage

Import Sol and at least one database dialect:

import (
    "github.com/aodin/sol"
    _ "github.com/aodin/sol/mysql"
    _ "github.com/aodin/sol/postgres"
    _ "github.com/aodin/sol/sqlite3"
)

Calling Open will return a *DB that implements Sol's Conn interface and embeds Go's *sql.DB. All queries use the Query method, which will return an error if the query fails:

conn, err := sol.Open("sqlite3", ":memory:")
if err != nil {
    log.Panic(err)
}
defer conn.Close()

if err = conn.Query(Users.Create()); err != nil {
	log.Panic(err)
}

var user User
if err = conn.Query(Users.Select(), &user); err != nil {
	log.Panic(err)
}

If you'd prefer to have queries panic on error, you can create a panicky version of the connection:

panicky := conn.PanicOnError() // or Must()
panicky.Query(Users.Create())

Transactions are started with Begin and include the standard methods Rollback and Commit. There is also a Close method which will rollback the transaction unless IsSuccessful is called:

tx, _ := conn.PanicOnError().Begin()
defer tx.Close()

tx.Query(Users.Insert().Values(User{Name: "Zero"}))
tx.IsSuccessful()
Statements

SQL can be handwritten using the Text function, which requires parameters to be written in a dialect neutral format and passed via Values:

sol.Text(`SELECT * FROM users WHERE id = :id OR name = :name`).Values(
    sol.Values{"name": "admin", "id": 1},
)

Or struct types:

user := struct {
    ID   int64
    Name string
}{
    ID:   1,
    Name: "admin",
}

sol.Text(`SELECT * FROM users WHERE id = :id OR name = :name`).Values(user)

The parameters will be re-written for the current dialect:

SELECT * FROM users WHERE id = ? OR name = ?

Sol also includes a variety of statements that can be constructed directly from declared schemas.

CREATE TABLE

Once a schema has been specified with Table, such as:

var Users = sol.Table("users",
	sol.Column("id", types.Integer().NotNull()),
	sol.Column("name", types.Varchar().Limit(32).NotNull()),
	sol.Column("password", types.Varchar().Limit(128).NotNull()),
	sol.PrimaryKey("id"),
)

A CREATE TABLE statement can be created with:

Users.Create()

As with most statements, it will output dialect neutral SQL from its String() method. Dialect specific output is created with the String() method on the current connection.

CREATE TABLE users (
  id INTEGER NOT NULL,
  name VARCHAR(32) NOT NULL,
  password VARCHAR(128) NOT NULL,
  PRIMARY KEY (id)
);
DROP TABLE

Using the Users schema, a DROP TABLE statement can be created with:

Users.Drop()
DROP TABLE "users"
INSERT

Insert statements can be created without specifying values. For instance, the method Insert() on a schema such as Users can be created with:

Users.Insert()

When using the Sqlite3 dialect it will generate the following SQL:

INSERT INTO users (id, name, password) VALUES (?, ?, ?)

Values can be inserted to the database using custom struct types or the generic sol.Values type. If given a struct, Sol will attempt to match SQL column names to struct field names both exactly and via a camel to snake case conversion. More complex names or aliases should specify db struct tags:

type User struct {
	DoesNotMatchColumn int64 `db:"id"`
	Name               string
	Password           string
}

Example camel to snake case conversions:

Camel Case Snake Case
TextBlock text_block
UserID user_id
UUID uuid
UPDATE

Rows in a table can be updated using either of:

Users.Update()
sol.Update(Users)

Both will produce the following SQL with the sqlite3 dialect:

UPDATE users SET id = ?, name = ?, password = ?

Conditionals can be specified using Where:

conn.Query(Users.Update().Values(
	sol.Values{"password": "supersecret"},
).Where(Users.C("name").Equals("admin")))
DELETE
Users.Delete().Where(Users.C("name").Equals("admin"))
DELETE FROM users WHERE users.name = ?
SELECT

Results can be queried in a number of ways. Each of the following statements will produce the same SQL output:

Users.Select()
sol.Select(Users)
sol.Select(Users.C("id"), Users.C("name"), Users.C("password"))
SELECT users.id, users.name, users.password FROM users

Multiple results can be returned directly into slice of structs:

var users []User
conn.Query(Users.Select(), &users)

Single column selections can select directly into a slice of the appropriate type:

var ids []int64
conn.Query(sol.Select(Users.C("id")), &ids)
Table Schema

Tables can be constructed with foreign keys, unique constraints, and composite primary keys. See the sol_test.go file for more examples:

var Contacts = sol.Table("contacts",
	sol.Column("id", types.Integer()),
	sol.ForeignKey("user_id", Users),
	sol.Column("key", types.Varchar()),
	sol.Column("value", types.Varchar()),
	sol.PrimaryKey("id"),
	sol.Unique("user_id", "key"),
)
CREATE TABLE contacts (
  id INTEGER,
  user_id INTEGER NOT NULL REFERENCES users(id),
  key VARCHAR,
  value VARCHAR,
  PRIMARY KEY (id),
  UNIQUE (user_id, key)
);

Develop

Some dialects require a configuration to be set via an environmental variable for testing, such as SOL_TEST_POSTGRES for the postgres dialect. Example variables and, if possible, Docker containers have been provided in the subpackages where these variables are required.

Statements and clauses can be tested by creating a new dialect-specific tester; for example using the postgres package:

expect := NewTester(t, postgres.Dialect())

The instance's SQL method will test expected output and parameterization:

expect.SQL(Users.Delete(), `DELETE FROM users`)

expect.SQL(
    Users.Insert().Values(Values{"id": 1, "name": "user"}),
    `INSERT INTO users (id, name) VALUES ($1, $2)`,
    1, "user",
)

And the Error method will test that an error occurred:

expect.Error(sql.Select(Users.C("does-not-exist")))

Happy Hacking!

aodin, 2015-2017

Documentation

Overview

Sol is a SQL toolkit for Go - in the style of Python's SQLAlchemy Core

Index

Constants

View Source
const (
	Equal              = "="
	NotEqual           = "<>"
	GreaterThan        = ">"
	GreaterThanOrEqual = ">="
	LessThan           = "<"
	LessThanOrEqual    = "<="
)

Conditionals ----

View Source
const (
	NoAction   fkAction = "NO ACTION"
	Restrict   fkAction = "RESTRICT"
	Cascade    fkAction = "CASCADE"
	SetNull    fkAction = "SET NULL"
	SetDefault fkAction = "SET DEFAULT"
)

The following constants represent possible foreign key actions that can be used in ON DELETE and ON UPDATE clauses.

View Source
const (
	OmitEmpty  = "omitempty"  // Skip this field if it has a zero value
	OmitUpdate = "omitupdate" // Skip this field during updates
)

Common options

View Source
const (
	AVG            = "AVG"
	COUNT          = "COUNT"
	CROSSJOIN      = "CROSS JOIN"
	DATE           = "DATE"
	DATEPART       = "DATE_PART"
	DELETE         = "DELETE"
	DISTINCT       = "DISTINCT"
	FROM           = "FROM"
	FULLOUTERJOIN  = "FULL OUTER JOIN"
	GROUPBY        = "GROUP BY"
	HAVING         = "HAVING"
	INNERJOIN      = "INNER JOIN"
	INSERT         = "INSERT"
	INTO           = "INTO"
	LEFTOUTERJOIN  = "LEFT OUTER JOIN"
	LIMIT          = "LIMIT"
	MAX            = "MAX"
	MIN            = "MIN"
	OFFSET         = "OFFSET"
	ORDERBY        = "ORDER BY"
	RIGHTOUTERJOIN = "RIGHT OUTER JOIN"
	SELECT         = "SELECT"
	SET            = "SET"
	STDDEV         = "STDDEV"
	SUM            = "SUM"
	UPDATE         = "UPDATE"
	VALUES         = "VALUES"
	VARIANCE       = "VARIANCE"
	WHERE          = "WHERE"
	WHITESPACE     = " "
)

Tokens holds SQL tokens that are used for compilation / AST parsing

Variables

View Source
var ErrNoColumns = errors.New(
	"sol: cannot compile a statement without columns",
)

ErrNoColumns is returned when attempting to compile a query without any columns

Functions

func IntegrationTest

func IntegrationTest(t *testing.T, conn *DB, ddlCommit bool)

IntegrationTest runs a large, neutral dialect test

func NewTester

func NewTester(t *testing.T, d dialect.Dialect) *tester

NewTester creates a new SQL/Error tester that uses the given dialect

func NoMatchingFields

func NoMatchingFields(fields []Field) bool

NoMatchingFields returns true if no fields exist

Types

type Aliases

type Aliases map[string]string

Aliases track column names during camel to snake case conversion

func (Aliases) Keys

func (aliases Aliases) Keys() []string

Keys returns the keys of the map in unspecified order

type ArrayClause

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

ArrayClause is any number of clauses with a column join

func (ArrayClause) Compile

func (c ArrayClause) Compile(d dialect.Dialect, ps *Parameters) (string, error)

Compile returns the ArrayClause as a compiled string using the given Dialect - possibly with an error. Any parameters will be appended to the given Parameters.

func (ArrayClause) String

func (c ArrayClause) String() string

String returns the parameter-less ArrayClause in a neutral dialect.

func (ArrayClause) Wrap

func (c ArrayClause) Wrap(str string) string

Wrap implements the Operator interface TODO Should Wrap operate on a clause and return a clause?

type BinaryClause

type BinaryClause struct {
	Pre, Post Clause
	Sep       string
}

BinaryClause is two clauses with a separator

func (BinaryClause) Compile

func (c BinaryClause) Compile(d dialect.Dialect, ps *Parameters) (string, error)

Compile returns the BinaryClause as a compiled string using the given Dialect - possibly with an error. Any parameters will be appended to the given Parameters.

func (BinaryClause) String

func (c BinaryClause) String() string

String returns the parameter-less BinaryClause in a neutral dialect.

type Clause

type Clause interface {
	Compiles
}

Clause is the interface that all structural components of a statement must implement

func AllOf

func AllOf(clauses ...Clause) Clause

AllOf joins the given clauses with 'AND' and wraps them in parentheses

func AnyOf

func AnyOf(clauses ...Clause) Clause

AnyOf joins the given clauses with 'OR' and wraps them in parentheses

type ColumnElem

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

ColumnElem is a dialect neutral implementation of a SQL column

func Avg

func Avg(col Columnar) ColumnElem

Avg returns a column wrapped in the AVG() function

func Column

func Column(name string, datatype types.Type) ColumnElem

Column is the constructor for a ColumnElem

func Count

func Count(col Columnar) ColumnElem

Count returns a column wrapped in the COUNT() function

func Date

func Date(col Columnar) ColumnElem

Date returns a column wrapped in the DATE() function

func DatePart

func DatePart(part string, col Columnar) ColumnElem

DatePart returns a column wrapped in the DATE_PART() function TODO This method is unsafe - it should not accept direct user input

func Function

func Function(name string, col Columnar) ColumnElem

Function adds a generic function to the column

func InvalidColumn

func InvalidColumn(name string, tabular Tabular) (column ColumnElem)

InvalidColumn creates an invalid ColumnElem

func Max

func Max(col Columnar) ColumnElem

Max returns a column wrapped in the MAX() function

func Min

func Min(col Columnar) ColumnElem

Min returns a column wrapped in the MIN() function

func StdDev

func StdDev(col Columnar) ColumnElem

StdDev returns a column wrapped in the STDDEV() function

func Sum

func Sum(col Columnar) ColumnElem

Sum returns a column wrapped in the SUM() function

func Variance

func Variance(col Columnar) ColumnElem

Variance returns a column wrapped in the VARIANCE() function

func (ColumnElem) AddOperator

func (col ColumnElem) AddOperator(op Operator) ColumnElem

func (ColumnElem) Alias

func (col ColumnElem) Alias() string

Alias returns the Column's alias

func (ColumnElem) As

func (col ColumnElem) As(alias string) ColumnElem

As sets an alias and returns a copy of the ColumnElem

func (ColumnElem) Asc

func (col ColumnElem) Asc() OrderedColumn

Asc returns an OrderedColumn. It is the same as passing the column itself to an ORDER BY clause.

func (ColumnElem) Between

func (col ColumnElem) Between(a, b interface{}) Clause

func (ColumnElem) Column

func (col ColumnElem) Column() ColumnElem

Column returns a copy of its receiver Column. This method implements the Columnar interface.

func (ColumnElem) Columns

func (col ColumnElem) Columns() []ColumnElem

Columns returns the ColumnElem itself in a slice of ColumnElem. This method implements the Selectable interface.

func (ColumnElem) Compile

func (col ColumnElem) Compile(d dialect.Dialect, ps *Parameters) (string, error)

Compile produces the dialect specific SQL and adds any parameters in the clause to the given Parameters instance

func (ColumnElem) Create

func (col ColumnElem) Create(d dialect.Dialect) (string, error)

Create implements the Creatable interface that outputs a column of a CREATE TABLE statement.

func (ColumnElem) Desc

func (col ColumnElem) Desc() OrderedColumn

Desc returns an OrderedColumn that will sort in descending order.

func (ColumnElem) DoesNotEqual

func (col ColumnElem) DoesNotEqual(param interface{}) BinaryClause

DoesNotEqual creates a does not equal clause that can be used in conditional clauses.

table.Select().Where(table.C("id").DoesNotEqual(3))

func (ColumnElem) Equals

func (col ColumnElem) Equals(param interface{}) BinaryClause

Equals creates an equals clause that can be used in conditional clauses.

table.Select().Where(table.C("id").Equals(3))

func (ColumnElem) FullName

func (col ColumnElem) FullName() string

FullName prefixes the column name with the table name It does not include operators (such as 'max')

func (ColumnElem) GTE

func (col ColumnElem) GTE(param interface{}) BinaryClause

GTE creates a greater than or equal to clause that can be used in conditional clauses.

table.Select().Where(table.C("id").GTE(3))

func (ColumnElem) GreaterThan

func (col ColumnElem) GreaterThan(param interface{}) BinaryClause

GreaterThan creates a greater than clause that can be used in conditional clauses.

table.Select().Where(table.C("id").GreaterThan(3))

func (ColumnElem) ILike

func (col ColumnElem) ILike(search string) BinaryClause

ILike creates a case insensitive pattern matching clause that can be used in conditional clauses.

table.Select().Where(table.C("name").ILike(`_b%`))

func (ColumnElem) In

func (col ColumnElem) In(args interface{}) BinaryClause

In creates a comparison clause with an IN operator that can be used in conditional clauses. An interface is used because the args may be of any type: ints, strings...

table.Select().Where(table.C("id").In([]int64{1, 2, 3}))

func (ColumnElem) IsInvalid

func (col ColumnElem) IsInvalid() bool

IsInvalid will return true when a column that does not exist was created by a table function - such as .Column() or .C()

func (ColumnElem) IsNotNull

func (col ColumnElem) IsNotNull() UnaryClause

IsNotNull creates a comparison clause that can be used for checking absence of NULLs in conditional clauses.

table.Select().Where(table.C("name").IsNotNull())

func (ColumnElem) IsNull

func (col ColumnElem) IsNull() UnaryClause

IsNull creates a comparison clause that can be used for checking existence of NULLs in conditional clauses.

table.Select().Where(table.C("name").IsNull())

func (ColumnElem) IsValid

func (col ColumnElem) IsValid() bool

IsValid returns true unless the column has been marked invalid. It may be a false positive.

func (ColumnElem) LTE

func (col ColumnElem) LTE(param interface{}) BinaryClause

LTE creates a less than or equal to clause that can be used in conditional clauses.

table.Select().Where(table.C("id").LTE(3))

func (ColumnElem) LessThan

func (col ColumnElem) LessThan(param interface{}) BinaryClause

LessThan creates a less than clause that can be used in conditional clauses.

table.Select().Where(table.C("id").LessThan(3))

func (ColumnElem) Like

func (col ColumnElem) Like(search string) BinaryClause

Like creates a pattern matching clause that can be used in conditional clauses.

table.Select().Where(table.C["name"].Like(`_b%`))

func (ColumnElem) Modify

func (col ColumnElem) Modify(tabular Tabular) error

Modify implements the Modifier interface, allowing the ColumnElem to modify the given TableElem.

func (ColumnElem) Name

func (col ColumnElem) Name() string

Name returns the name of the column - unescaped and without an alias

func (ColumnElem) NotBetween

func (col ColumnElem) NotBetween(a, b interface{}) Clause

func (ColumnElem) NotILike

func (col ColumnElem) NotILike(search string) BinaryClause

NotILike creates a negated, case insensitive pattern matching clause

func (ColumnElem) NotLike

func (col ColumnElem) NotLike(search string) BinaryClause

NotLike creates a pattern matching clause that can be used in conditional clauses.

table.Select().Where(table.C("name").NotLike(`_b%`))

func (ColumnElem) NullsFirst

func (col ColumnElem) NullsFirst() OrderedColumn

NullsFirst returns an OrderedColumn that will sort NULLs first.

func (ColumnElem) NullsLast

func (col ColumnElem) NullsLast() OrderedColumn

NullsLast returns an OrderedColumn that will sort NULLs last.

func (ColumnElem) Orderable

func (col ColumnElem) Orderable() OrderedColumn

Orderable implements the Orderable interface that allows the column to be used in an ORDER BY clause.

func (ColumnElem) Table

func (col ColumnElem) Table() *TableElem

Table returns the column's Table

func (ColumnElem) Type

func (col ColumnElem) Type() types.Type

Type returns the column's data type

type ColumnSet

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

ColumnSet maintains a []ColumnElem. It includes a variety of getters, setters, and filters.

func Columns

func Columns(columns ...ColumnElem) ColumnSet

Columns creates a new ColumnSet

func (ColumnSet) Add

func (set ColumnSet) Add(columns ...Columnar) (ColumnSet, error)

Add adds any number of Columnar types to the set and returns the new set.

func (ColumnSet) All

func (set ColumnSet) All() []ColumnElem

All returns all columns in their default order

func (ColumnSet) Compile

func (set ColumnSet) Compile(d dialect.Dialect, ps *Parameters) (string, error)

func (ColumnSet) Exists

func (set ColumnSet) Exists() bool

Exists returns true if there is at least one column in the set

func (ColumnSet) Filter

func (set ColumnSet) Filter(names ...string) (out ColumnSet)

Filter returns a ColumnSet of columns from the original set that match the given names

func (ColumnSet) FullNames

func (set ColumnSet) FullNames() []string

FullNames returns the full names of the set's columns without alias

func (ColumnSet) Get

func (set ColumnSet) Get(name string) ColumnElem

Get returns a ColumnElem - or an invalid ColumnElem if a column with the given name does not exist in the set

func (ColumnSet) Has

func (set ColumnSet) Has(name string) bool

Has returns true if there is a column with the given name in the ColumnSet

func (ColumnSet) IsEmpty

func (set ColumnSet) IsEmpty() bool

IsEmpty returns true if there are no columns in this set

func (ColumnSet) MakeUnique

func (set ColumnSet) MakeUnique() (UniqueColumnSet, error)

func (ColumnSet) Names

func (set ColumnSet) Names() []string

Names returns the names of the set's columns without alias

func (ColumnSet) Reject

func (set ColumnSet) Reject(names ...string) (out ColumnSet)

Reject removes the given column names and returns a new ColumnSet

type Columnar

type Columnar interface {
	// Two methods for neutral SQL element interfaces:
	// (1) Require the interface to return the neutral implementation
	// (2) Enumerate all the methods an implmentation would require
	// Columnar and Tabular both use method (1)
	// Name has been left as a legacy shortcut but may be removed
	Compiles
	Selectable
	Name() string
	Column() ColumnElem
	Table() *TableElem
}

Columnar is the interface that all dialects of a SQL column must implement

type Compiles

type Compiles interface {
	Compile(dialect.Dialect, *Parameters) (string, error)
}

Compiles is the main interface that all SQL statements and clauses must implement in order to be queried.

type ConditionalStmt

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

ConditionalStmt includes SELECT, DELETE, and UPDATE statements

func (*ConditionalStmt) AddConditional

func (stmt *ConditionalStmt) AddConditional(where Clause)

AddConditional adds a conditional clause to the statement. If a conditional clause already exists, it will be logically joined to the given clause with AND. TODO Additional logical operators?

func (ConditionalStmt) Conditional

func (stmt ConditionalStmt) Conditional() Clause

Conditional returns the statement's conditional Clause

type Conn

type Conn interface {
	Begin() (TX, error)
	Close() error
	Query(stmt Executable, dest ...interface{}) error
	String(stmt Executable) string
}

Conn is the common database connection interface. It can perform queries and dialect specific compilation. Since transactions also implement this interface, it is highly recommended to pass the Conn interface to functions that do not need to modify transactional state.

type Connection

type Connection interface {
	Conn
}

Connection is an alias for Conn

type CreateStmt

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

CreateStmt is the internal representation of an CREATE TABLE statement.

func (CreateStmt) Compile

func (stmt CreateStmt) Compile(d dialect.Dialect, p *Parameters) (string, error)

Compile outputs the CREATE TABLE statement using the given dialect and parameters. An error may be returned because of a pre-existing error or because an error occurred during compilation.

func (CreateStmt) IfNotExists

func (stmt CreateStmt) IfNotExists() CreateStmt

func (CreateStmt) String

func (stmt CreateStmt) String() string

String outputs the parameter-less CREATE TABLE statement in a neutral dialect.

func (CreateStmt) Temporary

func (stmt CreateStmt) Temporary() CreateStmt

type CreateViewStmt

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

CreateViewStmt is the internal representation of a CREATE VIEW statement.

func (CreateViewStmt) Compile

func (stmt CreateViewStmt) Compile(d dialect.Dialect, p *Parameters) (string, error)

Compile outputs the CREATE VIEW statement using the given dialect and parameters. An error may be returned because of a pre-existing error or because an error occurred during compilation.

func (CreateViewStmt) OrReplace

func (stmt CreateViewStmt) OrReplace() CreateViewStmt

func (CreateViewStmt) String

func (stmt CreateViewStmt) String() string

String outputs the parameter-less CREATE View statement in a neutral dialect.

func (CreateViewStmt) Temporary

func (stmt CreateViewStmt) Temporary() CreateViewStmt

type DB

type DB struct {
	*sql.DB
	// contains filtered or unexported fields
}

DB is a database connection pool. Most functions should use the Conn interface instead of this type.

func Open

func Open(driver, credentials string) (*DB, error)

Open connects to the database using the given driver and credentials. It returns a database connection pool and an error if one occurred.

func (*DB) Begin

func (c *DB) Begin() (TX, error)

Begin will start a new transaction on the current connection pool

func (*DB) Close

func (c *DB) Close() error

Close will make the current connection pool unusable

func (*DB) Dialect

func (c *DB) Dialect() dialect.Dialect

Dialect returns the current connection pool's dialect, e.g. sqlite3

func (DB) Must

func (c DB) Must() *DB

Must is an alias for PanicOnError

func (DB) PanicOnError

func (c DB) PanicOnError() *DB

PanicOnError will create a new connection that will panic on any error

func (*DB) Query

func (c *DB) Query(stmt Executable, dest ...interface{}) error

Query executes an Executable statement

func (*DB) String

func (c *DB) String(stmt Executable) string

String returns the compiled Executable using the DB's dialect. If an error is encountered during compilation, it will return the error instead.

type DeleteStmt

type DeleteStmt struct {
	ConditionalStmt
	// contains filtered or unexported fields
}

DeleteStmt is the internal representation of a DELETE statement.

func Delete

func Delete(table *TableElem) (stmt DeleteStmt)

Delete creates a DELETE statement for the given table.

func (DeleteStmt) Compile

func (stmt DeleteStmt) Compile(d dialect.Dialect, ps *Parameters) (string, error)

Compile outputs the DELETE statement using the given dialect and parameters. An error may be returned because of a pre-existing error or because an error occurred during compilation.

func (DeleteStmt) String

func (stmt DeleteStmt) String() string

String outputs the parameter-less DELETE statement in a neutral dialect.

func (DeleteStmt) Where

func (stmt DeleteStmt) Where(clauses ...Clause) DeleteStmt

Where adds a conditional WHERE clause to the DELETE statement.

type DropStmt

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

DropStmt is the internal representation of an DROP TABLE statement.

func (DropStmt) Compile

func (stmt DropStmt) Compile(d dialect.Dialect, p *Parameters) (string, error)

Compile outputs the DROP TABLE statement using the given dialect and parameters.

func (DropStmt) IfExists

func (stmt DropStmt) IfExists() DropStmt

IfExists adds the IF EXISTS modifier to a DROP TABLE statement.

func (DropStmt) String

func (stmt DropStmt) String() string

String outputs the parameter-less CREATE TABLE statement in a neutral dialect.

type Executable

type Executable interface {
	Compiles
}

Executable is - for now - an alias of Compiles

type FKElem

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

FKElem is an internal type representation. It implements the types.Type interface so it can be used in CREATE TABLE statements.

func ForeignKey

func ForeignKey(name string, fk Selectable, datatypes ...types.Type) FKElem

ForeignKey creates a FKElem from the given name and column/table. If given a column, it must already have its table assigned. If given a table, it must have one and only one primary key

func (FKElem) Create

func (fk FKElem) Create(d dialect.Dialect) (string, error)

Create returns the element's syntax for a CREATE TABLE statement.

func (FKElem) ForeignName

func (fk FKElem) ForeignName() string

func (FKElem) Modify

func (fk FKElem) Modify(tabular Tabular) error

Modify implements the TableModifier interface. It creates a column and adds the same column to the create array.

func (FKElem) OnDelete

func (fk FKElem) OnDelete(b fkAction) FKElem

OnDelete adds an ON DELETE clause to the foreign key

func (FKElem) OnUpdate

func (fk FKElem) OnUpdate(b fkAction) FKElem

OnUpdate add an ON UPDATE clause to the foreign key

func (FKElem) References

func (fk FKElem) References() *TableElem

References returns the table that this foreign key references.

type Field

type Field struct {
	Value   reflect.Value
	Type    reflect.StructField
	Name    string
	Options options
}

Field holds value and type info on a struct field

func AlignFields

func AlignFields(columns []string, fields []Field) []Field

AlignFields will reorder the given fields array to match the columns. Columns that do not match fields will be given empty field structs.

func DeepFields

func DeepFields(obj interface{}, index ...int) (fields []Field)

DeepFields returns value and type info on struct types. It will return nothing if the given object is not a struct or *struct type.

func NewField

func NewField(val reflect.Value, typ reflect.StructField, index ...int) (field Field)

NewField creates a Field from a reflect.Value and Type

func (Field) Exists

func (field Field) Exists() bool

Exists returns true if the field exists

func (Field) IsIgnorable

func (field Field) IsIgnorable() bool

IsIgnorable returns true if the field can be ignored

func (Field) IsOmittable

func (field Field) IsOmittable() bool

IsOmittable returns true if the field can be omitted

type FuncClause

type FuncClause struct {
	Inner Clause
	Name  string
}

func (FuncClause) Compile

func (c FuncClause) Compile(d dialect.Dialect, ps *Parameters) (string, error)

Compile returns the FuncClause as a compiled string using the given Dialect - possibly with an error. Any parameters will be appended to the given Parameters.

func (FuncClause) String

func (c FuncClause) String() string

String returns the parameter-less FuncClause in a neutral dialect.

func (FuncClause) Wrap

func (c FuncClause) Wrap(str string) string

Wrap implements the Operator interface

type InsertStmt

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

InsertStmt is the internal representation of an INSERT statement.

func Insert

func Insert(selections ...Selectable) (stmt InsertStmt)

Insert creates an INSERT statement for the given columns and tables. There must be at least one column and all columns must belong to the same table.

func (InsertStmt) Compile

func (stmt InsertStmt) Compile(d dialect.Dialect, ps *Parameters) (string, error)

Compile outputs the INSERT statement using the given dialect and parameters. An error may be returned because of a pre-existing error or because an error occurred during compilation.

func (InsertStmt) String

func (stmt InsertStmt) String() string

String outputs the parameter-less INSERT statement in a neutral dialect.

func (InsertStmt) Table

func (stmt InsertStmt) Table() Tabular

Table returns the INSERT statement's table

func (InsertStmt) Values

func (stmt InsertStmt) Values(obj interface{}) InsertStmt

Values adds parameters to the INSERT statement. Accepted types: struc, Values, or a slice of either. Both pointers and values are accepted.

type JoinClause

type JoinClause struct {
	ArrayClause
	// contains filtered or unexported fields
}

JoinClause implements a variety of joins

func (JoinClause) Compile

func (j JoinClause) Compile(d dialect.Dialect, ps *Parameters) (string, error)

Compile compiles a JoinClause

func (JoinClause) String

func (j JoinClause) String() string

String returns a default string representation of the JoinClause

type Modifier

type Modifier interface {
	Modify(Tabular) error
}

Modifier is the interface that all Table elements - such as columns and constraints - must implement in order to be added to the Table() constructor

type Operator

type Operator interface {
	Wrap(string) string // TODO errors?
}

TODO Merge with Clause?

type Orderable

type Orderable interface {
	Orderable() OrderedColumn
}

Orderable is implemented by both ColumnElem and OrderedColumn types. It allows those types to be used in ORDER BY clauses.

type OrderedColumn

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

OrderedColumn represents a ColumnElem that will be used in an ORDER BY clause within SELECT statements. It provides additional sorting features, such as ASC, DESC, NULLS FIRST, and NULLS LAST. If not specified, ASC is assumed by default. In Postgres: the default behavior is NULLS LAST when ASC is specified or implied, and NULLS FIRST when DESC is specified http://www.postgresql.org/docs/9.2/static/sql-select.html#SQL-ORDERBY

func (OrderedColumn) Asc

func (ord OrderedColumn) Asc() OrderedColumn

Asc sets the column ordering to ascending - the default

func (OrderedColumn) Compile

func (ord OrderedColumn) Compile(d dialect.Dialect, ps *Parameters) (string, error)

func (OrderedColumn) Desc

func (ord OrderedColumn) Desc() OrderedColumn

Desc sets the column ordering to descending

func (OrderedColumn) NullsFirst

func (ord OrderedColumn) NullsFirst() OrderedColumn

NullsFirst sets the column ordering to return NULL results first

func (OrderedColumn) NullsLast

func (ord OrderedColumn) NullsLast() OrderedColumn

NullsLast sets the column ordering to return NULL results last

func (OrderedColumn) Orderable

func (ord OrderedColumn) Orderable() OrderedColumn

Orderable returns the OrderedColumn itself

func (OrderedColumn) String

func (ord OrderedColumn) String() string

String outputs the OrderedColumn in a neutral dialect.

type PKArray

type PKArray []string

PKArray is a list of columns representing the table's primary key array. It is an array instead of a map because order is significant for primary keys.

func PrimaryKey

func PrimaryKey(names ...string) PKArray

PrimaryKey creates a new PKArray. Only one primary key is allowed per table.

func (PKArray) Create

func (pk PKArray) Create(d dialect.Dialect) (string, error)

Create returns the proper syntax for CREATE TABLE commands.

func (PKArray) Has

func (pk PKArray) Has(name string) bool

Has returns true if the PKArray contains the given column name.

func (PKArray) Modify

func (pk PKArray) Modify(tabular Tabular) error

Modify implements the TableModifier interface. It confirms that every column given exists in the parent table.

type Parameter

type Parameter struct {
	Value interface{}
}

Parameter is a value that will be passed to the database using a dialect specific parameterization

func NewParam

func NewParam(value interface{}) *Parameter

NewParam creates a new *Parameter

func (*Parameter) Compile

func (p *Parameter) Compile(d dialect.Dialect, ps *Parameters) (string, error)

Parameter compilation is dialect dependent. For instance, dialects such as PostGres require the parameter index.

type Parameters

type Parameters []interface{}

Parameters aggregated values before parameterization

func Params

func Params() *Parameters

Params creates a new Parameters

func (*Parameters) Add

func (ps *Parameters) Add(param interface{})

Add adds a parameter

func (*Parameters) Len

func (ps *Parameters) Len() int

Len returns the length of the Parameters

type Result

type Result struct {
	Scanner
	// contains filtered or unexported fields
}

Result is returned by a database query - it embeds a Scanner

func (Result) All

func (r Result) All(obj interface{}) error

All returns all result rows scanned into the given interface, which must be a pointer to a slice of either structs or values. If there is only a single result column, then the destination can be a slice of a single native type (e.g. []int).

func (Result) One

func (r Result) One(obj interface{}) error

One returns a single row from Result. The destination must be a pointer to a struct or Values type. If there is only a single result column, then the destination can be a single native type.

type Scanner

type Scanner interface {
	Close() error
	Columns() ([]string, error)
	Err() error
	Next() bool
	Scan(...interface{}) error
}

Scanner is used for building mock result rows for testing

type SelectStmt

type SelectStmt struct {
	ConditionalStmt
	// contains filtered or unexported fields
}

SelectStmt is the internal representation of an SQL SELECT statement.

func Select

func Select(selections ...Selectable) (stmt SelectStmt)

Select create a SELECT statement from the given columns and tables.

func SelectTable

func SelectTable(table Tabular, selects ...Selectable) (stmt SelectStmt)

SelectTable creates a SELECT statement from the given table and its columns. Any additional selections will not have their table added to the SelectStmt's tables field - they must be added manually or through a join. To perform selections using cartesian logic, use Select() instead.

func (SelectStmt) All

func (stmt SelectStmt) All() SelectStmt

All removes the DISTINCT clause from the SELECT statement.

func (SelectStmt) As

func (stmt SelectStmt) As(alias string) SelectStmt

As sets the alias for this statement

func (SelectStmt) Columns

func (stmt SelectStmt) Columns() []ColumnElem

Columns returns all the columns within the SELECT. This method implements the Tabular interface

func (SelectStmt) Compile

func (stmt SelectStmt) Compile(d dialect.Dialect, ps *Parameters) (string, error)

func (SelectStmt) CrossJoin

func (stmt SelectStmt) CrossJoin(table Tabular) SelectStmt

CrossJoin adds a CROSS JOIN ... clause to the SELECT statement.

func (SelectStmt) Distinct

func (stmt SelectStmt) Distinct(columns ...Columnar) SelectStmt

Distinct adds a DISTINCT clause to the SELECT statement. If any column are provided, the clause will be compiled as a DISTINCT ON.

func (SelectStmt) From

func (stmt SelectStmt) From(tables ...Tabular) SelectStmt

From manually specifies the SelectStmt's FROM clause

func (SelectStmt) FullOuterJoin

func (stmt SelectStmt) FullOuterJoin(table Tabular, clauses ...Clause) SelectStmt

FullOuterJoin adds a FULL OUTER JOIN ... ON ... clause to the SELECT statement. If no clauses are given, it will assume the clause is NATURAL.

func (SelectStmt) GroupBy

func (stmt SelectStmt) GroupBy(columns ...Columnar) SelectStmt

GroupBy adds a GROUP BY to the SELECT statement. Only one GROUP BY is allowed per statement. Additional calls to GroupBy will overwrite the existing GROUP BY clause.

func (SelectStmt) Having

func (stmt SelectStmt) Having(conditions ...Clause) SelectStmt

Having adds a conditional clause to the SELECT statement. Only one HAVING is allowed per statement. Additional calls to Having will overwrite the existing HAVING clause.

func (SelectStmt) InnerJoin

func (stmt SelectStmt) InnerJoin(table Tabular, clauses ...Clause) SelectStmt

InnerJoin adds an INNER JOIN ... ON ... clause to the SELECT statement. If no clauses are given, it will assume the clause is NATURAL.

func (SelectStmt) LeftOuterJoin

func (stmt SelectStmt) LeftOuterJoin(table Tabular, clauses ...Clause) SelectStmt

LeftOuterJoin adds a LEFT OUTER JOIN ... ON ... clause to the SELECT statement. If no clauses are given, it will assume the clause is NATURAL.

func (SelectStmt) Limit

func (stmt SelectStmt) Limit(limit int) SelectStmt

Limit sets the limit of the SELECT statement.

func (SelectStmt) Name

func (stmt SelectStmt) Name() string

Name returns the name of the statement's alias or the name of its first table. It will return nothing if neither an alias or any tables exist.

func (SelectStmt) Offset

func (stmt SelectStmt) Offset(offset int) SelectStmt

Offset sets the offset of the SELECT statement.

func (SelectStmt) OrderBy

func (stmt SelectStmt) OrderBy(ords ...Orderable) SelectStmt

OrderBy adds an ORDER BY to the SELECT statement. Only one ORDER BY is allowed per statement. Additional calls to OrderBy will overwrite the existing ORDER BY clause.

func (SelectStmt) RightOuterJoin

func (stmt SelectStmt) RightOuterJoin(table Tabular, clauses ...Clause) SelectStmt

RightOuterJoin adds a RIGHT OUTER JOIN ... ON ... clause to the SELECT statement. If no clauses are given, it will assume the clause is NATURAL.

func (SelectStmt) String

func (stmt SelectStmt) String() string

String outputs the parameter-less SELECT statement in a neutral dialect.

func (SelectStmt) Table

func (stmt SelectStmt) Table() *TableElem

func (SelectStmt) Where

func (stmt SelectStmt) Where(conditions ...Clause) SelectStmt

Where adds a conditional clause to the SELECT statement. Only one WHERE is allowed per statement. Additional calls to Where will overwrite the existing WHERE clause.

type Selectable

type Selectable interface {
	Columns() []ColumnElem
}

Selectable is an interface that allows both tables and columns to be selected. It is implemented by TableElem and ColumnElem.

type SelfFKElem

type SelfFKElem struct {
	FKElem
	// contains filtered or unexported fields
}

SelfFKElem allows a table to have a foreign key to itself. willReference is a placeholder for the column the self-referential foreign key will reference

func SelfForeignKey

func SelfForeignKey(name, ref string, datatypes ...types.Type) SelfFKElem

SelfForeignKey creates a self-referential foreign key

func (SelfFKElem) Modify

func (fk SelfFKElem) Modify(tabular Tabular) error

Modify implements the TableModifier interface. It creates a column and adds the same column to the create array, will adding the referencing table and column

type Stmt

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

Stmt is the base of all statements, including SELECT, UPDATE, DELETE, and INSERT statements

func (*Stmt) AddMeta

func (stmt *Stmt) AddMeta(msg string, args ...interface{})

AddMeta adds a meta errors to the Stmt errors

func (Stmt) Error

func (stmt Stmt) Error() error

Error returns the statement's inner error

type String

type String string

String implements the Clause interface for strings TODO dialect specific, safe-escape

func (String) Compile

func (str String) Compile(d dialect.Dialect, ps *Parameters) (string, error)

type TX

type TX interface {
	Conn
	Commit() error
	IsSuccessful()
	Rollback() error
}

TX is the interface for a transaction. In addition to standard COMMIT and ROLLBACK behavior, the interface includes a generic Close method that can be used with defer. Close will rollback the transaction unless the IsSuccessful method has been called.

type TableElem

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

TableElem is a dialect neutral implementation of a SQL table

func Table

func Table(name string, modifiers ...Modifier) *TableElem

Table creates a new dialect netural table. It will panic on any errors.

func (TableElem) C

func (table TableElem) C(name string) ColumnElem

C is an alias for Column

func (TableElem) Column

func (table TableElem) Column(name string) ColumnElem

Column returns the column as a ColumnElem. If the column does not exist it will return the ColumnElem in an invalid state that will be used to construct an error message

func (TableElem) Columns

func (table TableElem) Columns() []ColumnElem

Columns returns all the table columns in the original schema order

func (TableElem) Compile

func (table TableElem) Compile(d dialect.Dialect, ps *Parameters) (string, error)

func (*TableElem) Create

func (table *TableElem) Create() CreateStmt

Create returns a CREATE statement for the table

func (*TableElem) Delete

func (table *TableElem) Delete() DeleteStmt

Delete is an alias for Delete(table). It will generate a DELETE statement for the entire table

func (*TableElem) Drop

func (table *TableElem) Drop() DropStmt

Drop returns a DROP statement for the table

func (*TableElem) ForeignKeys

func (table *TableElem) ForeignKeys() []FKElem

ForeignKeys returns the table's foreign keys

func (*TableElem) Has

func (table *TableElem) Has(name string) bool

Has returns true if the column exists in this table

func (*TableElem) Insert

func (table *TableElem) Insert() InsertStmt

Insert is an alias for Insert(table). It will create an INSERT statement for the entire table. Specify the insert values with the method Values().

func (*TableElem) Name

func (table *TableElem) Name() string

Name returns the table name without escaping

func (TableElem) PrimaryKey

func (table TableElem) PrimaryKey() PKArray

PrimaryKey returns the primary key array

func (*TableElem) ReferencedBy

func (table *TableElem) ReferencedBy() []FKElem

ReferencedBy returns the foreign keys that reference this table

func (*TableElem) Select

func (table *TableElem) Select(selections ...Selectable) (stmt SelectStmt)

Select returns a SelectStmt for the entire table

func (*TableElem) Table

func (table *TableElem) Table() *TableElem

Table returns the table itself

func (*TableElem) Update

func (table *TableElem) Update() UpdateStmt

Update is an alias for Update(table). It will create an UPDATE statement for the entire table. Specify the update values with the method Values().

type Tabular

type Tabular interface {
	// Two methods for neutral SQL element interfaces:
	// (1) Require the interface to return the neutral implementation
	// (2) Enumerate all the methods an implmentation would require
	// Columnar and Tabular both use method (1)
	// Name has been left as a legacy shortcut but may be removed
	Compiles
	Selectable
	Name() string
	Table() *TableElem
}

Tabular is the interface that all dialects of a SQL table must implement

type TextStmt

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

TextStmt allows the creation of custom SQL statements

func Text

func Text(text string, values ...Values) TextStmt

Text creates a TextStmt with custom SQL

func (TextStmt) Compile

func (stmt TextStmt) Compile(d dialect.Dialect, ps *Parameters) (string, error)

Compile outputs the statement using the given dialect and parameters.

func (TextStmt) String

func (stmt TextStmt) String() string

String outputs the parameter-less statement in a neutral dialect.

func (TextStmt) Values

func (stmt TextStmt) Values(obj interface{}) TextStmt

Values sets the values of the statement. They can be given as either Values or struct types

type Transaction

type Transaction interface {
	TX
}

Transaction is an alias for TX

type UnaryClause

type UnaryClause struct {
	Pre Clause
	Sep string
}

func (UnaryClause) Compile

func (c UnaryClause) Compile(d dialect.Dialect, ps *Parameters) (string, error)

Compile returns the UnaryClause as a compiled string using the given Dialect - possibly with an error. Any parameters will be appended to the given Parameters.

func (UnaryClause) String

func (c UnaryClause) String() string

String returns the parameter-less UnaryClause in a neutral dialect.

type UniqueArray

type UniqueArray []string

UniqueArray is a list of columns representing a table UNIQUE constraint.

func Unique

func Unique(names ...string) UniqueArray

func (UniqueArray) Create

func (unique UniqueArray) Create(d dialect.Dialect) (string, error)

Create returns the proper syntax for CREATE TABLE commands.

func (UniqueArray) Has

func (unique UniqueArray) Has(name string) bool

Has returns true if the UniqueArray contains the given column name.

func (UniqueArray) Modify

func (unique UniqueArray) Modify(tabular Tabular) error

Modify implements the TableModifier interface. It confirms that every column given exists in the parent table.

type UniqueColumnSet

type UniqueColumnSet struct{ ColumnSet }

UniqueColumnSet is a ColumnSet, but column names must be unique

func UniqueColumns

func UniqueColumns() (set UniqueColumnSet)

UniqueColumns creates a new ColumnSet that can only hold columns with unique names

func (UniqueColumnSet) Add

func (set UniqueColumnSet) Add(columns ...Columnar) (UniqueColumnSet, error)

Add adds any number of Columnar types to the set and returns the new set. Adding a column with the same name as an existing column in the set will return an error.

func (UniqueColumnSet) EmptyValues

func (set UniqueColumnSet) EmptyValues() Values

EmptyValues creates an empty Values from the UniqueColumnSet

func (UniqueColumnSet) Filter

func (set UniqueColumnSet) Filter(names ...string) (out UniqueColumnSet)

Filter returns a UniqueColumnSet of columns from the original set that match the given names

func (UniqueColumnSet) Reject

func (set UniqueColumnSet) Reject(names ...string) (out UniqueColumnSet)

Reject removes the given column names and returns a new ColumnSet

type UpdateStmt

type UpdateStmt struct {
	ConditionalStmt
	// contains filtered or unexported fields
}

UpdateStmt is the internal representation of an SQL UPDATE statement.

func Update

func Update(table *TableElem) (stmt UpdateStmt)

Update creates an UPDATE statement for the given table.

func (UpdateStmt) Compile

func (stmt UpdateStmt) Compile(d dialect.Dialect, ps *Parameters) (string, error)

Compile outputs the UPDATE statement using the given dialect and parameters.

func (UpdateStmt) String

func (stmt UpdateStmt) String() string

String outputs the parameter-less UPDATE statement in a neutral dialect.

func (UpdateStmt) Values

func (stmt UpdateStmt) Values(values Values) UpdateStmt

Values attaches the given values to the statement. The keys of values must match columns in the table. TODO Allow structs to be used if a primary key is specified in the schema

func (UpdateStmt) Where

func (stmt UpdateStmt) Where(clauses ...Clause) UpdateStmt

Where adds a conditional WHERE clause to the UPDATE statement.

type Values

type Values map[string]interface{}

Values is a map of column names to values. It can be used both as a source of values in INSERT, UPDATE, and Text statements, or as a destination for SELECT.

func ValuesOf

func ValuesOf(obj interface{}) (Values, error)

ValuesOf converts the given object to a Values type

func (Values) Compile

func (v Values) Compile(d dialect.Dialect, ps *Parameters) (string, error)

Compile outputs the Values in a format for UPDATE using the given dialect and parameters.

func (Values) Diff

func (v Values) Diff(other Values) Values

Diff returns the values in v that differ from the values in other. ISO 31-11: v \ other

func (Values) Equals

func (v Values) Equals(other Values) bool

Equals returns true if both the receiver and parameter Values have equal keys and values

func (Values) Exclude

func (v Values) Exclude(keys ...string) Values

Exclude removes the given keys and returns the remaining Values

func (Values) Filter

func (v Values) Filter(keys ...string) Values

Filter returns a Values type with key-values from the original Values that match the given keys

func (Values) Keys

func (v Values) Keys() []string

Keys returns the keys of the Values map in alphabetical order.

func (Values) MarshalJSON

func (v Values) MarshalJSON() ([]byte, error)

MarshalJSON converts Values to JSON after converting all byte slices to a string type. By default, byte slices are JSON unmarshaled as base64. This is an issue since the postgres driver will scan string/varchar types as byte slices - the current solution is to convert before output.

func (Values) Merge

func (v Values) Merge(others ...Values) Values

Merge combines the given Values without modifying the original Values. Precedence is given to the rightmost Values given as parameters.

func (Values) Reject

func (v Values) Reject(keys ...string) Values

Reject is an alias for Exclude

func (Values) Values

func (v Values) Values() []interface{}

Values returns the values of the Values map in the alphabetical order of its keys.

type ViewElem

type ViewElem struct {
	*TableElem
	// contains filtered or unexported fields
}

ViewElem is a dialect neutral implementation of a SQL view

func View

func View(name string, stmt SelectStmt) (ViewElem, error)

View returns a new ViewElem that can be created or queried

func (ViewElem) Create

func (view ViewElem) Create() (stmt CreateViewStmt)

Create

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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