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

Function Example_validationWithExtraction

pkg/gosqlx/example_test.go:651–676  ·  view source on GitHub ↗

Example_validationWithExtraction demonstrates combining validation with metadata extraction.

()

Source from the content-addressed store, hash-verified

649
650// Example_validationWithExtraction demonstrates combining validation with metadata extraction.
651func Example_validationWithExtraction() {
652 userSQL := "SELECT u.id, u.name FROM users u WHERE u.status = 'active'"
653
654 // First validate
655 if err := gosqlx.Validate(userSQL); err != nil {
656 fmt.Println("Invalid SQL")
657 return
658 }
659
660 // Parse and extract metadata
661 ast, err := gosqlx.Parse(userSQL)
662 if err != nil {
663 log.Fatal(err)
664 }
665
666 metadata := gosqlx.ExtractMetadata(ast)
667
668 // Check if accessing sensitive tables
669 sensitiveTable := "users"
670 for _, table := range metadata.Tables {
671 if table == sensitiveTable {
672 fmt.Printf("Query accesses sensitive table: %s\n", sensitiveTable)
673 }
674 }
675 // Output: Query accesses sensitive table: users
676}
677
678// Example_extractWindowFunctions demonstrates extracting window functions.
679func Example_extractWindowFunctions() {

Callers

nothing calls this directly

Calls 3

ValidateFunction · 0.92
ParseFunction · 0.92
ExtractMetadataFunction · 0.92

Tested by

no test coverage detected