Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: MySQL parameter binding compatibility with SQLAlchemy#91

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
santinalbrowns wants to merge1 commit intosqlc-dev:main
base:main
Choose a base branch
Loading
fromsantinalbrowns:fix/mysql-parameter-binding
Open
Show file tree
Hide file tree
Changes fromall 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
12 changes: 11 additions & 1 deletioninternal/gen.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -193,8 +193,10 @@ func pyInnerType(req *plugin.GenerateRequest, col *plugin.Column) string {
switch req.Settings.Engine {
case "postgresql":
return postgresType(req, col)
case "mysql":
return mysqlType(req, col)
default:
log.Println("unsupported engine type")
log.Printf("unsupported engine type: %s\n", req.Settings.Engine)
return "Any"
}
}
Expand DownExpand Up@@ -360,6 +362,14 @@ func sqlalchemySQL(s, engine string) string {
if engine == "postgresql" {
return postgresPlaceholderRegexp.ReplaceAllString(s, ":p$1")
}
if engine == "mysql" {
// Convert MySQL ? placeholders to named parameters for SQLAlchemy compatibility
i := 1
for strings.Contains(s, "?") {
s = strings.Replace(s, "?", fmt.Sprintf(":p%d", i), 1)
i++
}
}
return s
}

Expand Down
53 changes: 53 additions & 0 deletionsinternal/mysql_type.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
package python

import (
"log"

"github.com/sqlc-dev/plugin-sdk-go/plugin"
"github.com/sqlc-dev/plugin-sdk-go/sdk"
)

func mysqlType(req *plugin.GenerateRequest, col *plugin.Column) string {
columnType := sdk.DataType(col.Type)

switch columnType {
case "tinyint", "smallint", "mediumint", "int", "integer", "bigint":
return "int"
case "float", "double", "real":
return "float"
case "decimal", "numeric":
return "decimal.Decimal"
case "bit", "boolean", "bool":
return "bool"
case "json":
return "Any"
case "binary", "varbinary", "blob", "tinyblob", "mediumblob", "longblob":
return "memoryview"
case "date":
return "datetime.date"
case "time":
return "datetime.time"
case "datetime", "timestamp":
return "datetime.datetime"
case "char", "varchar", "text", "tinytext", "mediumtext", "longtext":
return "str"
case "enum", "set":
return "str"
default:
for _, schema := range req.Catalog.Schemas {
if schema.Name == "information_schema" || schema.Name == "mysql" {
continue
}
for _, enum := range schema.Enums {
if columnType == enum.Name {
if schema.Name == req.Catalog.DefaultSchema {
return "models." + modelName(enum.Name, req.Settings)
}
return "models." + modelName(schema.Name+"_"+enum.Name, req.Settings)
}
}
}
log.Printf("unknown MySQL type: %s\n", columnType)
return "Any"
}
}

[8]ページ先頭

©2009-2025 Movatter.jp