Documentation
¶
Index ¶
Constants ¶
const QueryDSLSchemaJSON = `` /* 7518-byte string literal not displayed */
QueryDSLSchemaJSON is the JSON Schema for QueryDSL as a string constant This is useful for MCP/LLM tool calls and validation
Expression Syntax (string):
- field: "name", "table.name", "$model.name"
- alias: "name as n", "field as 别名"
- function: ":MAX(field)", ":COUNT(id)", ":SUM(amount)"
- constant: "123", "0.618", "'string'"
- encrypted: "field*"
- object: "object$.foo", "object$.arr[0]"
- array: "array[0]", "array[*]", "array@"
- binding: "?:name", "?:extra.score"
- type: "field(string 50)", "price(decimal 11,2)"
Table Syntax (string):
- table: "users", "users as u"
- model: "$user", "$user as u"
Condition Syntax (object):
- standard: { "field": "score", "op": "=", "value": 20 }
- shorthand: { "field": "score", "=": 20 }
- field shorthand: { ":score": "comment", "=": 20 }
- or condition: { "or": true, "field": "name", "=": "test" }
- or shorthand: { "or :name": "comment", "=": "test" }
- value expression: { "field": "a", "=": "{b}" }
Orders Syntax:
- string array: ["id desc", "name asc"]
- object array: [{"field": "id", "sort": "desc"}]
Groups Syntax:
- string: "kind, city rollup 所有城市"
- string array: ["kind", "city rollup 所有城市"]
- object array: [{"field": "kind"}, {"field": "city", "rollup": "所有城市"}]
Variables ¶
This section is empty.
Functions ¶
func MustParse ¶
MustParse parses a DSL string and panics if validation fails. Returns the parsed QueryDSL directly for convenience.
func QueryDSLSchema ¶
func QueryDSLSchema() map[string]interface{}
QueryDSLSchema returns the JSON Schema for QueryDSL as a map
func ValidateSchema ¶
func ValidateSchema(data interface{}) error
ValidateSchema validates data against the QueryDSL JSON Schema Returns nil if valid, error with validation details otherwise
Types ¶
type Diagnostic ¶
type Diagnostic struct {
Severity Severity `json:"severity"` // Error severity level
Message string `json:"message"` // Human-readable error message
Position Position `json:"position"` // Location in source
Path string `json:"path"` // JSON path to the error (e.g., "wheres[0].field")
Code string `json:"code"` // Error code for programmatic handling
Source string `json:"source"` // The problematic source text
}
Diagnostic represents a single validation error or warning
func (Diagnostic) String ¶
func (d Diagnostic) String() string
String returns a human-readable diagnostic string
type LintResult ¶
type LintResult struct {
DSL *gou.QueryDSL `json:"dsl,omitempty"` // Parsed DSL (nil if parsing failed)
Diagnostics []Diagnostic `json:"diagnostics"` // All diagnostics found
Source string `json:"-"` // Original source
Valid bool `json:"valid"` // True if no errors (warnings allowed)
// contains filtered or unexported fields
}
LintResult contains the complete result of parsing and validating a DSL
func Lint ¶
func Lint(source string) *LintResult
Lint validates a DSL string and returns only the LintResult. Use Parse() if you need both the DSL and validation result.
func Parse ¶
func Parse(source string) (dsl *gou.QueryDSL, result *LintResult)
Parse parses a JSON DSL string and returns the parsed DSL and LintResult. If validation passes (no errors), the returned DSL can be used directly. Returns: (*gou.QueryDSL, *LintResult) - DSL is nil if parsing/validation failed
func (*LintResult) Errors ¶
func (r *LintResult) Errors() []Diagnostic
Errors returns only error-level diagnostics
func (*LintResult) FormatDiagnostics ¶
func (r *LintResult) FormatDiagnostics() string
FormatDiagnostics returns a formatted string of all diagnostics
func (*LintResult) HasErrors ¶
func (r *LintResult) HasErrors() bool
HasErrors returns true if there are any error-level diagnostics
func (*LintResult) Warnings ¶
func (r *LintResult) Warnings() []Diagnostic
Warnings returns only warning-level diagnostics
type Position ¶
type Position struct {
Line int `json:"line"` // 1-based line number
Column int `json:"column"` // 1-based column number
Offset int `json:"offset"` // 0-based byte offset
EndLine int `json:"end_line"` // 1-based end line number
EndColumn int `json:"end_column"` // 1-based end column number
EndOffset int `json:"end_offset"` // 0-based end byte offset
}
Position represents a location in the source DSL
type Severity ¶
type Severity int
Severity represents the severity level of a diagnostic
const ( // SeverityError indicates an error that prevents query execution SeverityError Severity = iota // SeverityWarning indicates a potential issue that might cause problems SeverityWarning // SeverityInfo indicates informational messages SeverityInfo // SeverityHint indicates suggestions for improvement SeverityHint )