ent: github.com/facebookincubator/ent/dialect/sql Index | Files | Directories

package sql

import "github.com/facebookincubator/ent/dialect/sql"

Index

Package Files

builder.go driver.go graph.go scan.go sql_113.go

func As Uses

func As(ident string, as string) string

As suffixed the given column with an alias (`a` AS `b`).

func Asc Uses

func Asc(column string) string

Asc adds the ASC suffix for the given column.

func Avg Uses

func Avg(name string) string

Avg wraps the ident with the AVG aggregation function.

func Count Uses

func Count(name string) string

Count wraps the ident with the COUNT aggregation function.

func Desc Uses

func Desc(column string) string

Desc adds the DESC suffix for the given column.

func Dialect Uses

func Dialect(name string) *dialectBuilder

Dialect creates a new dialectBuilder with the given dialect name.

func Distinct Uses

func Distinct(idents ...string) string

Distinct prefixed the given columns with the `DISTINCT` keyword (DISTINCT `id`).

func Lower Uses

func Lower(name string) string

Lower wraps the given column with the LOWER function.

P().EQ(sql.Lower("name"), "a8m")

func Max Uses

func Max(name string) string

Max wraps the ident with the MAX aggregation function.

func Min Uses

func Min(name string) string

Min wraps the ident with the MIN aggregation function.

func ScanSlice Uses

func ScanSlice(rows ColumnScanner, v interface{}) error

ScanSlice scans the given ColumnScanner (basically, sql.Rows or sql.Rows) into the given slice.

func Sum Uses

func Sum(name string) string

Sum wraps the ident with the SUM aggregation function.

type Builder Uses

type Builder struct {
    bytes.Buffer // underlying buffer.
    // contains filtered or unexported fields
}

Builder is the base query builder for the sql dsl.

func (*Builder) Arg Uses

func (b *Builder) Arg(a interface{}) *Builder

Arg appends an input argument to the builder.

func (*Builder) Args Uses

func (b *Builder) Args(a ...interface{}) *Builder

Args appends a list of arguments to the builder.

func (*Builder) Comma Uses

func (b *Builder) Comma() *Builder

Comma adds a comma to the query.

func (Builder) Dialect Uses

func (b Builder) Dialect() string

Dialect returns the dialect of the builder.

func (*Builder) Ident Uses

func (b *Builder) Ident(s string) *Builder

Ident appends the given string as an identifier.

func (*Builder) IdentComma Uses

func (b *Builder) IdentComma(s ...string) *Builder

IdentComma calls Ident on all arguments and adds a comma between them.

func (*Builder) Join Uses

func (b *Builder) Join(qs ...Querier) *Builder

Join joins a list of Queries to the builder.

func (*Builder) JoinComma Uses

func (b *Builder) JoinComma(qs ...Querier) *Builder

JoinComma joins a list of Queries and adds comma between them.

func (*Builder) Nested Uses

func (b *Builder) Nested(f func(*Builder)) *Builder

Nested gets a callback, and wraps its result with parentheses.

func (*Builder) Pad Uses

func (b *Builder) Pad() *Builder

Pad adds a space to the query.

func (Builder) Query Uses

func (b Builder) Query() (string, []interface{})

Query implements the Querier interface.

func (*Builder) Quote Uses

func (b *Builder) Quote(ident string) string

Quote quotes the given identifier with the characters based on the configured dialect. It defaults to "`".

func (*Builder) SetDialect Uses

func (b *Builder) SetDialect(dialect string)

SetDialect sets the builder dialect. It's used for garnering dialect specific queries.

func (*Builder) SetTotal Uses

func (b *Builder) SetTotal(total int)

SetTotal sets the value of the total arguments. Used to pass this information between sub queries/expressions.

func (Builder) Total Uses

func (b Builder) Total() int

Total returns the total number of arguments so far.

type ColumnBuilder Uses

type ColumnBuilder struct {
    Builder
    // contains filtered or unexported fields
}

ColumnBuilder is a builder for column definition in table creation.

func Column Uses

func Column(name string) *ColumnBuilder

Column returns a new ColumnBuilder with the given name.

sql.Column("group_id").Type("int").Attr("UNIQUE")

func (*ColumnBuilder) Attr Uses

func (c *ColumnBuilder) Attr(attr string) *ColumnBuilder

Attr sets an extra attribute for the column, like UNIQUE or AUTO_INCREMENT.

func (*ColumnBuilder) Query Uses

func (c *ColumnBuilder) Query() (string, []interface{})

Query returns query representation of a Column.

func (*ColumnBuilder) Type Uses

func (c *ColumnBuilder) Type(t string) *ColumnBuilder

