geektutu/7days-golang · error
invalid sql type %s (%s)
Error message
invalid sql type %s (%s)
What it means
Same 'invalid sql type' panic as errors 103/104, in the day4-chain-operation stage of gee-orm. The sqlite3 dialect cannot map the reflect.Type of a schema field to a column type and fails fast during schema parsing.
Source
Thrown at gee-orm/day4-chain-operation/dialect/sqlite3.go:38
case reflect.Bool:
return "bool"
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32,
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uintptr:
return "integer"
case reflect.Int64, reflect.Uint64:
return "bigint"
case reflect.Float32, reflect.Float64:
return "real"
case reflect.String:
return "text"
case reflect.Array, reflect.Slice:
return "blob"
case reflect.Struct:
if _, ok := typ.Interface().(time.Time); ok {
return "datetime"
}
}
panic(fmt.Sprintf("invalid sql type %s (%s)", typ.Type().Name(), typ.Kind()))
}
// TableExistSQL returns SQL that judge whether the table exists in database
func (s *sqlite3) TableExistSQL(tableName string) (string, []interface{}) {
args := []interface{}{tableName}
return "SELECT name FROM sqlite_master WHERE type='table' and name = ?", args
}
View on GitHub (pinned to cf36443821)
Solutions
- Map the field to a supported primitive or []byte/string serialized form
- Extend the dialect's DataTypeOf switch with the needed kind
- Exclude the field from persistence
Example fix
// before
type Account struct {
Balance Money // custom struct type
}
// after
type Account struct {
BalanceCents int64
} Defensive patterns
Strategy: validation
Validate before calling
if err := checkSchemaTypes(&MyModel{}); err != nil {
log.Fatalf("model not persistable: %v", err)
}
_ = geeorm.Open(db, "sqlite3", "..." ) Type guard
func isSQLiteMappable(t reflect.Type) bool {
if t == reflect.TypeOf(time.Time{}) { return true }
switch t.Kind() {
case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
reflect.Float32, reflect.Float64, reflect.String, reflect.Slice:
return true
}
return false
} Try / catch
defer func() {
if r := recover(); r != nil {
if s, ok := r.(string); ok && strings.Contains(s, "invalid sql type") {
err = fmt.Errorf("bad model schema: %s", s)
} else { panic(r) }
}
}() Prevention
- Restrict model fields to SQL-mappable primitives
- Convert custom value types to primitive columns (e.g. int64 cents)
- Test schema parsing whenever a model changes
When it happens
Trigger: geeorm.Open or table creation against a struct containing an unsupported field kind; chained query building that first parses the schema triggers it.
Common situations: Evolving models with nested structs or slices; using custom numeric types (e.g. type Money struct) in model fields.
Related errors
- invalid sql type %s (%s)
- invalid sql type %s (%s)
- invalid sql type %s (%s)
- invalid sql type %s (%s)
- panic(p)
AI-assisted analysis of geektutu/7days-golang@cf36443821 (2026-09-03).
Data as JSON: /api/errors/1ec27d3a1cc39c18.
Report an issue: GitHub.