15 RegisterDialect("sqlite3", &sqlite3{})
18 func (sqlite3) GetName() string {
22 // Get Data Type for Sqlite Dialect
23 func (s *sqlite3) DataTypeOf(field *StructField) string {
24 var dataValue, sqlType, size, additionalType = ParseFieldStructForDialect(field, s)
27 switch dataValue.Kind() {
30 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uintptr:
31 if s.fieldCanAutoIncrement(field) {
32 field.TagSettingsSet("AUTO_INCREMENT", "AUTO_INCREMENT")
33 sqlType = "integer primary key autoincrement"
37 case reflect.Int64, reflect.Uint64:
38 if s.fieldCanAutoIncrement(field) {
39 field.TagSettingsSet("AUTO_INCREMENT", "AUTO_INCREMENT")
40 sqlType = "integer primary key autoincrement"
44 case reflect.Float32, reflect.Float64:
47 if size > 0 && size < 65532 {
48 sqlType = fmt.Sprintf("varchar(%d)", size)
53 if _, ok := dataValue.Interface().(time.Time); ok {
57 if IsByteArrayOrSlice(dataValue) {
64 panic(fmt.Sprintf("invalid sql type %s (%s) for sqlite3", dataValue.Type().Name(), dataValue.Kind().String()))
67 if strings.TrimSpace(additionalType) == "" {
70 return fmt.Sprintf("%v %v", sqlType, additionalType)
73 func (s sqlite3) HasIndex(tableName string, indexName string) bool {
75 s.db.QueryRow(fmt.Sprintf("SELECT count(*) FROM sqlite_master WHERE tbl_name = ? AND sql LIKE '%%INDEX %v ON%%'", indexName), tableName).Scan(&count)
79 func (s sqlite3) HasTable(tableName string) bool {
81 s.db.QueryRow("SELECT count(*) FROM sqlite_master WHERE type='table' AND name=?", tableName).Scan(&count)
85 func (s sqlite3) HasColumn(tableName string, columnName string) bool {
87 s.db.QueryRow(fmt.Sprintf("SELECT count(*) FROM sqlite_master WHERE tbl_name = ? AND (sql LIKE '%%\"%v\" %%' OR sql LIKE '%%%v %%');\n", columnName, columnName), tableName).Scan(&count)
91 func (s sqlite3) CurrentDatabase() (name string) {
93 ifaces = make([]interface{}, 3)
94 pointers = make([]*string, 3)
97 for i = 0; i < 3; i++ {
98 ifaces[i] = &pointers[i]
100 if err := s.db.QueryRow("PRAGMA database_list").Scan(ifaces...); err != nil {
103 if pointers[1] != nil {