Type sets the column type.

type ColumnScanner Uses

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

ColumnScanner is the interface that wraps the three sql.Rows methods used for scanning.

type DeleteBuilder Uses

type DeleteBuilder struct {
    Builder
    // contains filtered or unexported fields
}

DeleteBuilder is a builder for `DELETE` statement.

func Delete Uses

func Delete(table string) *DeleteBuilder

Delete creates a builder for the `DELETE` statement.

Delete("users").
	Where(
		Or(
			EQ("name", "foo").And().EQ("age", 10),
			EQ("name", "bar").And().EQ("age", 20),
			And(
				EQ("name", "qux"),
				EQ("age", 1).Or().EQ("age", 2),
			),
		),
	)

func (*DeleteBuilder) FromSelect Uses

func (d *DeleteBuilder) FromSelect(s *Selector) *DeleteBuilder

FromSelect make it possible to delete a sub query.

func (*DeleteBuilder) Query Uses

func (d *DeleteBuilder) Query() (string, []interface{})

Query returns query representation of a `DELETE` statement.

func (*DeleteBuilder) Where Uses

func (d *DeleteBuilder) Where(p *Predicate) *DeleteBuilder

Where appends a where predicate to the `DELETE` statement.

type DescribeBuilder Uses

type DescribeBuilder struct {
    Builder
    // contains filtered or unexported fields
}

DescribeBuilder is a query builder for `DESCRIBE` statement.

func Describe Uses

func Describe(name string) *DescribeBuilder

Describe returns a query builder for the `DESCRIBE` statement.

Describe("users")

func (*DescribeBuilder) Query Uses

func (t *DescribeBuilder) Query() (string, []interface{})

Query returns query representation of a `DESCRIBE` statement.

type Driver Uses

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

Driver is a dialect.Driver implementation for SQL based databases.

func Open Uses

func Open(driver, source string) (*Driver, error)

Open wraps the database/sql.Open method and returns a dialect.Driver that implements the an ent/dialect.Driver interface.

func OpenDB Uses

func OpenDB(driver string, db *sql.DB) *Driver

OpenDB wraps the given database/sql.DB method with a Driver.

func (*Driver) Close Uses

func (d *Driver) Close() error

Close closes the underlying connection.

func (Driver) DB Uses

func (d Driver) DB() *sql.DB

DB returns the underlying *sql.DB instance.

func (Driver) Dialect Uses

func (d Driver) Dialect() string

Dialect implements the dialect.Dialect method.

func (*Driver) Exec Uses

func (c *Driver) Exec(ctx context.Context, query string, args, v interface{}) error

Exec implements the dialect.Exec method.

func (*Driver) Query Uses

func (c *Driver) Query(ctx context.Context, query string, args, v interface{}) error

Exec implements the dialect.Query method.

func (*Driver) Tx Uses

func (d *Driver) Tx(ctx context.Context) (dialect.Tx, error)

Tx starts and returns a transaction.

type DropIndexBuilder Uses

type DropIndexBuilder struct {
    Builder
    // contains filtered or unexported fields
}

DropIndexBuilder is a builder for `DROP INDEX` statement.

func DropIndex Uses

func DropIndex(name string) *DropIndexBuilder

DropIndex creates a builder for the `DROP INDEX` statement.

MySQL:

	DropIndex("index_name").
		Table("users").

SQLite/PostgreSQL:

DropIndex("index_name")

func (*DropIndexBuilder) Query Uses

func (d *DropIndexBuilder) Query() (string, []interface{})

Query returns query representation of a reference clause.

DROP INDEX index_name [ON table_name]

func (*DropIndexBuilder) Table Uses

func (d *DropIndexBuilder) Table(table string) *DropIndexBuilder

Table defines the table for the index.

type ExecQuerier Uses

type ExecQuerier interface {
    ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
    QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
}

ExecQuerier wraps the standard Exec and Query methods.

type ForeignKeyBuilder Uses

type ForeignKeyBuilder struct {
    Builder
    // contains filtered or unexported fields
}

ForeignKeyBuilder is the builder for the foreign-key constraint clause.

func ForeignKey Uses

func ForeignKey(symbol ...string) *ForeignKeyBuilder

ForeignKey returns a builder for the foreign-key constraint clause in create/alter table statements.

ForeignKey().
	Columns("group_id").
	Reference(Reference().Table("groups").Columns("id")).
	OnDelete("CASCADE")

func (*ForeignKeyBuilder) Columns Uses

func (fk *ForeignKeyBuilder) Columns(s ...string) *ForeignKeyBuilder

