sqlite_dialect.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package migrator
  2. type Sqlite3 struct {
  3. BaseDialect
  4. }
  5. func NewSqlite3Dialect() *Sqlite3 {
  6. d := Sqlite3{}
  7. d.BaseDialect.dialect = &d
  8. d.BaseDialect.driverName = SQLITE
  9. return &d
  10. }
  11. func (db *Sqlite3) SupportEngine() bool {
  12. return false
  13. }
  14. func (db *Sqlite3) Quote(name string) string {
  15. return "`" + name + "`"
  16. }
  17. func (db *Sqlite3) QuoteStr() string {
  18. return "`"
  19. }
  20. func (db *Sqlite3) AutoIncrStr() string {
  21. return "AUTOINCREMENT"
  22. }
  23. func (db *Sqlite3) SqlType(c *Column) string {
  24. switch c.Type {
  25. case DB_Date, DB_DateTime, DB_TimeStamp, DB_Time:
  26. return DB_DateTime
  27. case DB_TimeStampz:
  28. return DB_Text
  29. case DB_Char, DB_Varchar, DB_NVarchar, DB_TinyText, DB_Text, DB_MediumText, DB_LongText:
  30. return DB_Text
  31. case DB_Bit, DB_TinyInt, DB_SmallInt, DB_MediumInt, DB_Int, DB_Integer, DB_BigInt, DB_Bool:
  32. return DB_Integer
  33. case DB_Float, DB_Double, DB_Real:
  34. return DB_Real
  35. case DB_Decimal, DB_Numeric:
  36. return DB_Numeric
  37. case DB_TinyBlob, DB_Blob, DB_MediumBlob, DB_LongBlob, DB_Bytea, DB_Binary, DB_VarBinary:
  38. return DB_Blob
  39. case DB_Serial, DB_BigSerial:
  40. c.IsPrimaryKey = true
  41. c.IsAutoIncrement = true
  42. c.Nullable = false
  43. return DB_Integer
  44. default:
  45. return c.Type
  46. }
  47. }
  48. func (db *Sqlite3) TableCheckSql(tableName string) (string, []interface{}) {
  49. args := []interface{}{tableName}
  50. return "SELECT name FROM sqlite_master WHERE type='table' and name = ?", args
  51. }