sqlite_dialect.go 1.6 KB

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