Columns sets the columns of the foreign key in the source table.

func (*ForeignKeyBuilder) OnDelete Uses

func (fk *ForeignKeyBuilder) OnDelete(action string) *ForeignKeyBuilder

OnDelete sets the on delete action for this constraint.

func (*ForeignKeyBuilder) OnUpdate Uses

func (fk *ForeignKeyBuilder) OnUpdate(action string) *ForeignKeyBuilder

OnUpdate sets the on delete action for this constraint.

func (*ForeignKeyBuilder) Query Uses

func (fk *ForeignKeyBuilder) Query() (string, []interface{})

Query returns query representation of a foreign key constraint.

func (*ForeignKeyBuilder) Reference Uses

func (fk *ForeignKeyBuilder) Reference(r *ReferenceBuilder) *ForeignKeyBuilder

Reference sets the reference clause.

func (*ForeignKeyBuilder) Symbol Uses

func (fk *ForeignKeyBuilder) Symbol(s string) *ForeignKeyBuilder

Symbol sets the symbol of the foreign key.

type Func Uses

type Func struct {
    Builder
}

Func represents an SQL function.

func (Func) Avg Uses

func (f Func) Avg(ident string) string

Avg wraps the ident with the AVG aggregation function.

func (Func) Count Uses

func (f Func) Count(ident string) string

Count wraps the ident with the COUNT aggregation function.

func (Func) Lower Uses

func (f Func) Lower(name string) string

Lower wraps the given ident with the LOWER function.

func (Func) Max Uses

func (f Func) Max(ident string) string

Max wraps the ident with the MAX aggregation function.

func (Func) Min Uses

func (f Func) Min(ident string) string

Min wraps the ident with the MIN aggregation function.

func (Func) Sum Uses

func (f Func) Sum(ident string) string

Sum wraps the ident with the SUM aggregation function.

type IndexBuilder Uses

type IndexBuilder struct {
    Builder
    // contains filtered or unexported fields
}

IndexBuilder is a builder for `CREATE INDEX` statement.

func CreateIndex Uses

func CreateIndex(name string) *IndexBuilder

CreateIndex creates a builder for the `CREATE INDEX` statement.

CreateIndex("index_name").
	Unique().
	Table("users").
	Column("name")

Or:

CreateIndex("index_name").
	Unique().
	Table("users").
	Columns("name", "age")

func (*IndexBuilder) Column Uses

func (i *IndexBuilder) Column(column string) *IndexBuilder

Column appends a column to the column list for the index.

func (*IndexBuilder) Columns Uses

func (i *IndexBuilder) Columns(columns ...string) *IndexBuilder

Columns appends the given columns to the column list for the index.

func (*IndexBuilder) Query Uses

func (i *IndexBuilder) Query() (string, []interface{})

Query returns query representation of a reference clause.

func (*IndexBuilder) Table Uses

func (i *IndexBuilder) Table(table string) *IndexBuilder

Table defines the table for the index.

func (*IndexBuilder) Unique Uses

func (i *IndexBuilder) Unique() *IndexBuilder

Unique sets the index to be a unique index.

type InsertBuilder Uses

type InsertBuilder struct {
    Builder
    // contains filtered or unexported fields
}

InsertBuilder is a builder for `INSERT INTO` statement.

func Insert Uses

func Insert(table string) *InsertBuilder

Insert creates a builder for the `INSERT INTO` statement.

Insert("users").
	Columns("name", "age").
	Values("a8m", 10).
	Values("foo", 20)

Note: Insert inserts all values in one batch.

func (*InsertBuilder) Columns Uses

func (i *InsertBuilder) Columns(columns ...string) *InsertBuilder

Columns sets the columns of the insert statement.

func (*InsertBuilder) Default Uses

func (i *InsertBuilder) Default() *InsertBuilder

Default sets the default values clause based on the dialect type.

func (*InsertBuilder) Query Uses

func (i *InsertBuilder) Query() (string, []interface{})

Query returns query representation of an `INSERT INTO` statement.

func (*InsertBuilder) Returning Uses

func (i *InsertBuilder) Returning(columns ...string) *InsertBuilder

Returning adds the `RETURNING` clause to the insert statement. PostgreSQL only.

func (*InsertBuilder) Set Uses

func (i *InsertBuilder) Set(column string, v interface{}) *InsertBuilder

Set is a syntactic sugar API for inserting only one row.

func (*InsertBuilder) Values Uses

func (i *InsertBuilder) Values(values ...interface{}) *InsertBuilder

Values append a value tuple for the insert statement.

type NullBool Uses

type NullBool = sql.NullBool

NullBool is an alias to sql.NullBool.

