Documentation
¶
Index ¶
- Constants
- func OutputFormat(s string) string
- type CTERestorer
- type Formatter
- type RestoreCtx
- func (ctx *RestoreCtx) WriteKeyWord(keyWord string)
- func (ctx *RestoreCtx) WriteKeyWordWithSpecialComments(featureID string, keyWord string)
- func (ctx *RestoreCtx) WriteName(name string)
- func (ctx *RestoreCtx) WritePlain(plainText string)
- func (ctx *RestoreCtx) WritePlainf(format string, a ...any)
- func (ctx *RestoreCtx) WriteString(str string)
- func (ctx *RestoreCtx) WriteWithSpecialComments(featureID string, fn func() error) error
- type RestoreFlags
- func (rf RestoreFlags) HasKeyWordLowercaseFlag() bool
- func (rf RestoreFlags) HasKeyWordUppercaseFlag() bool
- func (rf RestoreFlags) HasNameBackQuotesFlag() bool
- func (rf RestoreFlags) HasNameDoubleQuotesFlag() bool
- func (rf RestoreFlags) HasNameLowercaseFlag() bool
- func (rf RestoreFlags) HasNameUppercaseFlag() bool
- func (rf RestoreFlags) HasRestoreBracketAroundBetweenExpr() bool
- func (rf RestoreFlags) HasRestoreBracketAroundBinaryOperation() bool
- func (rf RestoreFlags) HasRestoreForNonPrepPlanCache() bool
- func (rf RestoreFlags) HasRestoreSkipRedundantParentheses() bool
- func (rf RestoreFlags) HasRestoreWithTTLEnableOff() bool
- func (rf RestoreFlags) HasSkipPlacementRuleForRestoreFlag() bool
- func (rf RestoreFlags) HasSpacesAroundBinaryOperationFlag() bool
- func (rf RestoreFlags) HasStringDoubleQuotesFlag() bool
- func (rf RestoreFlags) HasStringEscapeBackslashFlag() bool
- func (rf RestoreFlags) HasStringSingleQuotesFlag() bool
- func (rf RestoreFlags) HasStringWithoutCharset() bool
- func (rf RestoreFlags) HasStringWithoutDefaultCharset() bool
- func (rf RestoreFlags) HasTiDBSpecialCommentFlag() bool
- func (rf RestoreFlags) HasWithoutSchemaNameFlag() bool
- func (rf RestoreFlags) HasWithoutTableNameFlag() bool
- type RestoreWriter
Constants ¶
const ( // DefaultRestoreFlags is the default value of RestoreFlags. DefaultRestoreFlags = RestoreStringSingleQuotes | RestoreKeyWordUppercase | RestoreNameBackQuotes )
Variables ¶
This section is empty.
Functions ¶
func OutputFormat ¶
OutputFormat output escape character with backslash.
Types ¶
type CTERestorer ¶
type CTERestorer struct {
CTENames []string
}
CTERestorer is used by WithClause related nodes restore.
func (*CTERestorer) IsCTETableName ¶
func (c *CTERestorer) IsCTETableName(nameL string) bool
IsCTETableName returns true if the given tableName comes from CTE.
func (*CTERestorer) RecordCTEName ¶
func (c *CTERestorer) RecordCTEName(nameL string)
RecordCTEName records the CTE name.
func (*CTERestorer) RestoreCTEFunc ¶
func (c *CTERestorer) RestoreCTEFunc() func()
RestoreCTEFunc is used to restore CTE.
type Formatter ¶
Formatter is an io.Writer extended formatter by a fmt.Printf like function Format.
func FlatFormatter ¶
FlatFormatter returns a newly created Formatter with the same functionality as the one returned by IndentFormatter except it allows a newline in the 'format' string argument of Format to pass through if the indent level is current zero.
If the indent level is non-zero then such new lines are changed to a space character. There is no indent string, the %i and %u format verbs are used solely to determine the indent level.
The FlatFormatter is intended for flattening of normally nested structure textual representation to a one top level structure per line form.
FlatFormatter(os.Stdout, " ").Format("abc%d%%e%i\nx\ny\n%uz\n", 3)
output in the form of a Go quoted string literal:
"abc3%%e x y z\n"
func IndentFormatter ¶
IndentFormatter returns a new Formatter which interprets %i and %u in the Format() formats string as indent and unindent commands. The commands can nest. The Formatter writes to io.Writer 'w' and inserts one 'indent' string per current indent level value. Behaviour of commands reaching negative indent levels is undefined.
IndentFormatter(os.Stdout, "\t").Format("abc%d%%e%i\nx\ny\n%uz\n", 3)
output:
abc3%e
x
y
z
The Go quoted string literal form of the above is:
"abc%%e\n\tx\n\tx\nz\n"
The commands can be scattered between separate invocations of Format(), i.e. the formatter keeps track of the indent level and knows if it is positioned on start of a line and should emit indentation(s). The same output as above can be produced by e.g.:
f := IndentFormatter(os.Stdout, " ")
f.Format("abc%d%%e%i\nx\n", 3)
f.Format("y\n%uz\n")
type RestoreCtx ¶
type RestoreCtx struct {
Flags RestoreFlags
In RestoreWriter
DefaultDB string
// ParentBinaryOp stores the parent opcode.Op as an int; 0 means no parent.
// Expression Restore callers set it while restoring a child so parentheses
// removal can compare the child expression's precedence with the surrounding
// operator. Callers must restore the previous value before returning.
ParentBinaryOp int
// ParentBinarySide records whether the current child is on the left or right
// side of ParentBinaryOp. It is interpreted by expression restore using the
// internal left/right constants in ast/expressions.go and is meaningful only
// together with ParentBinaryOp.
//
// Examples:
// - In `(a + b) * c`, the `(a + b)` child is the left side of `*`, so `+`
// must keep its parentheses.
// - In `a + (b * c)`, the `(b * c)` child is the right side of `+`, so `*`
// can drop its parentheses because it binds tighter.
// - In `a - (b - c)`, the right-side marker makes the same-precedence `-`
// child keep parentheses because subtraction is not associative.
//
// Callers must restore the previous value before returning.
ParentBinarySide int
// InUnaryOperation marks that a child expression is being restored as a unary
// operand. Callers must restore the previous value before returning.
InUnaryOperation bool
CTERestorer
}
RestoreCtx is `Restore` context to hold flags and writer.
func NewRestoreCtx ¶
func NewRestoreCtx(flags RestoreFlags, in RestoreWriter) *RestoreCtx
NewRestoreCtx returns a new `RestoreCtx`.
func (*RestoreCtx) WriteKeyWord ¶
func (ctx *RestoreCtx) WriteKeyWord(keyWord string)
WriteKeyWord writes the `keyWord` into writer. `keyWord` will be converted format(uppercase and lowercase for now) according to `RestoreFlags`.
func (*RestoreCtx) WriteKeyWordWithSpecialComments ¶
func (ctx *RestoreCtx) WriteKeyWordWithSpecialComments(featureID string, keyWord string)
WriteKeyWordWithSpecialComments writes a keyword with a special comment wrapped.
func (*RestoreCtx) WriteName ¶
func (ctx *RestoreCtx) WriteName(name string)
WriteName writes the name into writer `name` maybe wrapped in quotes and escaped according to RestoreFlags.
func (*RestoreCtx) WritePlain ¶
func (ctx *RestoreCtx) WritePlain(plainText string)
WritePlain writes the plain text into writer without any handling.
func (*RestoreCtx) WritePlainf ¶
func (ctx *RestoreCtx) WritePlainf(format string, a ...any)
WritePlainf write the plain text into writer without any handling.
func (*RestoreCtx) WriteString ¶
func (ctx *RestoreCtx) WriteString(str string)
WriteString writes the string into writer `str` may be wrapped in quotes and escaped according to RestoreFlags.
func (*RestoreCtx) WriteWithSpecialComments ¶
func (ctx *RestoreCtx) WriteWithSpecialComments(featureID string, fn func() error) error
WriteWithSpecialComments writes a string with a special comment wrapped.
type RestoreFlags ¶
type RestoreFlags uint64
RestoreFlags mark the Restore format
const ( RestoreStringSingleQuotes RestoreFlags = 1 << iota RestoreStringDoubleQuotes RestoreStringEscapeBackslash RestoreKeyWordUppercase RestoreKeyWordLowercase RestoreNameUppercase RestoreNameLowercase RestoreNameDoubleQuotes RestoreNameBackQuotes RestoreSpacesAroundBinaryOperation RestoreBracketAroundBinaryOperation RestoreStringWithoutCharset RestoreStringWithoutDefaultCharset RestoreTiDBSpecialComment SkipPlacementRuleForRestore RestoreWithTTLEnableOff RestoreWithoutSchemaName RestoreWithoutTableName RestoreForNonPrepPlanCache RestoreBracketAroundBetweenExpr // RestoreSkipRedundantParentheses lets expression Restore omit parentheses // that do not affect SQL semantics under the current restore context. It is // intended for canonicalization paths such as binding normalization; default // SQL restore keeps user-written parentheses for stable round-tripping. RestoreSkipRedundantParentheses )
Mutually exclusive group of `RestoreFlags`: [RestoreStringSingleQuotes, RestoreStringDoubleQuotes] [RestoreKeyWordUppercase, RestoreKeyWordLowercase] [RestoreNameUppercase, RestoreNameLowercase] [RestoreNameDoubleQuotes, RestoreNameBackQuotes] The flag with the left position in each group has a higher priority.
func (RestoreFlags) HasKeyWordLowercaseFlag ¶
func (rf RestoreFlags) HasKeyWordLowercaseFlag() bool
HasKeyWordLowercaseFlag returns a boolean indicating whether `rf` has `RestoreKeyWordLowercase` flag.
func (RestoreFlags) HasKeyWordUppercaseFlag ¶
func (rf RestoreFlags) HasKeyWordUppercaseFlag() bool
HasKeyWordUppercaseFlag returns a boolean indicating whether `rf` has `RestoreKeyWordUppercase` flag.
func (RestoreFlags) HasNameBackQuotesFlag ¶
func (rf RestoreFlags) HasNameBackQuotesFlag() bool
HasNameBackQuotesFlag returns a boolean indicating whether `rf` has `RestoreNameBackQuotes` flag.
func (RestoreFlags) HasNameDoubleQuotesFlag ¶
func (rf RestoreFlags) HasNameDoubleQuotesFlag() bool
HasNameDoubleQuotesFlag returns a boolean indicating whether `rf` has `RestoreNameDoubleQuotes` flag.
func (RestoreFlags) HasNameLowercaseFlag ¶
func (rf RestoreFlags) HasNameLowercaseFlag() bool
HasNameLowercaseFlag returns a boolean indicating whether `rf` has `RestoreNameLowercase` flag.
func (RestoreFlags) HasNameUppercaseFlag ¶
func (rf RestoreFlags) HasNameUppercaseFlag() bool
HasNameUppercaseFlag returns a boolean indicating whether `rf` has `RestoreNameUppercase` flag.
func (RestoreFlags) HasRestoreBracketAroundBetweenExpr ¶
func (rf RestoreFlags) HasRestoreBracketAroundBetweenExpr() bool
HasRestoreBracketAroundBetweenExpr returns a boolean indicating whether `rf` has `RestoreBracketAroundBetweenExpr` flag.
func (RestoreFlags) HasRestoreBracketAroundBinaryOperation ¶
func (rf RestoreFlags) HasRestoreBracketAroundBinaryOperation() bool
HasRestoreBracketAroundBinaryOperation returns a boolean indicating whether `rf` has `RestoreBracketAroundBinaryOperation` flag.
func (RestoreFlags) HasRestoreForNonPrepPlanCache ¶
func (rf RestoreFlags) HasRestoreForNonPrepPlanCache() bool
HasRestoreForNonPrepPlanCache returns a boolean indicating whether `rf` has `RestoreForNonPrepPlanCache` flag.
func (RestoreFlags) HasRestoreSkipRedundantParentheses ¶
func (rf RestoreFlags) HasRestoreSkipRedundantParentheses() bool
HasRestoreSkipRedundantParentheses returns a boolean indicating whether `rf` has `RestoreSkipRedundantParentheses` flag.
func (RestoreFlags) HasRestoreWithTTLEnableOff ¶
func (rf RestoreFlags) HasRestoreWithTTLEnableOff() bool
HasRestoreWithTTLEnableOff returns a boolean indicating whether to force set TTL_ENABLE='OFF' when restoring a TTL table
func (RestoreFlags) HasSkipPlacementRuleForRestoreFlag ¶
func (rf RestoreFlags) HasSkipPlacementRuleForRestoreFlag() bool
HasSkipPlacementRuleForRestoreFlag returns a boolean indicating whether `rf` has `SkipPlacementRuleForRestore` flag.
func (RestoreFlags) HasSpacesAroundBinaryOperationFlag ¶
func (rf RestoreFlags) HasSpacesAroundBinaryOperationFlag() bool
HasSpacesAroundBinaryOperationFlag returns a boolean indicating whether `rf` has `RestoreSpacesAroundBinaryOperation` flag.
func (RestoreFlags) HasStringDoubleQuotesFlag ¶
func (rf RestoreFlags) HasStringDoubleQuotesFlag() bool
HasStringDoubleQuotesFlag returns a boolean indicating whether `rf` has `RestoreStringDoubleQuotes` flag.
func (RestoreFlags) HasStringEscapeBackslashFlag ¶
func (rf RestoreFlags) HasStringEscapeBackslashFlag() bool
HasStringEscapeBackslashFlag returns a boolean indicating whether `rf` has `RestoreStringEscapeBackslash` flag.
func (RestoreFlags) HasStringSingleQuotesFlag ¶
func (rf RestoreFlags) HasStringSingleQuotesFlag() bool
HasStringSingleQuotesFlag returns a boolean indicating when `rf` has `RestoreStringSingleQuotes` flag.
func (RestoreFlags) HasStringWithoutCharset ¶
func (rf RestoreFlags) HasStringWithoutCharset() bool
HasStringWithoutCharset returns a boolean indicating whether `rf` has `RestoreStringWithoutCharset` flag.
func (RestoreFlags) HasStringWithoutDefaultCharset ¶
func (rf RestoreFlags) HasStringWithoutDefaultCharset() bool
HasStringWithoutDefaultCharset returns a boolean indicating whether `rf` has `RestoreStringWithoutDefaultCharset` flag.
func (RestoreFlags) HasTiDBSpecialCommentFlag ¶
func (rf RestoreFlags) HasTiDBSpecialCommentFlag() bool
HasTiDBSpecialCommentFlag returns a boolean indicating whether `rf` has `RestoreTiDBSpecialComment` flag.
func (RestoreFlags) HasWithoutSchemaNameFlag ¶
func (rf RestoreFlags) HasWithoutSchemaNameFlag() bool
HasWithoutSchemaNameFlag returns a boolean indicating when `rf` has `RestoreWithoutSchemaName` flag.
func (RestoreFlags) HasWithoutTableNameFlag ¶
func (rf RestoreFlags) HasWithoutTableNameFlag() bool
HasWithoutTableNameFlag returns a boolean indicating when `rf` has `RestoreWithoutTableName` flag.
type RestoreWriter ¶
type RestoreWriter interface {
io.Writer
io.StringWriter
}
RestoreWriter is the interface for `Restore` to write.