Skip to content

Commit 28e4a86

Browse files
Working on adding SQLite support. Seems to be working... for now.
1 parent 12c384c commit 28e4a86

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

internal/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ func columnsToStruct(req *plugin.GenerateRequest, name string, columns []pyColum
368368
}
369369

370370
var postgresPlaceholderRegexp = regexp.MustCompile(`\B\$(\d+)\b`)
371-
var sqlitePlaceholderRegexp = regexp.MustCompile(`\B\?(\d+)\b`)
371+
var sqlitePlaceholderRegexp = regexp.MustCompile(`\B[?$@](\d+)\b`)
372372

373373
// Sqlalchemy uses ":name" for placeholders, so "$N" is converted to ":pN"
374374
// This also means ":" has special meaning to sqlalchemy, so it must be escaped.

internal/sqlite_type.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,35 @@ package python
22

33
import (
44
"log"
5+
"strings"
56

67
"github.com/sqlc-dev/plugin-sdk-go/plugin"
78
"github.com/sqlc-dev/plugin-sdk-go/sdk"
89
)
910

1011
func sqliteType(req *plugin.GenerateRequest, col *plugin.Column) string {
11-
columnType := sdk.DataType(col.Type)
12+
columnType := strings.ToLower(sdk.DataType(col.Type))
1213

1314
switch columnType {
14-
case "INTEGER", "INT", "TINYINT", "SMALLINT", "MEDIUMINT", "BIGINT", "INT2", "INT8":
15+
case "int", "integer", "tinyint", "smallint", "mediumint", "bigint", "unsigned big int", "int2", "int8":
1516
return "int"
16-
case "REAL", "DOUBLE", "DOUBLE PRECISION", "FLOAT":
17+
case "real", "double", "double precision", "float":
1718
return "float"
18-
case "NUMERIC", "DECIMAL":
19+
case "numeric", "decimal":
1920
return "decimal.Decimal"
20-
case "BOOLEAN":
21+
case "boolean":
2122
return "bool"
22-
case "JSON":
23+
case "json":
2324
return "Any"
24-
case "BLOB":
25+
case "blob":
2526
return "memoryview"
26-
case "DATE":
27+
case "date":
2728
return "datetime.date"
28-
case "TIME":
29-
return "datetime.time"
30-
case "DATETIME", "TIMESTAMP":
29+
case "datetime":
3130
return "datetime.datetime"
32-
case "TEXT", "CHARACTER", "VARCHAR", "NCHAR", "NVARCHAR", "CLOB":
31+
case "text", "character", "varchar", "nchar", "nvarchar", "clob":
3332
return "str"
3433
default:
35-
// SQLite doesn't have built-in UUID, INET, CIDR, MACADDR, or INTERVAL types
36-
// It also doesn't have an ENUM type, but we'll keep the enum check for consistency
3734
for _, schema := range req.Catalog.Schemas {
3835
for _, enum := range schema.Enums {
3936
if columnType == enum.Name {

0 commit comments

Comments
 (0)