postgres_sql_gen.go 1.7 KB

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