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

Function Example_extractFromCTE

pkg/gosqlx/example_test.go:634–648  ·  view source on GitHub ↗

Example_extractFromCTE demonstrates extracting from queries with CTEs.

()

Source from the content-addressed store, hash-verified

632
633// Example_extractFromCTE demonstrates extracting from queries with CTEs.
634func 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.
651func Example_validationWithExtraction() {

Callers

nothing calls this directly

Calls 2

ParseFunction · 0.92
ExtractMetadataFunction · 0.92

Tested by

no test coverage detected