sql

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package sql is a parser for the subset of SQL needed for SQLite's `CREATE TABLE` and `CREATE INDEX` statements.

It deals with most of https://sqlite.org/lang_createtable.html and https://sqlite.org/lang_createindex.html

It is used by sqlittle to read the table and index definitions embedded in `.sqlite` files.

Index

Constants

View Source
const ACTION = 57346
View Source
const AND = 57347
View Source
const ASC = 57348
View Source
const AUTOINCREMENT = 57349
View Source
const CASCADE = 57350
View Source
const COLLATE = 57351
View Source
const CONSTRAINT = 57352
View Source
const CREATE = 57353
View Source
const DEFAULT = 57354
View Source
const DELETE = 57355
View Source
const DESC = 57356
View Source
const FOREIGN = 57357
View Source
const FROM = 57358
View Source
const GLOB = 57359
View Source
const IN = 57360
View Source
const INDEX = 57361
View Source
const IS = 57362
View Source
const KEY = 57363
View Source
const LIKE = 57364
View Source
const MATCH = 57365
View Source
const NO = 57366
View Source
const NOT = 57367
View Source
const NULL = 57368
View Source
const ON = 57369
View Source
const OR = 57370
View Source
const PRIMARY = 57371
View Source
const REFERENCES = 57372
View Source
const REGEXP = 57373
View Source
const RESTRICT = 57374
View Source
const ROWID = 57375
View Source
const SELECT = 57376
View Source
const SET = 57377
View Source
const TABLE = 57378
View Source
const UNIQUE = 57379
View Source
const UPDATE = 57380
View Source
const WHERE = 57381
View Source
const WITHOUT = 57382

Variables

This section is empty.

Functions

func AsColumn

func AsColumn(e Expression) string

gives the column name if the expression is a simple single column

func AsString

func AsString(e Expression) string

func Parse

func Parse(sql string) (interface{}, error)

Parse is the main function. It will return either an error or a *Stmt struct.

Types

type ColumnDef

type ColumnDef struct {
	Name          string
	Type          string
	PrimaryKey    bool
	PrimaryKeyDir SortOrder
	AutoIncrement bool
	Null          bool
	Unique        bool
	Default       interface{}
	Collate       string
}

Definition of a column, as found by CreateTableStmt

type CreateIndexStmt

type CreateIndexStmt struct {
	Index          string
	Table          string
	Unique         bool
	IndexedColumns []IndexedColumn
	Where          Expression
}

A `CREATE INDEX` statement

type CreateTableStmt

type CreateTableStmt struct {
	Table        string
	Columns      []ColumnDef
	Constraints  []TableConstraint
	WithoutRowid bool
}

A `CREATE TABLE` statement

type ExBinaryOp

type ExBinaryOp struct {
	Op          string
	Left, Right Expression
}

type ExColumn

type ExColumn string

type ExFunction

type ExFunction struct {
	F    string
	Args []Expression
}

type Expression

type Expression interface{}

type IndexedColumn

type IndexedColumn struct {
	Column     string
	Expression string
	Collate    string
	SortOrder  SortOrder
}

Indexed column, for CreateIndexStmt, and index table constraints. Either Column or Expression is filled. Column is filled if the expression is a single column (as is always the case for PRIMARY KEY and UNIQUE constraints), and Expression is filled in every other case.

type SelectStmt

type SelectStmt struct {
	Columns []string
	Table   string
}

A `SELECT` statement

type SortOrder

type SortOrder int
const (
	Asc SortOrder = iota
	Desc
)

func (SortOrder) String

func (so SortOrder) String() string

type TableConstraint

type TableConstraint interface{}

CREATE TABLE constraint (primary key, index)

type TableForeignKey

type TableForeignKey struct {
	Columns        []string
	ForeignTable   string
	ForeignColumns []string
	Triggers       []Trigger
}

type TablePrimaryKey

type TablePrimaryKey struct {
	IndexedColumns []IndexedColumn
}

type TableUnique

type TableUnique struct {
	IndexedColumns []IndexedColumn
}

type Trigger

type Trigger interface{}

type TriggerAction

type TriggerAction int
const (
	ActionSetNull TriggerAction = iota
	ActionSetDefault
	ActionCascade
	ActionRestrict
	ActionNoAction
)

type TriggerOnDelete

type TriggerOnDelete TriggerAction

type TriggerOnUpdate

type TriggerOnUpdate TriggerAction

Jump to

Keyboard shortcuts

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