type NullFloat64 Uses

type NullFloat64 = sql.NullFloat64

NullFloat64 is an alias to sql.NullFloat64.

type NullInt64 Uses

type NullInt64 = sql.NullInt64

NullInt64 is an alias to sql.NullInt64.

type NullString Uses

type NullString = sql.NullString

NullString is an alias to sql.NullString.

type NullTime Uses

type NullTime = sql.NullTime

NullTime represents a time.Time that may be null.

type Predicate Uses

type Predicate struct {
    Builder
    // contains filtered or unexported fields
}

Predicate is a where predicate.

func And Uses

func And(preds ...*Predicate) *Predicate

And combines all given predicates with AND between them.

func Contains Uses

func Contains(col, sub string) *Predicate

Contains is a helper predicate that checks substring using the LIKE predicate.

func ContainsFold Uses

func ContainsFold(col, sub string) *Predicate

ContainsFold is a helper predicate that checks substring using the LIKE predicate.

func EQ Uses

func EQ(col string, value interface{}) *Predicate

EQ returns a "=" predicate.

func EqualFold Uses

func EqualFold(col, sub string) *Predicate

EqualFold is a helper predicate that applies the "=" predicate with case-folding.

func False Uses

func False() *Predicate

False appends the FALSE keyword to the predicate.

Delete().From("users").Where(False())

func GT Uses

func GT(col string, value interface{}) *Predicate

GT returns a ">" predicate.

func GTE Uses

func GTE(col string, value interface{}) *Predicate

GTE returns a ">=" predicate.

func HasPrefix Uses

func HasPrefix(col, prefix string) *Predicate

HasPrefix is a helper predicate that checks prefix using the LIKE predicate.

func HasSuffix Uses

func HasSuffix(col, suffix string) *Predicate

HasSuffix is a helper predicate that checks suffix using the LIKE predicate.

func In Uses

func In(col string, args ...interface{}) *Predicate

In returns the `IN` predicate.

func InInts Uses

func InInts(col string, args ...int) *Predicate

InInts returns the `IN` predicate for ints.

func IsNull Uses

func IsNull(col string) *Predicate

IsNull returns the `IS NULL` predicate.

func LT Uses

func LT(col string, value interface{}) *Predicate

LT returns a "<" predicate.

func LTE Uses

func LTE(col string, value interface{}) *Predicate

LTE returns a "<=" predicate.

func Like Uses

func Like(col, pattern string) *Predicate

Like returns the `LIKE` predicate.

func NEQ Uses

func NEQ(col string, value interface{}) *Predicate

NEQ returns a "<>" predicate.

func Not Uses

func Not(pred *Predicate) *Predicate

Not wraps the given predicate with the not predicate.

Not(Or(EQ("name", "foo"), EQ("name", "bar")))

func NotIn Uses

func NotIn(col string, args ...interface{}) *Predicate

NotIn returns the `Not IN` predicate.

func NotNull Uses

func NotNull(col string) *Predicate

NotNull returns the `IS NOT NULL` predicate.

func Or Uses

func Or(preds ...*Predicate) *Predicate

Or combines all given predicates with OR between them.

Or(EQ("name", "foo"), EQ("name", "bar"))

func P Uses

func P() *Predicate

P creates a new predicates.

P().EQ("name", "a8m").And().EQ("age", 30)

func (*Predicate) And Uses

func (p *Predicate) And() *Predicate

And appends And only if it's not a start of expression.

func (*Predicate) Contains Uses

func (p *Predicate) Contains(col, sub string) *Predicate

Contains is a helper predicate that checks substring using the LIKE predicate.

func (*Predicate) ContainsFold Uses

func (p *Predicate) ContainsFold(col, sub string) *Predicate

ContainsFold is a helper predicate that applies the LIKE predicate with case-folding. The recommendation is to avoid using it, and to use a dialect specific feature, like `ILIKE` in PostgreSQL, and `COLLATE` clause in MySQL.

func (*Predicate) EQ Uses

func (p *Predicate) EQ(col string, arg interface{}) *Predicate

EQ appends a "=" predicate.

func (*Predicate) EqualFold Uses

func (p *Predicate) EqualFold(col, sub string) *Predicate

EqualFold is a helper predicate that applies the "=" predicate with case-folding.

func (*Predicate) False Uses

func (p *Predicate) False() *Predicate

False appends FALSE to the predicate.

func (*Predicate) GT Uses

func (p *Predicate) GT(col string, arg interface{}) *Predicate

GT appends a ">" predicate.

func (*Predicate) GTE Uses

func (p *Predicate) GTE(col string, arg interface{}) *Predicate

