You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.8 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. package mysql
  2. import (
  3. "fmt"
  4. "github.com/chrislusf/seaweedfs/weed/filer/abstract_sql"
  5. _ "github.com/go-sql-driver/mysql"
  6. )
  7. type SqlGenMysql struct {
  8. CreateTableSqlTemplate string
  9. DropTableSqlTemplate string
  10. }
  11. var (
  12. _ = abstract_sql.SqlGenerator(&SqlGenMysql{})
  13. )
  14. func (gen *SqlGenMysql) GetSqlInsert(tableName string) string {
  15. return fmt.Sprintf("INSERT INTO `%s` (dirhash,name,directory,meta) VALUES(?,?,?,?)", tableName)
  16. }
  17. func (gen *SqlGenMysql) GetSqlUpdate(tableName string) string {
  18. return fmt.Sprintf("UPDATE `%s` SET meta=? WHERE dirhash=? AND name=? AND directory=?", tableName)
  19. }
  20. func (gen *SqlGenMysql) GetSqlFind(tableName string) string {
  21. return fmt.Sprintf("SELECT meta FROM `%s` WHERE dirhash=? AND name=? AND directory=?", tableName)
  22. }
  23. func (gen *SqlGenMysql) GetSqlDelete(tableName string) string {
  24. return fmt.Sprintf("DELETE FROM `%s` WHERE dirhash=? AND name=? AND directory=?", tableName)
  25. }
  26. func (gen *SqlGenMysql) GetSqlDeleteFolderChildren(tableName string) string {
  27. return fmt.Sprintf("DELETE FROM `%s` WHERE dirhash=? AND directory=?", tableName)
  28. }
  29. func (gen *SqlGenMysql) GetSqlListExclusive(tableName string) string {
  30. return fmt.Sprintf("SELECT NAME, meta FROM `%s` WHERE dirhash=? AND name>? AND directory=? AND name like ? ORDER BY NAME ASC LIMIT ?", tableName)
  31. }
  32. func (gen *SqlGenMysql) GetSqlListInclusive(tableName string) string {
  33. return fmt.Sprintf("SELECT NAME, meta FROM `%s` WHERE dirhash=? AND name>=? AND directory=? AND name like ? ORDER BY NAME ASC LIMIT ?", tableName)
  34. }
  35. func (gen *SqlGenMysql) GetSqlCreateTable(tableName string) string {
  36. return fmt.Sprintf(gen.CreateTableSqlTemplate, tableName)
  37. }
  38. func (gen *SqlGenMysql) GetSqlDropTable(tableName string) string {
  39. return fmt.Sprintf(gen.DropTableSqlTemplate, tableName)
  40. }