sql

package
v0.0.0-...-404e4da Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteSQL

func DeleteSQL(ir_del *ir.Delete, dialect Dialect) sqlgen.SQL

func ExprSQL

func ExprSQL(expr *ir.Expr, dialect Dialect) sqlgen.SQL

func GetLastSQL

func GetLastSQL(ir_model *ir.Model, dialect Dialect) sqlgen.SQL

func InsertSQL

func InsertSQL(ir_cre *ir.Create, dialect Dialect) sqlgen.SQL

func SQLFromGroupBy

func SQLFromGroupBy(group_by *GroupBy) sqlgen.SQL

func SQLFromInsert

func SQLFromInsert(insert *Insert) sqlgen.SQL

func SQLFromJoin

func SQLFromJoin(join Join) sqlgen.SQL

func SQLFromJoins

func SQLFromJoins(joins []Join) []sqlgen.SQL

func SQLFromOrderBy

func SQLFromOrderBy(order_by *OrderBy) sqlgen.SQL

func SQLFromSchema

func SQLFromSchema(schema *Schema) []sqlgen.SQL

func SQLFromSelect

func SQLFromSelect(sel *Select) sqlgen.SQL

func SQLFromUpdate

func SQLFromUpdate(upd *Update) sqlgen.SQL

func SchemaCreateSQL

func SchemaCreateSQL(ir_root *ir.Root, dialect Dialect) []sqlgen.SQL

func SchemaDropSQL

func SchemaDropSQL(ir_root *ir.Root, dialect Dialect) []sqlgen.SQL

func SelectSQL

func SelectSQL(ir_read *ir.Read, dialect Dialect) sqlgen.SQL

func UpdateSQL

func UpdateSQL(ir_upd *ir.Update, dialect Dialect) sqlgen.SQL

func WhereSQL

func WhereSQL(wheres []*ir.Where, dialect Dialect) (out []sqlgen.SQL)

Types

type Column

type Column struct {
	Name      string
	Type      string
	NotNull   bool
	Default   string
	Reference *Reference
}

type DefaultDialect

type DefaultDialect struct {
}

DefaultDialect can be used to make forward compatible Dialects with default implementations for new methods.

func (DefaultDialect) CreateSchema

func (d DefaultDialect) CreateSchema(schema *Schema) (res []sqlgen.SQL)

CreateSchema implements Dialect.

func (DefaultDialect) DropSchema

func (d DefaultDialect) DropSchema(schema *Schema) (res []sqlgen.SQL)

DropSchema implements Dialect.

func (DefaultDialect) ReturningLit

func (d DefaultDialect) ReturningLit() string

func (DefaultDialect) SupportDefaultValues

func (d DefaultDialect) SupportDefaultValues() bool

SupportDefaultValues implements Dialect.

type Dialect

type Dialect interface {
	Name() string
	Features() Features
	RowId() string
	ColumnType(field *ir.Field) string
	Rebind(sql string) string
	EscapeString(s string) string
	BoolLit(v bool) string
	DefaultLit(v string) string
	// ReturningLit returns with literal to be used for returning values from an insert.
	ReturningLit() string

	// CreateSchema generates SQL from abstract schema to create all the required tables/indexes.
	CreateSchema(schema *Schema) []sqlgen.SQL

	//DropSchema drops all the resources from the schema. Useful for testing.
	DropSchema(schema *Schema) []sqlgen.SQL
}

func Cockroach

func Cockroach() Dialect

func PGX

func PGX() Dialect

func PGXCockroach

func PGXCockroach() Dialect

func Postgres

func Postgres() Dialect

func SQLite3

func SQLite3() Dialect

func Spanner

func Spanner() Dialect

type Features

type Features struct {

	// Supports DEFAULT VALUES in INSERT statement
	DefaultValues bool

	// Supports the RETURNING syntax on INSERT/UPDATE
	Returning bool

	// Supports positional argument placeholders
	PositionalArguments bool

	// Token used with LIMIT to mean "no limit"
	NoLimitToken string

	// What style the database uses to handle replacement creates
	ReplaceStyle ReplaceStyle

	// Supports the STORING feature of indexes
	Storing bool
}

type GroupBy

type GroupBy struct {
	Fields []string
}

func GroupByFromIRGroupBy

func GroupByFromIRGroupBy(ir_group_by *ir.GroupBy) (group_by *GroupBy)

type Index

type Index struct {
	Name    string
	Table   string
	Columns []string
	Unique  bool
	Where   []sqlgen.SQL
	Storing []string
}

type Insert

type Insert struct {
	Table      string
	PrimaryKey []string

	// StaticColumns are column names without defaults, requested to be inserted
	StaticColumns []string

	// DynamicColumns are column names with defaults, requested to be inserted
	DynamicColumns []string

	// AllDefaults are all the available non-ref columns (even if they are not requested as insert parameters).
	AllDefaults []string

	Returning    []string
	ReplaceStyle *ReplaceStyle
	// SupportDefaultValues should be true, if `INSERT INTO .... DEFAULT VALUES` is supported
	SupportDefaultValues bool
	ReturningLit         string
}

func InsertFromIRCreate

func InsertFromIRCreate(ir_cre *ir.Create, dialect Dialect) *Insert

type Join

type Join struct {
	Type  string
	Table string
	Left  string
	Right string
}

func JoinFromIRJoin

func JoinFromIRJoin(ir_join *ir.Join) Join

func JoinsFromIRJoins

func JoinsFromIRJoins(ir_joins []*ir.Join) (joins []Join)

type OrderBy

type OrderBy struct {
	Entries []OrderByEntry
}

func OrderByFromIROrderBy

func OrderByFromIROrderBy(ir_order_by *ir.OrderBy) (order_by *OrderBy)

type OrderByEntry

type OrderByEntry struct {
	Field      string
	Descending bool
}

type Reference

type Reference struct {
	Table    string
	Column   string
	OnDelete string
	OnUpdate string
}

type ReplaceStyle

type ReplaceStyle int
const (
	ReplaceStyle_Replace ReplaceStyle = iota
	ReplaceStyle_OnConflictUpdate
	ReplaceStyle_Upsert
)

type Schema

type Schema struct {
	Tables  []Table
	Indexes []Index
}

func SchemaFromIRModels

func SchemaFromIRModels(ir_models []*ir.Model, dialect Dialect) *Schema

type Select

type Select struct {
	From    string
	Fields  []string
	Joins   []Join
	Where   []sqlgen.SQL
	GroupBy *GroupBy
	OrderBy *OrderBy
	Limit   string
	Offset  string
	Has     bool
}

func SelectFromIRRead

func SelectFromIRRead(ir_read *ir.Read, dialect Dialect) *Select

type Table

type Table struct {
	Name       string
	Columns    []Column
	PrimaryKey []string
	Unique     [][]string
}

type Update

type Update struct {
	Table        string
	Where        []sqlgen.SQL
	Returning    []string
	In           sqlgen.SQL
	ReturningLit string
}

func UpdateFromIRUpdate

func UpdateFromIRUpdate(ir_upd *ir.Update, dialect Dialect) *Update

Jump to

Keyboard shortcuts

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