Fixed ql types and integrated primary keys function
This commit is contained in:
parent
133176c3fb
commit
1d806d662c
@ -20,37 +20,53 @@ func (ql) GetName() string {
|
|||||||
return "ql"
|
return "ql"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ql) Quote(key string) string {
|
||||||
|
return fmt.Sprintf(`%s`, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ql) PrimaryKeys(keys []string) string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
// Get Data Type for Sqlite Dialect
|
// Get Data Type for Sqlite Dialect
|
||||||
func (ql) DataTypeOf(field *StructField) string {
|
func (ql) DataTypeOf(field *StructField) string {
|
||||||
var dataValue, sqlType, size, additionalType = ParseFieldStructForDialect(field)
|
var dataValue, sqlType, _, additionalType = ParseFieldStructForDialect(field)
|
||||||
|
|
||||||
if sqlType == "" {
|
if sqlType == "" {
|
||||||
switch dataValue.Kind() {
|
switch dataValue.Kind() {
|
||||||
case reflect.Bool:
|
case reflect.Bool:
|
||||||
sqlType = "bool"
|
sqlType = "bool"
|
||||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uintptr:
|
case reflect.Int:
|
||||||
if field.IsPrimaryKey {
|
sqlType = "int"
|
||||||
sqlType = "integer primary key autoincrement"
|
case reflect.Int8:
|
||||||
} else {
|
sqlType = "int8"
|
||||||
sqlType = "integer"
|
case reflect.Int16:
|
||||||
}
|
sqlType = "int16"
|
||||||
case reflect.Int64, reflect.Uint64:
|
case reflect.Int32:
|
||||||
if field.IsPrimaryKey {
|
sqlType = "int32"
|
||||||
sqlType = "integer primary key autoincrement"
|
case reflect.Int64:
|
||||||
} else {
|
sqlType = "int64"
|
||||||
sqlType = "bigint"
|
case reflect.Uint:
|
||||||
}
|
sqlType = "uint"
|
||||||
case reflect.Float32, reflect.Float64:
|
case reflect.Uint8:
|
||||||
sqlType = "real"
|
sqlType = "uint8"
|
||||||
|
case reflect.Uint16:
|
||||||
|
sqlType = "uint16"
|
||||||
|
case reflect.Uint32:
|
||||||
|
sqlType = "uint32"
|
||||||
|
case reflect.Uint64:
|
||||||
|
sqlType = "uint64"
|
||||||
|
case reflect.Uintptr:
|
||||||
|
sqlType = "uint"
|
||||||
|
case reflect.Float32:
|
||||||
|
sqlType = "float32"
|
||||||
|
case reflect.Float64:
|
||||||
|
sqlType = "float64"
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
if size > 0 && size < 65532 {
|
sqlType = "string"
|
||||||
sqlType = fmt.Sprintf("varchar(%d)", size)
|
|
||||||
} else {
|
|
||||||
sqlType = "text"
|
|
||||||
}
|
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
if _, ok := dataValue.Interface().(time.Time); ok {
|
if _, ok := dataValue.Interface().(time.Time); ok {
|
||||||
sqlType = "datetime"
|
sqlType = "time"
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if _, ok := dataValue.Interface().([]byte); ok {
|
if _, ok := dataValue.Interface().([]byte); ok {
|
||||||
@ -87,3 +103,8 @@ func (s ql) HasIndex(tableName string, indexName string) bool {
|
|||||||
s.db.QueryRow("SELECT COUNT(*) FROM __Index WHERE TableName = ? AND Name = ?", tableName, indexName).Scan(&count)
|
s.db.QueryRow("SELECT COUNT(*) FROM __Index WHERE TableName = ? AND Name = ?", tableName, indexName).Scan(&count)
|
||||||
return count > 0
|
return count > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s ql) RemoveIndex(tableName string, indexName string) error {
|
||||||
|
_, err := s.db.Exec(fmt.Sprintf("BEGIN TRANSACTION; DROP INDEX %v; COMMIT;", indexName))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user