GTE appends a ">=" predicate.

func (*Predicate) HasPrefix Uses

func (p *Predicate) HasPrefix(col, prefix string) *Predicate

HasPrefix is a helper predicate that checks prefix using the LIKE predicate.

func (*Predicate) HasSuffix Uses

func (p *Predicate) HasSuffix(col, suffix string) *Predicate

HasSuffix is a helper predicate that checks suffix using the LIKE predicate.

func (*Predicate) In Uses

func (p *Predicate) In(col string, args ...interface{}) *Predicate

In appends the `IN` predicate.

func (*Predicate) InInts Uses

func (p *Predicate) InInts(col string, args ...int) *Predicate

InInts adds the `IN` predicate for ints.

func (*Predicate) IsNull Uses

func (p *Predicate) IsNull(col string) *Predicate

IsNull appends the `IS NULL` predicate.

func (*Predicate) LT Uses

func (p *Predicate) LT(col string, arg interface{}) *Predicate

LT appends a "<" predicate.

func (*Predicate) LTE Uses

func (p *Predicate) LTE(col string, arg interface{}) *Predicate

LTE appends a "<=" predicate.

func (*Predicate) Like Uses

func (p *Predicate) Like(col, pattern string) *Predicate

Like appends the `LIKE` predicate.

func (*Predicate) NEQ Uses

func (p *Predicate) NEQ(col string, arg interface{}) *Predicate

NEQ appends a "<>" predicate.

func (*Predicate) Not Uses

func (p *Predicate) Not() *Predicate

Not appends NOT to the predicate.

func (*Predicate) NotIn Uses

func (p *Predicate) NotIn(col string, args ...interface{}) *Predicate

NotIn appends the `Not IN` predicate.

func (*Predicate) NotNull Uses

func (p *Predicate) NotNull(col string) *Predicate

NotNull appends the `IS NOT NULL` predicate.

func (*Predicate) Or Uses

func (p *Predicate) Or() *Predicate

Or appends an OR only if it's not a start of expression.

func (*Predicate) Query Uses

func (p *Predicate) Query() (string, []interface{})

Query returns query representation of a predicate.

type Querier Uses

type Querier interface {
    // Query returns the query representation of the element
    // and its arguments (if any).
    Query() (string, []interface{})
}

Querier wraps the basic Query method implemented by the different builders in this file.

func Raw Uses

func Raw(s string) Querier

Raw returns a raw sql Querier that is placed as-is in the query.

type Queries Uses

type Queries []Querier

Queries are list of queries join with space between them.

func (Queries) Query Uses

func (n Queries) Query() (string, []interface{})

Query returns query representation of Queriers.

type ReferenceBuilder Uses

type ReferenceBuilder struct {
    Builder
    // contains filtered or unexported fields
}

ReferenceBuilder is a builder for the reference clause in constraints. For example, in foreign key creation.

func Reference Uses

func Reference() *ReferenceBuilder

Reference create a reference builder for the reference_option clause.

Reference().Table("groups").Columns("id")

func (*ReferenceBuilder) Columns Uses

func (r *ReferenceBuilder) Columns(s ...string) *ReferenceBuilder

Columns sets the columns of the referenced table.

func (*ReferenceBuilder) Query Uses

func (r *ReferenceBuilder) Query() (string, []interface{})

Query returns query representation of a reference clause.

func (*ReferenceBuilder) Table Uses

func (r *ReferenceBuilder) Table(s string) *ReferenceBuilder

Table sets the referenced table.

type Rel Uses

type Rel int

Rel is a relation type of an edge.

const (
    Unk Rel = iota // Unknown.
    O2O            // One to one / has one.
    O2M            // One to many / has many.
    M2O            // Many to one (inverse perspective for O2M).
    M2M            // Many to many.
)

Relation types.

func (Rel) String Uses

func (r Rel) String() (s string)

String returns the relation name.

type Result Uses

type Result = sql.Result

Result is an alias to sql.Result.

type Rows Uses

type Rows struct{ *sql.Rows }

Rows wraps the sql.Rows to avoid locks copy.

type SelectTable Uses

type SelectTable struct {
    Builder
    // contains filtered or unexported fields
}

SelectTable is a table selector.

func Table Uses

func Table(name string) *SelectTable

Table returns a new table selector.

t1 := Table("users").As("u")
return Select(t1.C("name"))

func (*SelectTable) As Uses

func (s *SelectTable) As(alias string) *SelectTable

As adds the AS clause to the table selector.

func (*SelectTable) C Uses

func (s *SelectTable) C(column string) string

C returns a formatted string for the table column.

