Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated list of schemas to ignore based on engine #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/sqlc-dev/sqlc-gen-kotlin

go 1.19
go 1.21

require (
github.com/jinzhu/inflection v1.0.0
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/sqlc-dev/plugin-sdk-go v1.23.0 h1:iSeJhnXPlbDXlbzUEebw/DxsGzE9rdDJArl8Hvt0RMM=
Expand Down
25 changes: 23 additions & 2 deletions internal/core/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"bytes"
"errors"
"fmt"
"log"
"regexp"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -73,6 +75,21 @@ func (v QueryValue) Type() string {
panic("no type for QueryValue: " + v.Name)
}

// 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 jdbcSet(t ktType, idx int, name string) string {
if t.IsEnum && t.IsArray {
return fmt.Sprintf(`stmt.setArray(%d, conn.createArrayOf("%s", %s.map { v -> v.value }.toTypedArray()))`, idx, t.DataType, name)
Expand Down Expand Up @@ -235,8 +252,10 @@ func ktEnumValueName(value string) string {

func BuildEnums(req *plugin.GenerateRequest) []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 @@ -280,8 +299,10 @@ func memberName(name string, settings *plugin.Settings) string {

func BuildDataClasses(conf Config, req *plugin.GenerateRequest) []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