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 Spanner migration tool.
Definitions are from https://cloud.google.com/spanner/docs/data-definition-language.
Index ¶
Constants ¶
const ( // Types supported by Spanner with google_standard_sql (default) dialect. // Bool represent BOOL type. Bool string = "BOOL" // Bytes represent BYTES type. Bytes string = "BYTES" // Date represent DATE type. Date string = "DATE" // Float64 represent FLOAT64 type. Float64 string = "FLOAT64" // Int64 represent INT64 type. Int64 string = "INT64" // String represent STRING type. String string = "STRING" // Timestamp represent TIMESTAMP type. Timestamp string = "TIMESTAMP" // Numeric represent NUMERIC type. Numeric string = "NUMERIC" // Json represent JSON type. JSON string = "JSON" // MaxLength is a sentinel for Type's Len field, representing the MAX value. MaxLength = math.MaxInt64 // StringMaxLength represents maximum allowed STRING length. StringMaxLength = 2621440 // BytesMaxLength represents maximum allowed BYTES length. BytesMaxLength = 10485760 MaxNonKeyColumnLength = 1677721600 // Types specific to Spanner with postgresql dialect, when they differ from // Spanner with google_standard_sql. // PGBytea represent BYTEA type, which is BYTES type in PG. PGBytea string = "BYTEA" // PGFloat8 represent FLOAT8 type, which is double type in PG. PGFloat8 string = "FLOAT8" // PGInt8 respresent INT8, which is INT type in PG. PGInt8 string = "INT8" // PGVarchar represent VARCHAR, which is STRING type in PG. PGVarchar string = "VARCHAR" // PGTimestamptz represent TIMESTAMPTZ, which is TIMESTAMP type in PG. PGTimestamptz string = "TIMESTAMPTZ" // Jsonb represents the PG.JSONB type PGJSONB string = "JSONB" // PGMaxLength represents sentinel for Type's Len field in PG. PGMaxLength = 2621440 )
Variables ¶
var PGSQL_RESERVED_KEYWORD_LIST = []string{}/* 151 elements not displayed */
PGDialect keyword list Assumption is that this list PGSQL dialect uses the same keywords
Functions ¶
func GetSortedTableIdsBySpName ¶
Tables are ordered in alphabetical order with one exception: interleaved tables appear after the definition of their parent table.
TODO: Move this method to mapping.go and preserve the table names in sorted order in conv so that we don't need to order the table names multiple times.
Types ¶
type ColumnDef ¶
ColumnDef encodes the following DDL definition:
column_def: column_name type [NOT NULL] [options_def]
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). Tables bool // If true, print tables ForeignKeys bool // If true, print foreign key constraints. SpDialect string Source string //SourceDB information for determining case-sensitivity handling for PGSQL }
Config controls how AST nodes are printed (aka unparsed).
type CreateIndex ¶
type CreateIndex struct { Name string TableId string `json:"TableId"` Unique bool Keys []IndexKey Id string StoredColumnIds []string }
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(ct CreateTable, c Config) string
PrintCreateIndex unparses a CREATE INDEX statement.
type CreateTable ¶
type CreateTable struct { Name string ColIds []string // Provides names and order of columns ShardIdColumn string ColDefs map[string]ColumnDef // Provides definition of columns (a map for simpler/faster lookup during type processing) PrimaryKeys []IndexKey ForeignKeys []Foreignkey Indexes []CreateIndex ParentId string //if not empty, this table will be interleaved Comment string Id 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(spSchema Schema, config Config) string
PrintCreateTable unparses a CREATE TABLE statement.
type Foreignkey ¶
type Foreignkey struct { Name string ColIds []string ReferTableId string ReferColumnIds []string Id string }
Foreignkey encodes the following DDL definition:
[ CONSTRAINT constraint_name ] FOREIGN KEY ( column_name [, ... ] ) REFERENCES ref_table ( ref_column [, ... ] ) }
func (Foreignkey) PrintForeignKey ¶
func (k Foreignkey) PrintForeignKey(c Config) string
PrintForeignKey unparses the foreign keys.
func (Foreignkey) PrintForeignKeyAlterTable ¶
func (k Foreignkey) PrintForeignKeyAlterTable(spannerSchema Schema, c Config, tableId string) string
PrintForeignKeyAlterTable unparses the foreign keys using ALTER TABLE.
type IndexKey ¶
type IndexKey struct { ColId string Desc bool // Default order is ascending i.e. Desc = false. Order int }
IndexKey encodes the following DDL definition:
primary_key: PRIMARY KEY ( [key_part, ...] ) key_part: column_name [{ ASC | DESC }]
func (IndexKey) PrintPkOrIndexKey ¶
func (idx IndexKey) PrintPkOrIndexKey(ct CreateTable, c Config) string
PrintPkOrIndexKey unparses the primary or index keys.
type Schema ¶
type Schema map[string]CreateTable
Schema stores a map of table names and Tables.
func (Schema) CheckInterleaved ¶
CheckInterleaved checks if schema contains interleaved tables.
type Type ¶
type Type struct { Name string // Len encodes the following Spanner DDL definition: // length: // { int64_value | MAX } Len int64 // IsArray represents if Type is an array_type or not // When false, column has type T; when true, it is an array of type T. IsArray bool }
Type represents the type of a column.
type: { BOOL | INT64 | FLOAT64 | STRING( length ) | BYTES( length ) | DATE | TIMESTAMP | NUMERIC }
func (Type) PGPrintColumnDefType ¶
func (Type) PrintColumnDefType ¶
PrintColumnDefType unparses the type encoded in a ColumnDef.