Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
core: hand views to codegen along with tables
The dump that carries the core catalog to codegen listed tables only, so
under SQLCEXPERIMENT=coreanalyzer a view, a materialized view or a table
created from a query had no model in models.go, and a query selecting all
of one got a row struct of its own instead of the view's model.

The listing now covers the relations a query selects rows from the same
way, which is what codegen builds a model for.

In the core replay context 8 more cases pass, with no case regressing.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XZcKb4GFiZQbeo9oVmyF3m
  • Loading branch information
claude committed Sep 9, 2026
commit 94fb2a5c21358b845f8721f7ee8ec6a0523e7a7b
6 changes: 3 additions & 3 deletions internal/compiler/catalog_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
// coreResultCatalog dumps the core catalog into the legacy catalog shape a
// Result carries, so codegen sees the same table models either way a query
// set was analyzed. Relations and enums make the trip: codegen reads tables
// and their columns to build models and enums to build their Go types, and
// none of the functions or operators the core catalog also holds.
// and views with their columns to build models and enums to build their Go
// types, and none of the functions or operators the core catalog also holds.
func coreResultCatalog(c *core.Catalog) (*catalog.Catalog, error) {
cat := catalog.New("public")
namespaces, err := c.Namespaces()
Expand All @@ -23,7 +23,7 @@ func coreResultCatalog(c *core.Catalog) (*catalog.Catalog, error) {
for _, ns := range namespaces {
schema := &catalog.Schema{Name: ns.Name}
schemas[ns.Name] = schema
tables, err := c.TablesInNamespace(ns.OID)
tables, err := c.ModelClassesInNamespace(ns.OID)
if err != nil {
return nil, err
}
Expand Down
38 changes: 19 additions & 19 deletions internal/core/catalogdb/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/core/catalogdef/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ SELECT oid FROM sql_class WHERE namespace_oid = ? AND name = ?;
-- name: ClassOIDByName :one
SELECT oid FROM sql_class WHERE name = ? LIMIT 1;

-- name: ListTablesInNamespace :many
-- name: ListModelClassesInNamespace :many
SELECT oid, name FROM sql_class
WHERE namespace_oid = ? AND kind = 'r'
WHERE namespace_oid = ? AND kind IN ('r', 'v')
ORDER BY oid;

-- name: DeleteClass :exec
Expand Down
9 changes: 6 additions & 3 deletions internal/core/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ type ClassInfo struct {
Name string
}

func (c *Catalog) TablesInNamespace(namespaceOID int64) ([]ClassInfo, error) {
rows, err := c.q.ListTablesInNamespace(context.Background(), namespaceOID)
// ModelClassesInNamespace lists the relations codegen builds a model for, in
// declaration order: the tables, and the views and tables created from a
// query, whose rows a query selects the same way.
func (c *Catalog) ModelClassesInNamespace(namespaceOID int64) ([]ClassInfo, error) {
rows, err := c.q.ListModelClassesInNamespace(context.Background(), namespaceOID)
if err != nil {
return nil, fmt.Errorf("list tables in namespace %d: %w", namespaceOID, err)
return nil, fmt.Errorf("list model classes in namespace %d: %w", namespaceOID, err)
}
out := make([]ClassInfo, 0, len(rows))
for _, r := range rows {
Expand Down