diff options
| author | Chris Lu <chris.lu@gmail.com> | 2021-01-19 13:53:16 -0800 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2021-01-19 13:53:16 -0800 |
| commit | 4c5b752b040bbbee34fdc1db61fe6e210fb11961 (patch) | |
| tree | 179a33da743be436b38f7ec5dd5c9562cd40898e /weed/filer/postgres/postgres_store.go | |
| parent | 96354208c57c69b05a9c94fc26ae13860f1f5008 (diff) | |
| download | seaweedfs-4c5b752b040bbbee34fdc1db61fe6e210fb11961.tar.xz seaweedfs-4c5b752b040bbbee34fdc1db61fe6e210fb11961.zip | |
restructuring sql stores
Diffstat (limited to 'weed/filer/postgres/postgres_store.go')
| -rw-r--r-- | weed/filer/postgres/postgres_store.go | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/weed/filer/postgres/postgres_store.go b/weed/filer/postgres/postgres_store.go index 2325568fe..783f27c10 100644 --- a/weed/filer/postgres/postgres_store.go +++ b/weed/filer/postgres/postgres_store.go @@ -14,6 +14,41 @@ const ( CONNECTION_URL_PATTERN = "host=%s port=%d sslmode=%s connect_timeout=30" ) +type SqlGenPostgres struct { +} + +var ( + _ = abstract_sql.SqlGenerator(&SqlGenPostgres{}) +) + +func (gen *SqlGenPostgres) GetSqlInsert(bucket string) string { + return "INSERT INTO filemeta (dirhash,name,directory,meta) VALUES($1,$2,$3,$4)" +} + +func (gen *SqlGenPostgres) GetSqlUpdate(bucket string) string { + return "UPDATE filemeta SET meta=$1 WHERE dirhash=$2 AND name=$3 AND directory=$4" +} + +func (gen *SqlGenPostgres) GetSqlFind(bucket string) string { + return "SELECT meta FROM filemeta WHERE dirhash=$1 AND name=$2 AND directory=$3" +} + +func (gen *SqlGenPostgres) GetSqlDelete(bucket string) string { + return "DELETE FROM filemeta WHERE dirhash=$1 AND name=$2 AND directory=$3" +} + +func (gen *SqlGenPostgres) GetSqlDeleteFolderChildren(bucket string) string { + return "DELETE FROM filemeta WHERE dirhash=$1 AND directory=$2" +} + +func (gen *SqlGenPostgres) GetSqlListExclusive(bucket string) string { + return "SELECT NAME, meta FROM filemeta WHERE dirhash=$1 AND name>$2 AND directory=$3 AND name like $4 ORDER BY NAME ASC LIMIT $5" +} + +func (gen *SqlGenPostgres) GetSqlListInclusive(bucket string) string { + return "SELECT NAME, meta FROM filemeta WHERE dirhash=$1 AND name>=$2 AND directory=$3 AND name like $4 ORDER BY NAME ASC LIMIT $5" +} + func init() { filer.Stores = append(filer.Stores, &PostgresStore{}) } @@ -41,13 +76,7 @@ func (store *PostgresStore) Initialize(configuration util.Configuration, prefix func (store *PostgresStore) initialize(user, password, hostname string, port int, database, sslmode string, maxIdle, maxOpen int) (err error) { - store.SqlInsert = "INSERT INTO filemeta (dirhash,name,directory,meta) VALUES($1,$2,$3,$4)" - store.SqlUpdate = "UPDATE filemeta SET meta=$1 WHERE dirhash=$2 AND name=$3 AND directory=$4" - store.SqlFind = "SELECT meta FROM filemeta WHERE dirhash=$1 AND name=$2 AND directory=$3" - store.SqlDelete = "DELETE FROM filemeta WHERE dirhash=$1 AND name=$2 AND directory=$3" - store.SqlDeleteFolderChildren = "DELETE FROM filemeta WHERE dirhash=$1 AND directory=$2" - store.SqlListExclusive = "SELECT NAME, meta FROM filemeta WHERE dirhash=$1 AND name>$2 AND directory=$3 AND name like $4 ORDER BY NAME ASC LIMIT $5" - store.SqlListInclusive = "SELECT NAME, meta FROM filemeta WHERE dirhash=$1 AND name>=$2 AND directory=$3 AND name like $4 ORDER BY NAME ASC LIMIT $5" + store.SqlGenerator = &SqlGenPostgres{} sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode) if user != "" { |
