Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ sqlc-dev:
sqlc-pg-gen:
go build -o ~/bin/sqlc-pg-gen ./internal/tools/sqlc-pg-gen

sqlc-dolphin-gen:
go build -o ~/bin/sqlc-dolphin-gen ./internal/tools/sqlc-dolphin-gen

sqlc-gen-json:
go build -o ~/bin/sqlc-gen-json ./cmd/sqlc-gen-json

Expand Down
25 changes: 23 additions & 2 deletions internal/codegen/golang/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package golang
import (
"bufio"
"fmt"
"log"
"slices"
"sort"
"strings"

Expand All @@ -13,10 +15,27 @@ import (
"github.com/sqlc-dev/sqlc/internal/plugin"
)

// getSchemasToSkip Returns a list of schemas which should not be included in the generated output
func getSchemasToSkip(req *plugin.GenerateRequest) []string {
switch req.Settings.Engine {
case "postgresql":
return []string{"pg_catalog", "information_schema"}
case "mysql":
return []string{"information_schema", "performance_schema", "sys", "mysql"}
case "sqlite":
return []string{}
default:
log.Printf("WARN internal/codegen/golang/result.go:getSchemasToSkip unhandled engine: %s\n", req.Settings.Engine)
return []string{}
}
}

func buildEnums(req *plugin.GenerateRequest, options *opts.Options) []Enum {
var enums []Enum
schemasToSkip := getSchemasToSkip(req)

for _, schema := range req.Catalog.Schemas {
if schema.Name == "pg_catalog" || schema.Name == "information_schema" {
if slices.Contains(schemasToSkip, schema.Name) {
continue
}
for _, enum := range schema.Enums {
Expand Down Expand Up @@ -62,8 +81,10 @@ func buildEnums(req *plugin.GenerateRequest, options *opts.Options) []Enum {

func buildStructs(req *plugin.GenerateRequest, options *opts.Options) []Struct {
var structs []Struct
schemasToSkip := getSchemasToSkip(req)

for _, schema := range req.Catalog.Schemas {
if schema.Name == "pg_catalog" || schema.Name == "information_schema" {
if slices.Contains(schemasToSkip, schema.Name) {
continue
}
for _, table := range schema.Tables {
Expand Down
23 changes: 16 additions & 7 deletions internal/engine/dolphin/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ import (
"github.com/sqlc-dev/sqlc/internal/sql/catalog"
)

// toPointer converts an int to a pointer without a temporary
// variable at the call-site, and is used by the generated schemas
func toPointer(x int) *int {
return &x
}

func NewCatalog() *catalog.Catalog {
def := "public" // TODO: What is the default database for MySQL?
return &catalog.Catalog{
DefaultSchema: def,
Schemas: []*catalog.Schema{
defaultSchema(def),
},
Extensions: map[string]struct{}{},
}

c := catalog.New(def)
// New() creates an empty schema which we'll replace with MySQL stdlib functions
c.Schemas[0] = defaultSchema(def)
c.Schemas = append(c.Schemas, genInformationSchema())
c.Schemas = append(c.Schemas, genPerformanceSchema())
c.Schemas = append(c.Schemas, genSysSchema())
c.Schemas = append(c.Schemas, genMysqlCatalog())

return c
}
Loading