mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
filer/sql: generators bind the arguments of row statements
Insert, update, find and delete now take the row key and return their arguments with the query, so a generator decides how a key maps to its columns. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK
This commit is contained in:
1 parent
88fb3c60eb
commit
4ae00a4728
8 files changed
+80
-45
No files matched your search
@@ -44,20 +44,19 @@ func ResolveCreateTableQuery(createTable string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func (gen *SqlGenPostgres) GetSqlInsert(tableName string) string {
|
||||
func (gen *SqlGenPostgres) GetSqlInsert(tableName string, key abstract_sql.RowKey, meta []byte) (string, []interface{}) {
|
||||
if gen.UpsertQueryTemplate != "" {
|
||||
return fmt.Sprintf(gen.UpsertQueryTemplate, tableName)
|
||||
} else {
|
||||
return fmt.Sprintf(`INSERT INTO "%s" (dirhash,name,directory,meta) VALUES($1,$2,$3,$4)`, tableName)
|
||||
return fmt.Sprintf(gen.UpsertQueryTemplate, tableName), key.Args(meta)
|
||||
}
|
||||
return fmt.Sprintf(`INSERT INTO "%s" (dirhash,name,directory,meta) VALUES($1,$2,$3,$4)`, tableName), key.Args(meta)
|
||||
}
|
||||
|
||||
func (gen *SqlGenPostgres) GetSqlUpdate(tableName string) string {
|
||||
return fmt.Sprintf(`UPDATE "%s" SET meta=$1 WHERE dirhash=$2 AND name=$3 AND directory=$4`, tableName)
|
||||
func (gen *SqlGenPostgres) GetSqlUpdate(tableName string, key abstract_sql.RowKey, meta []byte) (string, []interface{}) {
|
||||
return fmt.Sprintf(`UPDATE "%s" SET meta=$4 WHERE dirhash=$1 AND name=$2 AND directory=$3`, tableName), key.Args(meta)
|
||||
}
|
||||
|
||||
func (gen *SqlGenPostgres) GetSqlFind(tableName string) string {
|
||||
return fmt.Sprintf(`SELECT meta FROM "%s" WHERE dirhash=$1 AND name=$2 AND directory=$3`, tableName)
|
||||
func (gen *SqlGenPostgres) GetSqlFind(tableName string, key abstract_sql.RowKey) (string, []interface{}) {
|
||||
return fmt.Sprintf(`SELECT meta FROM "%s" WHERE dirhash=$1 AND name=$2 AND directory=$3`, tableName), key.Args()
|
||||
}
|
||||
|
||||
func (gen *SqlGenPostgres) GetSqlFindBatch(tableName string, count int) string {
|
||||
@@ -68,8 +67,8 @@ func (gen *SqlGenPostgres) GetSqlFindBatch(tableName string, count int) string {
|
||||
return fmt.Sprintf(`SELECT dirhash, name, directory, meta FROM "%s" WHERE (dirhash, name, directory) IN (%s)`, tableName, strings.Join(rows, ","))
|
||||
}
|
||||
|
||||
func (gen *SqlGenPostgres) GetSqlDelete(tableName string) string {
|
||||
return fmt.Sprintf(`DELETE FROM "%s" WHERE dirhash=$1 AND name=$2 AND directory=$3`, tableName)
|
||||
func (gen *SqlGenPostgres) GetSqlDelete(tableName string, key abstract_sql.RowKey) (string, []interface{}) {
|
||||
return fmt.Sprintf(`DELETE FROM "%s" WHERE dirhash=$1 AND name=$2 AND directory=$3`, tableName), key.Args()
|
||||
}
|
||||
|
||||
func (gen *SqlGenPostgres) GetSqlDeleteFolderChildren(tableName string) string {
|
||||
|
||||
Reference in new issue
Block a user