Example_extractFromCTE demonstrates extracting from queries with CTEs.
()
| 632 | |
| 633 | // Example_extractFromCTE demonstrates extracting from queries with CTEs. |
| 634 | func Example_extractFromCTE() { |
| 635 | sql := `WITH active_users AS ( |
| 636 | SELECT id, name FROM users WHERE active = true |
| 637 | ) |
| 638 | SELECT name, COUNT(*) FROM active_users GROUP BY name` |
| 639 | |
| 640 | ast, err := gosqlx.Parse(sql) |
| 641 | if err != nil { |
| 642 | log.Fatal(err) |
| 643 | } |
| 644 | |
| 645 | metadata := gosqlx.ExtractMetadata(ast) |
| 646 | fmt.Printf("Tables found: %d\n", len(metadata.Tables)) |
| 647 | // Output: Tables found: 2 |
| 648 | } |
| 649 | |
| 650 | // Example_validationWithExtraction demonstrates combining validation with metadata extraction. |
| 651 | func Example_validationWithExtraction() { |
nothing calls this directly
no test coverage detected