func (*SelectTable) Columns Uses

func (s *SelectTable) Columns(columns ...string) []string

Columns returns a list of formatted strings for the table columns.

func (*SelectTable) Unquote Uses

func (s *SelectTable) Unquote() *SelectTable

Unquote makes the table name to be formatted as raw string (unquoted). It is useful whe you don't want to query tables under the current database. For example: "INFORMATION_SCHEMA.TABLE_CONSTRAINTS" in MySQL.

type Selector Uses

type Selector struct {
    Builder
    // contains filtered or unexported fields
}

Selector is a builder for the `SELECT` statement.

func Neighbors Uses

func Neighbors(dialect string, s *Step) (q *Selector)

Neighbors returns a Selector for evaluating the path-step and getting the neighbors of one vertex.

func Select Uses

func Select(columns ...string) *Selector

Select returns a new selector for the `SELECT` statement.

t1 := Table("users").As("u")
t2 := Select().From(Table("groups")).Where(EQ("user_id", 10)).As("g")
return Select(t1.C("id"), t2.C("name")).
		From(t1).
		Join(t2).
		On(t1.C("id"), t2.C("user_id"))

func SetNeighbors Uses

func SetNeighbors(dialect string, s *Step) (q *Selector)

SetNeighbors returns a Selector for evaluating the path-step and getting the neighbors of set of vertices.

func (*Selector) As Uses

func (s *Selector) As(alias string) *Selector

As give this selection an alias.

func (*Selector) C Uses

func (s *Selector) C(column string) string

C returns a formatted string for a selected column from this statement.

func (*Selector) Clone Uses

func (s *Selector) Clone() *Selector

Clone returns a duplicate of the selector, including all associated steps. It can be used to prepare common SELECT statements and use them differently after the clone is made.

func (*Selector) Columns Uses

func (s *Selector) Columns(columns ...string) []string

Columns returns a list of formatted strings for a selected columns from this statement.

func (*Selector) Count Uses

func (s *Selector) Count(columns ...string) *Selector

Count sets the Select statement to be a `SELECT COUNT(*)`.

func (*Selector) Distinct Uses

func (s *Selector) Distinct() *Selector

Distinct adds the DISTINCT keyword to the `SELECT` statement.

func (*Selector) From Uses

func (s *Selector) From(t TableView) *Selector

From sets the source of `FROM` clause.

func (*Selector) FromSelect Uses

func (s *Selector) FromSelect(s2 *Selector) *Selector

FromSelect copies the predicate from a selector.

func (*Selector) GroupBy Uses

func (s *Selector) GroupBy(columns ...string) *Selector

GroupBy appends the `GROUP BY` clause to the `SELECT` statement.

func (*Selector) Having Uses

func (s *Selector) Having(p *Predicate) *Selector

Having appends a predicate for the `HAVING` clause.

func (*Selector) Join Uses

func (s *Selector) Join(t TableView) *Selector

Join appends a `JOIN` clause to the statement.

func (*Selector) Limit Uses

func (s *Selector) Limit(limit int) *Selector

Limit adds the `LIMIT` clause to the `SELECT` statement.

func (*Selector) Not Uses

func (s *Selector) Not() *Selector

Not sets the next coming predicate with not.

func (*Selector) Offset Uses

func (s *Selector) Offset(offset int) *Selector

Offset adds the `OFFSET` clause to the `SELECT` statement.

func (*Selector) On Uses

func (s *Selector) On(c1, c2 string) *Selector

On sets the `ON` clause for the `JOIN` operation.

func (*Selector) Or Uses

func (s *Selector) Or() *Selector

Or sets the next coming predicate with OR operator (disjunction).

func (*Selector) OrderBy Uses

func (s *Selector) OrderBy(columns ...string) *Selector

OrderBy appends the `ORDER BY` clause to the `SELECT` statement.

func (*Selector) P Uses

func (s *Selector) P() *Predicate

P returns the predicate of a selector.

func (*Selector) Query Uses

func (s *Selector) Query() (string, []interface{})

Query returns query representation of a `SELECT` statement.

func (*Selector) Select Uses

func (s *Selector) Select(columns ...string) *Selector

Select changes the columns selection of the SELECT statement. Empty selection means all columns *.

func (*Selector) SetP Uses

func (s *Selector) SetP(p *Predicate) *Selector

SetP sets explicitly the predicate function for the selector and clear its previous state.

func (*Selector) Table Uses

func (s *Selector) Table() *SelectTable

Table returns the selected table.

func (*Selector) Where Uses

func (s *Selector) Where(p *Predicate) *Selector

Where sets or appends the given predicate to the statement.

