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.

69 lines
2.4 KiB

  1. //go:build dameng
  2. // +build dameng
  3. package dameng
  4. import (
  5. "fmt"
  6. "github.com/seaweedfs/seaweedfs/weed/filer/abstract_sql"
  7. )
  8. type SqlGenDameng struct {
  9. CreateTableSqlTemplate string
  10. DropTableSqlTemplate string
  11. UpsertQueryTemplate string
  12. }
  13. var (
  14. _ = abstract_sql.SqlGenerator(&SqlGenDameng{})
  15. )
  16. func (gen *SqlGenDameng) GetSqlInsert(tableName string) string {
  17. sql := ""
  18. if gen.UpsertQueryTemplate != "" {
  19. sql = fmt.Sprintf(`MERGE INTO %s AS target
  20. USING (SELECT ? AS dirhash, ? AS name, ? AS directory, ? AS meta FROM dual) AS source
  21. ON (target.dirhash = source.dirhash AND target.name = source.name)
  22. WHEN MATCHED THEN
  23. UPDATE SET target.meta = source.meta
  24. WHEN NOT MATCHED THEN
  25. INSERT (dirhash, name, directory, meta)
  26. VALUES (source.dirhash, source.name, source.directory, source.meta);`, tableName)
  27. } else {
  28. sql = fmt.Sprintf("INSERT INTO %s (dirhash,name,directory,meta) VALUES(?,?,?,?)", tableName)
  29. }
  30. return sql
  31. }
  32. func (gen *SqlGenDameng) GetSqlUpdate(tableName string) string {
  33. return fmt.Sprintf("UPDATE %s SET meta = ? WHERE dirhash = ? AND name = ? AND directory = ?", tableName)
  34. }
  35. func (gen *SqlGenDameng) GetSqlFind(tableName string) string {
  36. return fmt.Sprintf("SELECT meta FROM %s WHERE dirhash = ? AND name = ? AND directory = ?", tableName)
  37. }
  38. func (gen *SqlGenDameng) GetSqlDelete(tableName string) string {
  39. return fmt.Sprintf("DELETE FROM %s WHERE dirhash = ? AND name = ? AND directory = ?", tableName)
  40. }
  41. func (gen *SqlGenDameng) GetSqlDeleteFolderChildren(tableName string) string {
  42. return fmt.Sprintf("DELETE FROM %s WHERE dirhash = ? AND directory = ?", tableName)
  43. }
  44. func (gen *SqlGenDameng) GetSqlListExclusive(tableName string) string {
  45. return fmt.Sprintf("SELECT name, meta FROM %s WHERE dirhash = ? AND rowid > (SELECT IFNULL(MIN(rowid), 0) FROM %s WHERE directory = ? AND name = ?) AND directory = ? ORDER BY rowid ASC LIMIT ?", tableName, tableName)
  46. }
  47. func (gen *SqlGenDameng) GetSqlListInclusive(tableName string) string {
  48. return fmt.Sprintf("SELECT name, meta FROM %s WHERE dirhash = ? AND rowid >= (SELECT IFNULL(MIN(rowid), 0) FROM %s WHERE directory = ? AND name = ?) AND directory = ? ORDER BY rowid ASC LIMIT ?", tableName, tableName)
  49. }
  50. func (gen *SqlGenDameng) GetSqlCreateTable(tableName string) string {
  51. return fmt.Sprintf(gen.CreateTableSqlTemplate, tableName)
  52. }
  53. func (gen *SqlGenDameng) GetSqlDropTable(tableName string) string {
  54. return fmt.Sprintf(gen.DropTableSqlTemplate, tableName)
  55. }