mysql_sql_gen.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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(bucket string) string {
  15. return fmt.Sprintf("INSERT INTO %s (dirhash,name,directory,meta) VALUES(?,?,?,?)", bucket)
  16. }
  17. func (gen *SqlGenMysql) GetSqlUpdate(bucket string) string {
  18. return fmt.Sprintf("UPDATE %s SET meta=? WHERE dirhash=? AND name=? AND directory=?", bucket)
  19. }
  20. func (gen *SqlGenMysql) GetSqlFind(bucket string) string {
  21. return fmt.Sprintf("SELECT meta FROM %s WHERE dirhash=? AND name=? AND directory=?", bucket)
  22. }
  23. func (gen *SqlGenMysql) GetSqlDelete(bucket string) string {
  24. return fmt.Sprintf("DELETE FROM %s WHERE dirhash=? AND name=? AND directory=?", bucket)
  25. }
  26. func (gen *SqlGenMysql) GetSqlDeleteFolderChildren(bucket string) string {
  27. return fmt.Sprintf("DELETE FROM %s WHERE dirhash=? AND directory=?", bucket)
  28. }
  29. func (gen *SqlGenMysql) GetSqlListExclusive(bucket 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 ?", bucket)
  31. }
  32. func (gen *SqlGenMysql) GetSqlListInclusive(bucket 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 ?", bucket)
  34. }
  35. func (gen *SqlGenMysql) GetSqlCreateTable(bucket string) string {
  36. return fmt.Sprintf(gen.CreateTableSqlTemplate, bucket)
  37. }
  38. func (gen *SqlGenMysql) GetSqlDropTable(bucket string) string {
  39. return fmt.Sprintf(gen.DropTableSqlTemplate, bucket)
  40. }