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.

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