MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / Validate

Method Validate

cmd/gosqlx/cmd/validator.go:166–219  ·  view source on GitHub ↗

Validate validates the given SQL files or patterns. This is the main validation entry point that processes file arguments, expands patterns, and validates each file using the GoSQLX parser. The method: 1. Expands file arguments (globs, directories, individual files) 2. Validates each file using to

(args []string)

Source from the content-addressed store, hash-verified

164//
165// Validate validates the given SQL files or patterns
166func (v *Validator) Validate(args []string) (*output.ValidationResult, error) {
167 startTime := time.Now()
168
169 // Expand file arguments (glob patterns, directories, etc.)
170 files, err := v.expandFileArgs(args)
171 if err != nil {
172 return nil, fmt.Errorf("failed to expand file arguments: %w", err)
173 }
174
175 if len(files) == 0 {
176 return nil, fmt.Errorf("no SQL files found matching the specified patterns")
177 }
178
179 result := &output.ValidationResult{
180 Files: make([]output.FileValidationResult, 0, len(files)),
181 }
182
183 // Validate each file
184 for _, file := range files {
185 fileResult := v.validateFile(file)
186 result.Files = append(result.Files, fileResult)
187 result.TotalFiles++
188 result.TotalBytes += fileResult.Size
189
190 if fileResult.Error != nil {
191 if !v.Opts.Quiet {
192 fmt.Fprintf(v.Err, "❌ %s: %v\n", file, fileResult.Error) // #nosec G705
193 }
194 result.InvalidFiles++
195 continue
196 }
197
198 if fileResult.Valid {
199 if !v.Opts.Quiet {
200 fmt.Fprintf(v.Out, "✅ %s: Valid SQL\n", file) // #nosec G705
201 }
202 result.ValidFiles++
203 } else {
204 if !v.Opts.Quiet {
205 fmt.Fprintf(v.Out, "❌ %s: Invalid SQL\n", file) // #nosec G705
206 }
207 result.InvalidFiles++
208 }
209 }
210
211 result.Duration = time.Since(startTime)
212
213 // Display statistics if requested
214 if v.Opts.ShowStats {
215 v.displayStats(result)
216 }
217
218 return result, nil
219}
220
221// validateFile validates a single SQL file or direct SQL input
222func (v *Validator) validateFile(filename string) output.FileValidationResult {

Callers 4

validateRunFunction · 0.95
validateFromStdinFunction · 0.95
TestValidator_ValidateFunction · 0.95
TestValidator_EmptyArgsFunction · 0.95

Calls 4

expandFileArgsMethod · 0.95
validateFileMethod · 0.95
displayStatsMethod · 0.95
ErrorfMethod · 0.65

Tested by 2

TestValidator_ValidateFunction · 0.76
TestValidator_EmptyArgsFunction · 0.76