Example_validationWithExtraction demonstrates combining validation with metadata extraction.
()
| 649 | |
| 650 | // Example_validationWithExtraction demonstrates combining validation with metadata extraction. |
| 651 | func 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. |
| 679 | func Example_extractWindowFunctions() { |
nothing calls this directly
no test coverage detected