{"record":{"id":"3ad070bf3b636579","repo":"geektutu/7days-golang","slug":"invalid-sql-type-s-s","errorCode":null,"errorMessage":"invalid sql type %s (%s)","messagePattern":"invalid sql type (.+?) \\((.+?)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gee-orm/day2-reflect-schema/dialect/sqlite3.go","lineNumber":38,"sourceCode":"\tcase reflect.Bool:\n\t\treturn \"bool\"\n\tcase reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32,\n\t\treflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uintptr:\n\t\treturn \"integer\"\n\tcase reflect.Int64, reflect.Uint64:\n\t\treturn \"bigint\"\n\tcase reflect.Float32, reflect.Float64:\n\t\treturn \"real\"\n\tcase reflect.String:\n\t\treturn \"text\"\n\tcase reflect.Array, reflect.Slice:\n\t\treturn \"blob\"\n\tcase reflect.Struct:\n\t\tif _, ok := typ.Interface().(time.Time); ok {\n\t\t\treturn \"datetime\"\n\t\t}\n\t}\n\tpanic(fmt.Sprintf(\"invalid sql type %s (%s)\", typ.Type().Name(), typ.Kind()))\n}\n\n// TableExistSQL returns SQL that judge whether the table exists in database\nfunc (s *sqlite3) TableExistSQL(tableName string) (string, []interface{}) {\n\targs := []interface{}{tableName}\n\treturn \"SELECT name FROM sqlite_master WHERE type='table' and name = ?\", args\n}\n","sourceCodeStart":20,"sourceCodeEnd":46,"githubUrl":"https://github.com/geektutu/7days-golang/blob/cf3644382101dc13e7fd92e8f5c66cabc51bcd3b/gee-orm/day2-reflect-schema/dialect/sqlite3.go#L20-L46","documentation":"sqlite3.DataTypeOf panics when a schema field's reflect type has no mapping to a SQLite column type. The dialect maps Bool/Int/Float/String/Bytes/Blob and time.Time structs; anything else (slices, maps, pointers, custom structs) is unsupported and triggers this fail-fast panic during schema parsing.","triggerScenarios":"Defining a Go struct with a field whose type is not one of the supported kinds (e.g. a nested struct other than time.Time, a map, a slice, or a custom named type outside the switch) and calling geeorm.Open on it or New with such a schema.","commonSituations":"Modeling nested objects (addresses, tags) directly in the struct; embedding a custom value type; renaming a field's type from string to a custom type after a refactor.","solutions":["Change the unsupported field to a supported type (int, string, float64, []byte, bool, time.Time)","Serialize complex fields to []byte or string (JSON) and store that","Add a case to the dialect switch to map the new kind to a SQL type","Tag or exclude the field from the schema if it should not be persisted"],"exampleFix":"// before\ntype User struct {\n    Tags map[string]string\n}\n// after\ntype User struct {\n    Tags string // store JSON: json.Marshal(tags) before Save\n}","handlingStrategy":"validation","validationCode":"func checkSchemaTypes(v interface{}) error {\n    t := reflect.TypeOf(v).Elem()\n    for i := 0; i < t.NumField(); i++ {\n        switch t.Field(i).Type.Kind() {\n        case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,\n            reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,\n            reflect.Float32, reflect.Float64, reflect.String, reflect.Slice:\n        case reflect.Struct:\n            if t.Field(i).Type != reflect.TypeOf(time.Time{}) {\n                return fmt.Errorf(\"field %s: unsupported type %s\", t.Field(i).Name, t.Field(i).Type)\n            }\n        default:\n            return fmt.Errorf(\"field %s: unsupported kind %s\", t.Field(i).Name, t.Field(i).Type.Kind())\n        }\n    }\n    return nil\n}","typeGuard":"func isSupportedColumnKind(k reflect.Kind) bool {\n    switch k {\n    case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,\n        reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,\n        reflect.Float32, reflect.Float64, reflect.String, reflect.Slice:\n        return true\n    }\n    return false\n}","tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        if s, ok := r.(string); ok && strings.HasPrefix(s, \"invalid sql type\") {\n            err = fmt.Errorf(\"schema field not mappable to sqlite: %s\", s)\n        } else { panic(r) }\n    }\n}()","preventionTips":["Keep model fields to primitives, []byte, string, and time.Time","Serialize nested structures as JSON text columns","Run schema parse in a test at CI time so bad fields surface before runtime"],"tags":["go","panic","sqlite","orm","schema"],"backgroundTag":"unsupported-field-type","analyzedSha":"cf3644382101dc13e7fd92e8f5c66cabc51bcd3b","analyzedAt":"2026-09-03T18:31:24.087Z","contentChangedAt":"2026-09-03T18:31:24.087Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}