Documentation
¶
Overview ¶
Package dbspec parses, validates and emits dbspec documents, the schema language that docs/dbspec.md specifies.
Parse reads one document together with the declared document set that its `use` lines name, validates every rule of the specification and returns either the document or every diagnostic in source order. Emit writes a document in its one canonical text, so Emit(Parse(s)) == s for canonical s.
Index ¶
- Constants
- func Apply(ctx context.Context, c Execer, dialect Dialect, plans []*Plan, ...) error
- func CanonicalLiteral(t Type, text string) (string, bool)
- func Chain(plans []*Plan) ([]*Plan, []Diagnostic)
- func CompareSchemas(source, target *Document) ([]Difference, []Diagnostic)
- func Diff(source *Document, p *Plan) ([]Change, []Diagnostic)
- func Emit(document *Document) string
- func EmitPlan(p *Plan) string
- func ExternalDifferences(live *Document, documents []*Document) []string
- func Finalize(ctx context.Context, c Execer, dialect Dialect, plans []*Plan, ...) error
- func ImportMermaid(text, name string) (*Document, []Unsupported, []Diagnostic)
- func InstalledDifferences(live *Document, unsupported []Unsupported, target *Document) []string
- func Introspect(ctx context.Context, q Querier, dialect Dialect, name string) (*Document, []Unsupported, error)
- func ManifestOf(documents []*Document) (*Manifest, []Diagnostic)
- func Parse(text string, documents map[string]string) (*Document, []Position, []Diagnostic)
- func ParsePlan(text string) (*Plan, []Diagnostic)
- func PlanSteps(source *Document, p *Plan, dialect Dialect) ([]PlanStep, []Diagnostic)
- func ReadSet(path string) (Set, []SetError)
- func Recover(ctx context.Context, c Execer, dialect Dialect, plans []*Plan, ...) error
- func RenderStatements(documents []*Document, dialect Dialect) ([]RenderedStatement, []Diagnostic)
- func Rollback(ctx context.Context, c Execer, dialect Dialect, plans []*Plan, ...) error
- type Action
- type Analysis
- type ApplyError
- type ApplyEvent
- type AuditSetting
- type Binary
- type BlindIndexSetting
- type Change
- type Check
- type CheckboxSetting
- type CodecSetting
- type Column
- type ColumnName
- type ColumnRef
- type ColumnRename
- type ColumnSetting
- type Default
- type Diagnostic
- type Diagram
- type DiagramEntry
- type Dialect
- type Difference
- type Document
- type Effect
- type EntitySetting
- type Execer
- type Expr
- type ForeignKey
- type HistorySetting
- type ImmutableSetting
- type In
- type Index
- type IndexColumn
- type IsNull
- type KeyPrefixSetting
- type LimitSetting
- type Literal
- type Manifest
- type MarkSetting
- type NavigationSetting
- type NullCheck
- type Plan
- type PlanStep
- type Position
- type PrimaryKey
- type Querier
- type QueryObserver
- type RenderedStatement
- type SelectExplicitSetting
- type Set
- type SetDocument
- type SetError
- type SetFile
- type Settings
- type StateLineSetting
- type StateMachineSetting
- type StoreSetting
- type StoreShard
- type Table
- type TableRename
- type Token
- type Type
- type TypeKind
- type Unique
- type Unsupported
- type Use
Constants ¶
const ( RuleSignature = "signature" RuleHeader = "header" RuleSyntax = "syntax" RuleOrder = "order" RuleNameFormat = "name.format" RuleNameLength = "name.length" RuleNameDuplicate = "name.duplicate" RuleType = "type" RuleColumn = "column" RuleKey = "key" RuleForeignKey = "foreign_key" RuleCheck = "check" RuleSetting = "setting" RuleUse = "use" RuleDiagram = "diagram" RuleLimit = "limit" RuleEncoding = "encoding" )
Rules of a diagnostic, as listed in docs/dbspec.md "Limits and errors".
const ( RulePlan = "plan" RuleChain = "chain" )
RulePlan과 RuleChain은 plan 문서와 plan chain의 diagnostic이다 (docs/plans.md).
const ( PositionDocument = "document" PositionUse = "use" PositionUseTable = "use_table" PositionTable = "table" PositionColumn = "column" PositionConstraint = "constraint" PositionSetting = "setting" PositionDiagram = "diagram" PositionDiagramEntry = "diagram_entry" )
The kinds of a Position.
const ( RuleSetFile = "set.file" RuleSetSymlink = "set.symlink" RuleSetJSON = "set.json" RuleSetSchema = "set.schema" RuleSetKey = "set.key" RuleSetEmpty = "set.empty" RuleSetPath = "set.path" RuleSetDuplicate = "set.duplicate" )
The rules of the set reader (docs/dbspec.md "Document sets").
const Code = "SCHEMA_INVALID"
Code is the error code of every dbspec diagnostic.
const RuleCompare = "compare"
RuleCompare는 schema text가 아닌 비교 대상의 diagnostic이다(docs/plans.md "Comparison").
const RuleMermaid = "mermaid"
RuleMermaid는 import가 읽지 못한 Mermaid 줄의 diagnostic이다(docs/mermaid.md).
const SetFileName = "dbspec-set.json"
SetFileName is the only name of a set file.
const Signature = "dbspec "
Signature는 모든 dbspec document 파일의 첫 byte다. header `dbspec 1 <document>`가 이것으로 시작한다(docs/dbspec.md "Files").
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
func Apply(ctx context.Context, c Execer, dialect Dialect, plans []*Plan, now func() time.Time, events func(ApplyEvent) error) error
Apply는 chain에서 database가 아직 적용하지 않은 plan을 차례로 finalize step 앞까지 적용한다. 이미 끝까지 적용한 database에서는 아무것도 바꾸지 않는다.
func CanonicalLiteral ¶
CanonicalLiteral returns the canonical text of text, a literal written as the default of a column of type t, or false when text is not a literal of t. A literal is one token on one line with no space around it: a number whose minus sign is attached, a word (true, false or now) or a quoted string. A text or bytes column has no literal.
func Chain ¶
func Chain(plans []*Plan) ([]*Plan, []Diagnostic)
Chain은 plan들을 from empty에서 이어지는 순서로 돌려준다. plan이 없으면 table이 없는 database의 빈 chain이다.
func CompareSchemas ¶
func CompareSchemas(source, target *Document) ([]Difference, []Diagnostic)
CompareSchemas는 plan 없이 source에서 target까지의 모든 차이를 돌려준다. rename은 없고 table과 column은 이름으로만 맞춘다. 두 문서는 schema text여야 하며, 아닌 쪽마다 compare diagnostic을 source, target 순으로 돌려준다.
func Diff ¶
func Diff(source *Document, p *Plan) ([]Change, []Diagnostic)
Diff는 source schema(nil이면 빈 schema)에서 plan의 target으로 가는 변경을 돌려준다. source의 schemaHash가 plan의 from과 다르면 diagnostic이다.
func Emit ¶
Emit writes document in canonical form (docs/dbspec.md "Canonical form"). It writes the model as given and does not validate it; a document returned by Parse is valid and its literals are already in canonical form.
func EmitPlan ¶
EmitPlan은 plan을 canonical 문서로 쓴다: rename table, rename column, allow drop table, allow drop column 순서로, 각각 이름 순이다.
func ExternalDifferences ¶
ExternalDifferences는 set이 외부 문서에서 쓰는 table이 database에 있는지 확인한다(docs/dbspec.md "External documents"). live는 database를 introspect한 문서다. 쓰는 table마다 table이 없거나, 외부 문서의 column이 없거나 type이나 null이 다르거나, primary key가 다르거나, unique key의 column 목록이 없으면 그 차이를 table, column 순으로 돌려준다. 외부 문서가 없으면 nil이다.
func Finalize ¶
func Finalize(ctx context.Context, c Execer, dialect Dialect, plans []*Plan, now func() time.Time, events func(ApplyEvent) error) error
Finalize는 applied인 모든 plan의 finalize step을 chain 순서로 실행해 숨긴 table과 column을 지운다.
func ImportMermaid ¶
func ImportMermaid(text, name string) (*Document, []Unsupported, []Diagnostic)
ImportMermaid는 표준 erDiagram을 name이라는 dbspec 문서로 읽고, 옮기지 못한 것을 돌려준다(docs/mermaid.md "Import"). 문법에 맞지 않는 줄은 diagnostic이다.
func InstalledDifferences ¶
func InstalledDifferences(live *Document, unsupported []Unsupported, target *Document) []string
InstalledDifferences는 database가 document set과 같은지 확인한다(docs/schema.md "Schema installation"). live는 연결의 database를 introspect한 문서, unsupported는 introspection이 읽지 못한 객체, target은 document set의 schema text 문서다. set에 없는 database의 table은 비교하지 않는다. set의 table에 읽지 못한 객체가 있으면 그 객체를 "unsupported_<kind> <table>[.<name>]: <reason>"로, 아니면 database에 있는 set의 table에서 set까지의 모든 차이를 "<kind> <table>[.<name>]"로 돌려준다. 빈 목록이면 같다.
func Introspect ¶
func Introspect(ctx context.Context, q Querier, dialect Dialect, name string) (*Document, []Unsupported, error)
Introspect는 connection의 현재 database, schema 또는 main database를 읽어 name이라는 dbspec 문서와 읽지 못한 객체 목록을 돌려준다. query 수는 table 수와 무관하다. query 실패와 문서를 만들 수 없는 catalog는 error다.
func ManifestOf ¶
func ManifestOf(documents []*Document) (*Manifest, []Diagnostic)
ManifestOf returns the manifest of the document set, whose documents are taken in document name order, or the diagnostics of an invalid set. The manifest text holds the owned documents; the external text holds, for each external document, the tables that owned documents use, with their columns, primary key and unique keys; the schema text holds the owned tables and a use line for each external document they use; and manifestHash covers the manifest text followed by the external text.
func Parse ¶
Parse parses and validates text. documents is the declared document set: each document name that a `use` line may name, mapped to its text. Parse returns the document, the positions of its declarations in source order (docs/dbspec.md "Declaration positions") and nil diagnostics, or nil, nil and every diagnostic of the document ordered by line, column and rule; never both. An encoding, header or limit error stops parsing: it follows the diagnostics found before it, and later lines are not diagnosed.
func ParsePlan ¶
func ParsePlan(text string) (*Plan, []Diagnostic)
ParsePlan은 plan 문서를 읽는다. 잘못된 문서는 위치가 붙은 diagnostic이다.
func PlanSteps ¶
func PlanSteps(source *Document, p *Plan, dialect Dialect) ([]PlanStep, []Diagnostic)
PlanSteps는 plan의 step을 dialect로 쓴다(docs/plans.md "Steps"). source는 plan이 시작하는 schema이며 빈 database이면 nil이다.
func ReadSet ¶
ReadSet reads the set file at path (docs/dbspec.md "Document sets"): the set file, its JSON, the normal form and the components of each listed path, and the bytes and identity of each listed file, in that order. It returns the listed files, or the errors ordered by step, then by path. It never checks the bytes of a listed file; the caller gives them to ReadBytes with their path.
func Recover ¶
func Recover(ctx context.Context, c Execer, dialect Dialect, plans []*Plan, now func() time.Time, events func(ApplyEvent) error) error
Recover는 중단된 plan을 catalog의 효과로 판단해 앞으로 이어 간다. 중단된 plan이 없으면 아무것도 바꾸지 않는다.
func RenderStatements ¶
func RenderStatements(documents []*Document, dialect Dialect) ([]RenderedStatement, []Diagnostic)
RenderStatements는 Render와 같은 statement를 같은 순서로 쓰고, 각 statement가 만들거나 바꾸는 table을 함께 돌려준다.
Types ¶
type Analysis ¶
type Analysis struct {
Document *Document
Positions []Position
Diagnostics []Diagnostic
Tokens []Token
}
Analysis is the result of Analyze: the result of Parse, unchanged, and the tokens of the text (docs/dbspec.md "Syntax analysis").
type ApplyError ¶
ApplyError는 명령의 실패다. Code는 locked, session, interrupted, drift, chain, failed, verify, irreversible, nulls 중 하나다.
func (*ApplyError) Error ¶
func (e *ApplyError) Error() string
func (*ApplyError) Unwrap ¶
func (e *ApplyError) Unwrap() error
type ApplyEvent ¶
ApplyEvent는 apply, recover, rollback, finalize가 알리는 일이다(docs/plans.md "Apply"). Kind는 plan, rollback, finalize, irreversible, statement, applied, verified, done 중 하나다.
type AuditSetting ¶
type AuditSetting struct {
Comments []string
History string
Column string
References string
Action string
Previous string
Exclude []string
Include []string
}
AuditSetting은 `audit into <history> column <column> references <table> action <column> previous <column> [exclude (<column>, ...) | include (<column>, ...)]`이다. Column은 audit 기록 table References의 primary key를 담는 column이다. 목록이 없으면 Exclude와 Include는 nil이고, parse한 setting은 둘 중 하나만 가진다(docs/dbspec.md "Audit").
func (*AuditSetting) Excluded ¶
func (a *AuditSetting) Excluded(t *Table) []string
Excluded는 audit trigger가 복사하지 않는 t의 column을 column 순서로 돌려준다. schema text가 쓰는 목록이다.
func (*AuditSetting) Records ¶
func (a *AuditSetting) Records(column string) bool
Records는 audit trigger가 column을 복사하는지 알린다. audit column은 언제나, exclude 목록의 column은 언제나 아니며, include 목록이 있으면 그 column만 복사한다.
type BlindIndexSetting ¶
BlindIndexSetting is `blind_index <aes column> <index column>`.
type Change ¶
Change는 diff의 변경 하나다(docs/plans.md "Diff"). Table은 target 이름이고, drop_table, drop_* 객체는 source 이름이다.
type CheckboxSetting ¶
CheckboxSetting은 한 state의 list glyph다.
type CodecSetting ¶
CodecSetting is `codec <column> <stage> ...`.
type Column ¶
type Column struct {
Comments []string
Name string
Type Type
Null bool
Identity bool
// Default is nil when the column has no default.
Default *Default
}
Column is one column line.
type ColumnName ¶
type ColumnName struct{ Table, Name string }
ColumnName은 `allow drop column <table>.<name>`의 source table과 column이다.
type ColumnRef ¶
type ColumnRef struct {
Name string
// contains filtered or unexported fields
}
ColumnRef refers to a column of the same table.
type ColumnRename ¶
type ColumnRename struct{ Table, Old, New string }
ColumnRename은 `rename column <table>.<old> <new>`이며 Table은 target 이름이다.
type ColumnSetting ¶
ColumnSetting is a setting that names one column: `updated`, `soft_delete` or `aes_version`.
type Default ¶
Default is a column default: Now for `default now`, otherwise Literal holds the literal in canonical form, such as 1.00 or 'pending'.
type Diagnostic ¶
Diagnostic is one SCHEMA_INVALID error: the rule it breaks, the 1-based line and column (in Unicode code points) of the offending token, and a message.
func Format ¶
func Format(text string, documents map[string]string) (string, []Diagnostic)
Format returns the canonical text of a document with no diagnostic, and otherwise the diagnostics and no text: a document with a diagnostic is never rewritten (docs/dbspec.md "Formatting").
func ReadBytes ¶
func ReadBytes(name string, b []byte) (string, []Diagnostic)
ReadBytes는 호출자가 자기 규칙으로 읽은 dbspec document 파일의 byte를 parse 전에 확인한다. name은 message가 파일을 가리키는 이름이다. Signature로 시작하지 않는 byte는 text 없이 line 1, column 1의 RuleSignature diagnostic 하나와 message "<name> is not a dbspec document"를, UTF-8이 아닌 byte는 첫 잘못된 byte의 줄과 칸에서 RuleEncoding diagnostic 하나와 message "<name> is not valid UTF-8"을 돌려준다. 그 밖의 byte는 diagnostic 없이 그대로 text가 된다.
func ReadFile ¶
func ReadFile(path string) (string, []Diagnostic, error)
ReadFile은 parse할 path의 dbspec document 파일을 읽고 그 byte를 path를 이름으로 ReadBytes로 확인한다. 읽을 수 없는 파일은 읽기의 error를 돌려준다.
func Render ¶
func Render(documents []*Document, dialect Dialect) ([]string, []Diagnostic)
Render writes the statements that create the tables of the document set in one dialect (docs/dialects.md "Rendered statements"), or returns the diagnostics of an invalid set. A dialect other than the three constants is a programming error and panics.
type Diagram ¶
type Diagram struct {
Comments []string
Name string
Entries []DiagramEntry
ClosingComments []string
}
Diagram places tables for a view.
type DiagramEntry ¶
DiagramEntry is `<table> at <x> <y>`.
type Difference ¶
Difference는 두 schema의 차이 하나다(docs/plans.md "Comparison"). Name은 column이나 객체의 이름이고, table 단위 차이에서는 빈 문자열이다.
type Document ¶
type Document struct {
Name string
// External은 문서가 set의 소유가 아니라 소유한 문서가 use로 쓰는 외부 문서임을
// 뜻한다. 외부 문서는 parse하고 검사하지만 렌더링, 설치, 비교, 생성하지 않는다
// (docs/dbspec.md "Documents and use"). 문서 text에는 나오지 않는다.
External bool
Uses []Use
Tables []Table
Diagrams []Diagram
// TrailingComments are comment lines that no line follows.
TrailingComments []string
}
Document is one parsed dbspec document. Slices keep document order; Emit applies the canonical order. Comments hold whole comment lines from `#` to the end of the line, attached to the line that follows them.
type Effect ¶
Effect는 statement가 효과를 냈는지 catalog나 table에서 읽는 방법이다. Kind는 table, column, index, constraint, trigger, function, sequence, rows, repeat 중 하나다. Present는 statement 뒤의 상태다.
type EntitySetting ¶
EntitySetting is `entity <name>`.
type Execer ¶
type Execer interface {
Querier
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}
Execer는 명령이 statement를 실행하고 catalog를 읽는 connection 하나다. *sql.Conn이 이를 만족하며, 명령은 lock과 session 설정을 그 connection에서만 쓴다.
type Expr ¶
type Expr interface {
// contains filtered or unexported methods
}
Expr는 check predicate나 그 operand다(docs/dbspec.md "Checks"). tree에는 괄호가 없고, emission은 and 안의 or가 필요로 하는 괄호만 쓴다.
type ForeignKey ¶
type ForeignKey struct {
Comments []string
Name string
Columns []string
Table string
References []string
OnDelete Action
OnUpdate Action
}
ForeignKey is a named foreign key from Columns to References of Table.
type HistorySetting ¶
type HistorySetting struct {
Comments []string
Table string
Row string
From string
To string
At string
}
HistorySetting은 state_machine의 history 줄이다. Row는 history table의 foreign key column, From, To와 At은 상태 전환의 이전 상태, 이후 상태와 시각 column이다.
type ImmutableSetting ¶
type ImmutableSetting struct {
Comments []string
}
ImmutableSetting is `immutable`.
type Index ¶
type Index struct {
Comments []string
Name string
Columns []IndexColumn
}
Index is a named index.
type IndexColumn ¶
IndexColumn is one index column with its direction.
type KeyPrefixSetting ¶
KeyPrefixSetting은 `key_prefix '<p>'`다: 문자 primary key의 할당 접두사다.
type LimitSetting ¶
LimitSetting은 state_machine의 limit 줄이다: 그 state의 행은 Count를 넘을 수 없다.
type Literal ¶
type Literal struct {
Text string
// contains filtered or unexported fields
}
Literal is an integer, decimal, string, true or false literal in the canonical default form of the column it meets.
type Manifest ¶
type Manifest struct {
ManifestText string
// ExternalText는 외부 문서마다 소유한 문서가 쓰는 table의 column, primary key,
// unique key만 담은 canonical text다. 외부 문서가 없으면 비어 있다.
ExternalText string
SchemaText string
ManifestHash string
SchemaHash string
}
Manifest holds the manifest and schema texts of a document set and their hashes (docs/dbspec.md, "Manifest and hashes").
type MarkSetting ¶
MarkSetting은 `markdown <column>`이다: 산문 column의 manifest 전용 표시다.
type NavigationSetting ¶
type NavigationSetting struct {
}
NavigationSetting is `navigation <foreign key> <child name> <parent name>`.
type NullCheck ¶
NullCheck는 rollback이 다시 non-null로 만드는 column이다. Column은 적용한 plan에서의 이름이고, HasDefault이면 Default가 source default의 SQL text다.
type Plan ¶
type Plan struct {
Name string
From string
RenameTables []TableRename
RenameColumns []ColumnRename
DropTables []string
DropColumns []ColumnName
// Schema는 target schema text를 parse한 문서이고 To는 그 schemaHash다.
Schema *Document
To string
// contains filtered or unexported fields
}
Plan은 parse한 plan 문서다. From이 빈 문자열이면 빈 database에서 시작한다.
type PlanStep ¶
type PlanStep struct {
Statement string
Rollback string
Irreversible string
Effect Effect
// Restore와 RollbackRestore는 RestoreIf가 참일 때 Statement와 Rollback 대신 실행하는
// statement다(rollback이 숨긴 더한 column이 table에 있을 때).
Restore string
RollbackRestore string
RestoreIf Effect
NullChecks []NullCheck
Finalize bool
}
PlanStep은 plan의 step 하나다(docs/plans.md "Steps"). Rollback이 비어 있으면 finalize step이거나 Irreversible이 그 이유를 적는다.
func AddTablesAndColumnsSteps ¶
func AddTablesAndColumnsSteps(live *Document, unsupported []Unsupported, target *Document, dialect Dialect) (added []string, steps []PlanStep, differences []string)
AddTablesAndColumnsSteps는 연결의 addTablesAndColumns가 실행할 step을 쓴다 (docs/schema.md "Adding tables and columns"). live는 연결의 database를 introspect한 문서, unsupported는 introspection이 읽지 못한 객체, target은 document set의 schema text 문서다. set에 없는 database의 table은 비교하지도 바꾸지도 않는다. database에 있는 set의 table과 set의 차이가 database에 없는 table의 create_table, null이거나 default가 있는 column의 add_column, unique가 아닌 index의 add_index뿐이면, database에 있는 set의 table에서 set까지의 plan step(docs/plans.md "Steps")과, table 이름 순으로 만드는 table은 "table", 더하는 column은 column 순서로 "table.column", 그 뒤 더하는 index는 index 순서로 "table.index"인 목록을 돌려준다. 다른 차이는 step 없이 differences에 "<kind> <table>[.<name>]"로 돌려주며, 빠진 unique key는 있는 행에서 실패할 수 있으므로 그 이유와 함께 돌려준다.
type Position ¶
Position is the place of one declaration of a parsed document (docs/dbspec.md "Declaration positions"): its kind, its path of enclosing names and its own name, and the 1-based line and column, in Unicode code points, of its name token or, for a setting and the primary key, of its keyword.
type PrimaryKey ¶
PrimaryKey is the unnamed primary key of a table.
type Querier ¶
type Querier interface {
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
}
Querier는 introspection이 catalog query를 보내는 connection이다. *sql.DB, *sql.Conn, *sql.Tx가 이를 만족한다.
type QueryObserver ¶
QueryObserver는 Querier가 구현하면 catalog query마다 그 행을 모두 읽었거나 읽다 실패했을 때 불린다. err는 query의 오류다. QueryEnded가 돌려준 오류는 introspection을 그 오류로 끝낸다.
type RenderedStatement ¶
RenderedStatement은 Render의 statement 하나와 그 statement가 만들거나 바꾸는 table이다.
type SelectExplicitSetting ¶
SelectExplicitSetting is `select explicit <column> ...`.
type Set ¶
Set is a document set read from its set file: the owned documents and the external documents, each in written order.
type SetDocument ¶
type SetDocument struct {
Name string
External bool
Document *Document
Positions []Position
Diagnostics []Diagnostic
}
SetDocument is the result of one text of a set (docs/dbspec.md "Parsing a set"): the name that the parser reads from its header, empty when the header fails; whether the text is external; and what one parse of the text returns, its document and positions or its diagnostics.
func ParseSet ¶
func ParseSet(owned, external []string) []SetDocument
ParseSet parses the texts of one document set (docs/dbspec.md "Parsing a set") and returns one SetDocument per text, owned first, each in set order. Each text's name is the name the parser reads from its header; a text whose name an earlier text has is not parsed and carries the diagnostic name.duplicate. Every other text is parsed with the texts of all other named documents as the documents its use lines name.
type SetError ¶
SetError is one error of the set reader: its rule, the path it concerns and a message that names that path.
type Settings ¶
type Settings struct {
Comments []string
Entity *EntitySetting
Updated *ColumnSetting
SoftDelete *ColumnSetting
SelectExplicit *SelectExplicitSetting
Codecs []CodecSetting
AESVersion *ColumnSetting
BlindIndexes []BlindIndexSetting
Immutable *ImmutableSetting
Audit *AuditSetting
StateMachine *StateMachineSetting
Marks []MarkSetting
Store *StoreSetting
KeyPrefix *KeyPrefixSetting
Title *ColumnSetting
Body *ColumnSetting
Order *ColumnSetting
Checkboxes []CheckboxSetting
ClosingComments []string
}
Settings is the settings block of a table. A nil field or an empty slice is an absent setting. Codecs repeat per column, BlindIndexes per AES column and Navigations per foreign key.
type StateLineSetting ¶
type StateLineSetting struct {
Comments []string
Initial bool
Terminal bool
From string
To string
State string
Requires []string
}
StateLineSetting은 전환 줄, terminal 선언 줄 또는 initial 선언 줄이다.
type StateMachineSetting ¶
type StateMachineSetting struct {
Comments []string
Column string
Lines []StateLineSetting
History *HistorySetting
Limits []LimitSetting
}
StateMachineSetting은 한 column의 상태 기계다. 줄은 선언 순서를 유지한다.
type StoreSetting ¶
type StoreSetting struct {
Comments []string
Kind string
Foreign string
Shape string
// Shard는 `shard <column> <period>` 절이며, 절이 없으면 nil이다. SQL backend는 읽지 않는다.
Shard *StoreShard
}
StoreSetting은 table의 저장 선언이다. Kind는 files, document 또는 block이다. block은 Foreign에 부모 행의 foreign key 이름을 쓰고, document와 block은 Shape에 list 또는 table을 쓴다.
type StoreShard ¶
StoreShard는 저장의 시간 shard다: Column은 non-null date 또는 datetime column이고 Period는 year, month 또는 day다.
type Table ¶
type Table struct {
Comments []string
Name string
Columns []Column
PrimaryKey PrimaryKey
Uniques []Unique
Indexes []Index
ForeignKeys []ForeignKey
Checks []Check
// Settings is nil when the table has no settings block.
Settings *Settings
// ClosingComments precede the closing brace of the table.
ClosingComments []string
}
Table is one table block.
type TableRename ¶
type TableRename struct{ Old, New string }
TableRename은 `rename table <old> <new>`다.
type Token ¶
Token is one token of the text: its 1-based line, the number of Unicode code points before it on the line, the number before the code point after it, and its class.
type Type ¶
Type is a column type with its parameters: Length for varchar(n), Precision and Scale for decimal(p,s), and Precision (fraction digits) for time(p) and datetime(p). Unused parameters are zero.
type TypeKind ¶
type TypeKind string
TypeKind names a dbspec type.
const ( TypeI16 TypeKind = "i16" TypeI32 TypeKind = "i32" TypeI64 TypeKind = "i64" TypeBool TypeKind = "bool" TypeDecimal TypeKind = "decimal" TypeF64 TypeKind = "f64" TypeVarchar TypeKind = "varchar" TypeText TypeKind = "text" TypeBytes TypeKind = "bytes" TypeUUID TypeKind = "uuid" TypeDate TypeKind = "date" TypeTime TypeKind = "time" TypeDatetime TypeKind = "datetime" )
The dbspec types.
type Unsupported ¶
Unsupported는 introspection이 dbspec으로 읽지 못한 객체다(docs/dialects.md "Introspection"). Kind는 column, index, unique, foreign_key, check, trigger, view, routine, sequence, event, partition, table 중 하나다.
func ExportMermaid ¶
func ExportMermaid(d *Document) (string, []Unsupported)
ExportMermaid는 문서 하나를 표준 erDiagram으로 쓰고, diagram이 담지 못해 뺀 것을 [kind, table, name] 순서로 돌려준다(docs/mermaid.md "Export").
Source Files
¶
- add_tables_and_columns.go
- analyze.go
- apply.go
- checks.go
- compare.go
- dbspec.go
- emit.go
- expr.go
- file.go
- introspect.go
- introspect_check.go
- introspect_mysql.go
- introspect_postgres.go
- introspect_sqlite.go
- introspect_trigger.go
- lex.go
- literal.go
- mermaid.go
- model.go
- names.go
- parse.go
- parseset.go
- plan.go
- plan_diff.go
- plan_objects.go
- plan_steps.go
- positions.go
- render.go
- set.go
- set_other.go
- settings.go
- validate.go