@@ -76,7 +76,10 @@ type CodegenOptions struct {
7676}
7777
7878// TableOptions holds table-level filtering options for the gen-queries plugin.
79+ // Include is an allow-list: when non-empty, only the listed tables are
80+ // generated. Exclude is a deny-list that always takes precedence over Include.
7981type TableOptions struct {
82+ Include []string `yaml:"include,omitempty"`
8083 Exclude []string `yaml:"exclude,omitempty"`
8184}
8285
@@ -102,8 +105,20 @@ func (s *SQL) GetQueriesSet() map[string]bool {
102105 return querySet
103106}
104107
105- // GetExcludeSet returns a set of table names to skip during query generation.
106- // Entries may be unqualified table names or schema-qualified names.
108+ // GetIncludeSet returns the allow-list of table names for query generation.
109+ // Entries may be unqualified table names or schema-qualified names. An empty
110+ // set means every table is included.
111+ func (s * SQL ) GetIncludeSet () map [string ]bool {
112+ opts := s .GetOptions ()
113+ includeSet := make (map [string ]bool , len (opts .Tables .Include ))
114+ for _ , name := range opts .Tables .Include {
115+ includeSet [name ] = true
116+ }
117+ return includeSet
118+ }
119+
120+ // GetExcludeSet returns the deny-list of table names to skip during query
121+ // generation. Entries may be unqualified table names or schema-qualified names.
107122func (s * SQL ) GetExcludeSet () map [string ]bool {
108123 opts := s .GetOptions ()
109124 excludeSet := make (map [string ]bool , len (opts .Tables .Exclude ))
@@ -113,6 +128,17 @@ func (s *SQL) GetExcludeSet() map[string]bool {
113128 return excludeSet
114129}
115130
116- func tableExcluded (excludeSet map [string ]bool , schema , table string ) bool {
117- return excludeSet [table ] || excludeSet [schema + "." + table ]
131+ // tableSelected reports whether a table should have query files generated.
132+ // Exclude always takes precedence over include; an empty include set matches
133+ // every table. Both sets are checked against the unqualified table name and
134+ // the schema-qualified name (schema.table).
135+ func tableSelected (includeSet , excludeSet map [string ]bool , schema , table string ) bool {
136+ qualified := schema + "." + table
137+ if excludeSet [table ] || excludeSet [qualified ] {
138+ return false
139+ }
140+ if len (includeSet ) == 0 {
141+ return true
142+ }
143+ return includeSet [table ] || includeSet [qualified ]
118144}
0 commit comments