Documentation ¶
Overview ¶
Package ddl provides a go representation of Spanner DDL as well as helpers for building and manipulating Spanner DDL. We only implement enough DDL types to meet the needs of HarbourBridge.
Definitions are from https://cloud.google.com/spanner/docs/data-definition-language. Before defining each type, we give the snippet from this definition.
We use go interface types to preserve the structural constraints of Spanner DDL. For example, suppose ScalarType could be either an INT or a STRING with a length specifier:
ScalarType := INT | STRING( length )
then we use a go interface type to encode ScalarType:
type ScalarType interface { PrintScalarType() string // To print ScalarTypes types. }
and struct types for each case:
type Int struct { } type String struct { length int64 }
and finally, we define functions:
func (i Int) PrintScalarType() { ... } func (s String) PrintScalarType() { .. }
The net result is that the only way to build a ScalarType is using Int or String.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bytes ¶
type Bytes struct{ Len Length }
Bytes encodes DDL BYTES( length ).
func (Bytes) PrintScalarType ¶
PrintScalarType unparses Bytes.
type ColumnDef ¶
type ColumnDef struct { Name string T ScalarType IsArray bool // When false, this column has type T; when true, it is an array of type T. NotNull bool Comment string }
ColumnDef encodes the following DDL definition:
column_def: column_name {scalar_type | array_type} [NOT NULL] [options_def]
func (ColumnDef) PrintColumnDef ¶
PrintColumnDef unparses ColumnDef and returns it as well as any ColumnDef comment. These are returned as separate strings to support formatting needs of PrintCreateTable.
func (ColumnDef) PrintColumnDefType ¶
PrintColumnDefType unparses the type encoded in a ColumnDef.
type Config ¶
type Config struct { Comments bool // If true, print comments. ProtectIds bool // If true, table and col names are quoted using backticks (avoids reserved-word issue). }
Config controls how AST nodes are printed (aka unparsed).
type CreateIndex ¶
CreateIndex encodes the following DDL definition:
create index: CREATE [UNIQUE] [NULL_FILTERED] INDEX index_name ON table_name ( key_part [, ...] ) [ storing_clause ] [ , interleave_clause ]
func (CreateIndex) PrintCreateIndex ¶
func (ci CreateIndex) PrintCreateIndex(c Config) string
PrintCreateIndex unparses a CREATE INDEX statement.
type CreateTable ¶
type CreateTable struct { Name string ColNames []string // Provides names and order of columns ColDefs map[string]ColumnDef // Provides definition of columns (a map for simpler/faster lookup during type processing) Pks []IndexKey Comment string }
CreateTable encodes the following DDL definition:
create_table: CREATE TABLE table_name ([column_def, ...] ) primary_key [, cluster]
func (CreateTable) PrintCreateTable ¶
func (ct CreateTable) PrintCreateTable(config Config) string
PrintCreateTable unparses a CREATE TABLE statement.
type Float64 ¶
type Float64 struct{}
Float64 encodes DDL FLOAT64.
func (Float64) PrintScalarType ¶
PrintScalarType unparses Float64
type IndexKey ¶
IndexKey encodes the following DDL definition:
primary_key: PRIMARY KEY ( [key_part, ...] ) key_part: column_name [{ ASC | DESC }]
func (IndexKey) PrintIndexKey ¶
PrintIndexKey unparses the index keys.
type Int64 ¶
type Int64 struct{}
Int64 encodes DDL INT64.
func (Int64) PrintScalarType ¶
PrintScalarType unparses Int64
type Int64Length ¶
type Int64Length struct{ Value int64 }
Int64Length wraps an integer length specifier.
func (Int64Length) PrintLength ¶
func (i Int64Length) PrintLength() string
PrintLength unparses Int64Length.
type Length ¶
type Length interface {
PrintLength() string
}
Length encodes the following Spanner DDL definition:
length: { int64_value | MAX }
type MaxLength ¶
type MaxLength struct{}
MaxLength represents "MAX".
func (MaxLength) PrintLength ¶
PrintLength unparses MaxLength.
type ScalarType ¶
type ScalarType interface {
PrintScalarType() string
}
ScalarType encodes the following DDL definition:
scalar_type: { BOOL | INT64 | FLOAT64 | STRING( length ) | BYTES( length ) | DATE | TIMESTAMP }
type String ¶
type String struct{ Len Length }
String encodes DDL STRING.
func (String) PrintScalarType ¶
PrintScalarType unparses String