Skip to content

Remove the deprecated mysql package #793

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

Merged
merged 3 commits into from
Nov 19, 2020
Merged
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 examples/authors/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{
"schema": "mysql/schema.sql",
"queries": "mysql/query.sql",
"engine": "mysql:beta",
"engine": "mysql",
"gen": {
"go": {
"package": "authors",
Expand Down
2 changes: 1 addition & 1 deletion examples/booktest/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"path": "mysql",
"schema": "mysql/schema.sql",
"queries": "mysql/query.sql",
"engine": "mysql:beta"
"engine": "mysql"
}
]
}
6 changes: 3 additions & 3 deletions examples/kotlin/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
{
"schema": "src/main/resources/authors/mysql/schema.sql",
"queries": "src/main/resources/authors/mysql/query.sql",
"engine": "mysql:beta",
"engine": "mysql",
"gen": {
"kotlin": {
"out": "src/main/kotlin/com/example/authors/mysql",
Expand All @@ -59,7 +59,7 @@
{
"schema": "src/main/resources/booktest/mysql/schema.sql",
"queries": "src/main/resources/booktest/mysql/query.sql",
"engine": "mysql:beta",
"engine": "mysql",
"gen": {
"kotlin": {
"out": "src/main/kotlin/com/example/booktest/mysql",
Expand All @@ -70,7 +70,7 @@
{
"schema": "src/main/resources/ondeck/mysql/schema",
"queries": "src/main/resources/ondeck/mysql/query",
"engine": "mysql:beta",
"engine": "mysql",
"gen": {
"kotlin": {
"out": "src/main/kotlin/com/example/ondeck/mysql",
Expand Down
2 changes: 1 addition & 1 deletion examples/ondeck/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"name": "ondeck",
"schema": "mysql/schema",
"queries": "mysql/query",
"engine": "mysql:beta",
"engine": "mysql",
"emit_json_tags": true,
"emit_prepared_queries": true,
"emit_interface": true
Expand Down
54 changes: 13 additions & 41 deletions internal/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/kyleconroy/sqlc/internal/config"
"github.com/kyleconroy/sqlc/internal/debug"
"github.com/kyleconroy/sqlc/internal/multierr"
"github.com/kyleconroy/sqlc/internal/mysql"
"github.com/kyleconroy/sqlc/internal/opts"
)

Expand Down Expand Up @@ -147,32 +146,22 @@ func Generate(e Env, dir string, stderr io.Writer) (map[string]string, error) {
name = combo.Kotlin.Package
}

result, errored := parse(e, name, dir, sql.SQL, combo, parseOpts, stderr)
if errored {
break
}

var files map[string]string
var out string

// TODO: Note about how this will be going away
if sql.Engine == config.EngineMySQL {
result, errored := parseMySQL(e, name, dir, sql.SQL, combo, parseOpts, stderr)
if errored {
break
}
switch {
case sql.Gen.Go != nil:
out = combo.Go.Out
files, err = golang.DeprecatedGenerate(result, combo)
} else {
result, errored := parse(e, name, dir, sql.SQL, combo, parseOpts, stderr)
if errored {
break
}
switch {
case sql.Gen.Go != nil:
out = combo.Go.Out
files, err = golang.Generate(result, combo)
case sql.Gen.Kotlin != nil:
out = combo.Kotlin.Out
files, err = kotlin.Generate(result, combo)
default:
panic("missing language backend")
}
files, err = golang.Generate(result, combo)
case sql.Gen.Kotlin != nil:
out = combo.Kotlin.Out
files, err = kotlin.Generate(result, combo)
default:
panic("missing language backend")
}

if err != nil {
Expand All @@ -193,23 +182,6 @@ func Generate(e Env, dir string, stderr io.Writer) (map[string]string, error) {
return output, nil
}

// Experimental MySQL support
func parseMySQL(e Env, name, dir string, sql config.SQL, combo config.CombinedSettings, parserOpts opts.Parser, stderr io.Writer) (golang.Generateable, bool) {
q, err := mysql.GeneratePkg(name, sql.Schema, sql.Queries, combo)
if err != nil {
fmt.Fprintf(stderr, "# package %s\n", name)
if parserErr, ok := err.(*multierr.Error); ok {
for _, fileErr := range parserErr.Errs() {
printFileErr(stderr, dir, fileErr)
}
} else {
fmt.Fprintf(stderr, "error parsing schema: %s\n", err)
}
return nil, true
}
return q, false
}

func parse(e Env, name, dir string, sql config.SQL, combo config.CombinedSettings, parserOpts opts.Parser, stderr io.Writer) (*compiler.Result, bool) {
c := compiler.NewCompiler(sql, combo)
if err := c.ParseCatalog(sql.Schema); err != nil {
Expand Down
4 changes: 0 additions & 4 deletions internal/codegen/golang/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,6 @@ func (t *tmplCtx) OutputQuery(sourceName string) bool {
return t.SourceName == sourceName
}

func DeprecatedGenerate(r Generateable, settings config.CombinedSettings) (map[string]string, error) {
return generate(settings, r.Enums(settings), r.Structs(settings), r.GoQueries(settings))
}

func Generate(r *compiler.Result, settings config.CombinedSettings) (map[string]string, error) {
enums := buildEnums(r, settings)
structs := buildStructs(r, settings)
Expand Down
2 changes: 1 addition & 1 deletion internal/codegen/golang/go_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func goInnerType(r *compiler.Result, col *compiler.Column, settings config.Combi

// TODO: Extend the engine interface to handle types
switch settings.Package.Engine {
case config.EngineMySQL, config.EngineMySQLBeta:
case config.EngineMySQL:
return mysqlType(r, col, settings)
case config.EnginePostgreSQL:
return postgresType(r, col, settings)
Expand Down
2 changes: 1 addition & 1 deletion internal/codegen/kotlin/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func makeType(r *compiler.Result, col *compiler.Column, settings config.Combined
func ktInnerType(r *compiler.Result, col *compiler.Column, settings config.CombinedSettings) (string, bool) {
// TODO: Extend the engine interface to handle types
switch settings.Package.Engine {
case config.EngineMySQL, config.EngineMySQLBeta:
case config.EngineMySQL:
return mysqlType(r, col, settings)
case config.EnginePostgreSQL:
return postgresType(r, col, settings)
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewCompiler(conf config.SQL, combo config.CombinedSettings) *Compiler {
case config.EngineXLemon:
c.parser = sqlite.NewParser()
c.catalog = catalog.New("main")
case config.EngineMySQL, config.EngineMySQLBeta:
case config.EngineMySQL:
c.parser = dolphin.NewParser()
c.catalog = dolphin.NewCatalog()
case config.EnginePostgreSQL:
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (c *Compiler) expand(qc *QueryCatalog, raw *ast.RawStmt) ([]source.Edit, er
func (c *Compiler) quoteIdent(ident string) string {
if c.parser.IsReservedKeyword(ident) {
switch c.conf.Engine {
case config.EngineMySQL, config.EngineMySQLBeta:
case config.EngineMySQL:
return "`" + ident + "`"
default:
return "\"" + ident + "\""
Expand Down
1 change: 0 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func (p *Paths) UnmarshalYAML(unmarshal func(interface{}) error) error {

const (
EngineMySQL Engine = "mysql"
EngineMySQLBeta Engine = "mysql:beta"
EnginePostgreSQL Engine = "postgresql"

// Experimental engines
Expand Down
2 changes: 1 addition & 1 deletion internal/endtoend/testdata/alias/mysql/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages": [
{
"path": "go",
"engine": "mysql:beta",
"engine": "mysql",
"name": "querytest",
"schema": "query.sql",
"queries": "query.sql"
Expand Down
2 changes: 1 addition & 1 deletion internal/endtoend/testdata/column_as/mysql/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": "1",
"packages": [
{
"engine": "mysql:beta",
"engine": "mysql",
"path": "go",
"name": "querytest",
"schema": "query.sql",
Expand Down
2 changes: 1 addition & 1 deletion internal/endtoend/testdata/comment_syntax/mysql/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages": [
{
"path": "go",
"engine": "mysql:beta",
"engine": "mysql",
"name": "querytest",
"schema": "query.sql",
"queries": "query.sql"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"path": "go",
"schema": "schema.sql",
"queries": "query.sql",
"engine": "mysql:beta"
"engine": "mysql"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages": [
{
"path": "go",
"engine": "mysql:beta",
"engine": "mysql",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"queries": "query.sql"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages": [
{
"path": "go",
"engine": "mysql:beta",
"engine": "mysql",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"queries": "query.sql"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages": [
{
"path": "go",
"engine": "mysql:beta",
"engine": "mysql",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"queries": "query.sql"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages": [
{
"path": "go",
"engine": "mysql:beta",
"engine": "mysql",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"queries": "query.sql"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages": [
{
"path": "go",
"engine": "mysql:beta",
"engine": "mysql",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"queries": "query.sql"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages": [
{
"path": "go",
"engine": "mysql:beta",
"engine": "mysql",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"queries": "query.sql"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages": [
{
"path": "go",
"engine": "mysql:beta",
"engine": "mysql",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"queries": "query.sql"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages": [
{
"path": "go",
"engine": "mysql:beta",
"engine": "mysql",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"queries": "query.sql"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"queries": "query.sql"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"queries": "query.sql"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"queries": "query.sql"
}
]
}
}
2 changes: 1 addition & 1 deletion internal/endtoend/testdata/ddl_comment/mysql/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages": [
{
"path": "go",
"engine": "mysql:beta",
"engine": "mysql",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"queries": "query.sql"
}
]
}
}
2 changes: 1 addition & 1 deletion internal/endtoend/testdata/ddl_create_enum/mysql/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages": [
{
"path": "go",
"engine": "mysql:beta",
"engine": "mysql",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
Expand Down
Loading