type Step Uses

type Step struct {
    // From is the source of the step.
    From struct {
        // V can be either one vertex or set of vertices.
        // It can be a pre-processed step (sql.Query) or a simple Go type (integer or string).
        V   interface{}
        // Table holds the table name of V (from).
        Table string
        // Column to join with. Usually the "id" column.
        Column string
    }
    // Edge holds the edge information for getting the neighbors.
    Edge struct {
        // Rel of the edge.
        Rel Rel
        // Table name of where this edge columns reside.
        Table string
        // Columns of the edge.
        // In O2O and M2O, it holds the foreign-key column. Hence, len == 1.
        // In M2M, it holds the primary-key columns of the join table. Hence, len == 2.
        Columns []string
        // Inverse indicates if the edge is an inverse edge.
        Inverse bool
    }
    // To is the dest of the path (the neighbors).
    To  struct {
        // Table holds the table name of the neighbors (to).
        Table string
        // Column to join with. Usually the "id" column.
        Column string
    }
}

A Step provides a path-step information to the traversal functions.

type TableAlter Uses

type TableAlter struct {
    Builder

    Queries []Querier // columns and foreign-keys to add.
    // contains filtered or unexported fields
}

TableAlter is a query builder for `ALTER TABLE` statement.

func AlterTable Uses

func AlterTable(name string) *TableAlter

AlterTable returns a query builder for the `ALTER TABLE` statement.

AlterTable("users").
	AddColumn(Column("group_id").Type("int").Attr("UNIQUE")).
	AddForeignKey(ForeignKey().Columns("group_id").
		Reference(Reference().Table("groups").Columns("id")).OnDelete("CASCADE")),
	)

func (*TableAlter) AddColumn Uses

func (t *TableAlter) AddColumn(c *ColumnBuilder) *TableAlter

AddColumn appends the `ADD COLUMN` clause to the given `ALTER TABLE` statement.

func (*TableAlter) AddForeignKey Uses

func (t *TableAlter) AddForeignKey(fk *ForeignKeyBuilder) *TableAlter

AddForeignKey adds a foreign key constraint to the `ALTER TABLE` statement.

func (*TableAlter) DropColumn Uses

func (t *TableAlter) DropColumn(c *ColumnBuilder) *TableAlter

DropColumn appends the `DROP COLUMN` clause to the given `ALTER TABLE` statement.

func (*TableAlter) ModifyColumn Uses

func (t *TableAlter) ModifyColumn(c *ColumnBuilder) *TableAlter

ModifyColumn appends the `MODIFY/ALTER COLUMN` clause to the given `ALTER TABLE` statement.

func (*TableAlter) ModifyColumns Uses

func (t *TableAlter) ModifyColumns(cs ...*ColumnBuilder) *TableAlter

ModifyColumns calls ModifyColumn with each of the given builders.

func (*TableAlter) Query Uses

func (t *TableAlter) Query() (string, []interface{})

Query returns query representation of the `ALTER TABLE` statement.

	ALTER TABLE name
   [alter_specification]

type TableBuilder Uses

type TableBuilder struct {
    Builder
    // contains filtered or unexported fields
}

TableBuilder is a query builder for `CREATE TABLE` statement.

func CreateTable Uses

func CreateTable(name string) *TableBuilder

CreateTable returns a query builder for the `CREATE TABLE` statement.

CreateTable("users").
	Columns(
		Column("id").Type("int").Attr("auto_increment"),
		Column("name").Type("varchar(255)"),
	).
	PrimaryKey("id")

func (*TableBuilder) Charset Uses

func (t *TableBuilder) Charset(s string) *TableBuilder

Charset appends the `CHARACTER SET` clause to the statement. MySQL only.

func (*TableBuilder) Collate Uses

func (t *TableBuilder) Collate(s string) *TableBuilder

Collate appends the `COLLATE` clause to the statement. MySQL only.

func (*TableBuilder) Column Uses

func (t *TableBuilder) Column(c *ColumnBuilder) *TableBuilder

Column appends the given column to the `CREATE TABLE` statement.

func (*TableBuilder) Columns Uses

func (t *TableBuilder) Columns(columns ...*ColumnBuilder) *TableBuilder

Columns appends the a list of columns to the builder.

func (*TableBuilder) Constraints Uses

func (t *TableBuilder) Constraints(fks ...*ForeignKeyBuilder) *TableBuilder

Constraints adds a list of foreign-key constraints to the statement.

func (*TableBuilder) ForeignKeys Uses

func (t *TableBuilder) ForeignKeys(fks ...*ForeignKeyBuilder) *TableBuilder

ForeignKeys adds a list of foreign-keys to the statement (without constraints).

func (*TableBuilder) IfNotExists Uses

func (t *TableBuilder) IfNotExists() *TableBuilder

IfNotExists appends the `IF NOT EXISTS` clause to the `CREATE TABLE` statement.

func (*TableBuilder) PrimaryKey Uses

func (t *TableBuilder) PrimaryKey(column ...string) *TableBuilder

PrimaryKey adds a column to the primary-key constraint in the statement.

func (*TableBuilder) Query Uses

func (t *TableBuilder) Query() (string, []interface{})

Query returns query representation of a `CREATE TABLE` statement.

CREATE TABLE [IF NOT EXISTS] name

(table definition)
[charset and collation]

type TableView Uses

type TableView interface {
    // contains filtered or unexported methods
}

TableView is a view that returns a table view. Can ne a Table, Selector or a View (WITH statement).

type Tx Uses

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

Tx wraps the sql.Tx for implementing the dialect.Tx interface.

func (*Tx) Commit Uses

func (t *Tx) Commit() error

Commit commits the transaction.

func (*Tx) Exec Uses

func (c *Tx) Exec(ctx context.Context, query string, args, v interface{}) error

Exec implements the dialect.Exec method.

func (*Tx) Query Uses

func (c *Tx) Query(ctx context.Context, query string, args, v interface{}) error

Exec implements the dialect.Query method.

func (*Tx) Rollback Uses

func (t *Tx) Rollback() error

Rollback rollback the transaction.

type UpdateBuilder Uses

type UpdateBuilder struct {
    Builder
    // contains filtered or unexported fields
}

UpdateBuilder is a builder for `UPDATE` statement.

func Update Uses

func Update(table string) *UpdateBuilder

Update creates a builder for the `UPDATE` statement.

Update("users").Set("name", "foo").Set("age", 10)

func (*UpdateBuilder) Add Uses

func (u *UpdateBuilder) Add(column string, v interface{}) *UpdateBuilder

Add adds a numeric value to the given column.

func (*UpdateBuilder) Empty Uses

func (u *UpdateBuilder) Empty() bool

Empty reports whether this builder does not contain update changes.

func (*UpdateBuilder) Query Uses

func (u *UpdateBuilder) Query() (string, []interface{})

Query returns query representation of an `UPDATE` statement.

func (*UpdateBuilder) Set Uses

func (u *UpdateBuilder) Set(column string, v interface{}) *UpdateBuilder

Set sets a column and a its value.

func (*UpdateBuilder) SetNull Uses

func (u *UpdateBuilder) SetNull(column string) *UpdateBuilder

SetNull sets a column as null value.

func (*UpdateBuilder) Where Uses

func (u *UpdateBuilder) Where(p *Predicate) *UpdateBuilder

Where adds a where predicate for update statement.

type WithBuilder Uses

type WithBuilder struct {
    Builder
    // contains filtered or unexported fields
}

WithBuilder is the builder for the `WITH` statement.

func With Uses

func With(name string) *WithBuilder

With returns a new builder for the `WITH` statement.

n := Queries{With("users_view").As(Select().From(Table("users"))), Select().From(Table("users_view"))}
return n.Query()

func (*WithBuilder) As Uses

func (w *WithBuilder) As(s *Selector) *WithBuilder

As sets the view sub query.

func (*WithBuilder) Name Uses

func (w *WithBuilder) Name() string

Name returns the name of the view.

func (*WithBuilder) Query Uses

func (w *WithBuilder) Query() (string, []interface{})

Query returns query representation of a `WITH` clause.

type Wrapper Uses

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

Wrapper wraps a given Querier with different format. Used to prefix/suffix other queries.

func (*Wrapper) Dialect Uses

func (w *Wrapper) Dialect() string

Dialect calls Dialect on the wrapped query.

func (*Wrapper) Query Uses

func (w *Wrapper) Query() (string, []interface{})

Query returns query representation of a wrapped Querier.

func (*Wrapper) SetDialect Uses

func (w *Wrapper) SetDialect(name string)

SetDialect calls SetDialect on the wrapped query.

func (*Wrapper) SetTotal Uses

func (w *Wrapper) SetTotal(total int)

SetTotal sets the value of the total arguments. Used to pass this information between sub queries/expressions.

func (*Wrapper) Total Uses

func (w *Wrapper) Total() int

Total returns the total number of arguments so far.

Directories

PathSynopsis
schemaPackage schema contains all schema migration logic for SQL dialects.

Package sql imports 8 packages (graph) and is imported by 24 packages. Updated 2019-11-21. Refresh now. Tools for package owners.