-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into julien/system-test
- Loading branch information
Showing
29 changed files
with
1,489 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package postgres | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"strings" | ||
) | ||
|
||
// delete deletes the row with the provided key from the table. | ||
func (tm *objectIndexer) delete(ctx context.Context, conn dbConn, key interface{}) error { | ||
buf := new(strings.Builder) | ||
var params []interface{} | ||
var err error | ||
if !tm.options.disableRetainDeletions && tm.typ.RetainDeletions { | ||
params, err = tm.retainDeleteSqlAndParams(buf, key) | ||
} else { | ||
params, err = tm.deleteSqlAndParams(buf, key) | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
|
||
sqlStr := buf.String() | ||
tm.options.logger.Info("Delete", "sql", sqlStr, "params", params) | ||
_, err = conn.ExecContext(ctx, sqlStr, params...) | ||
return err | ||
} | ||
|
||
// deleteSqlAndParams generates a DELETE statement and binding parameters for the provided key. | ||
func (tm *objectIndexer) deleteSqlAndParams(w io.Writer, key interface{}) ([]interface{}, error) { | ||
_, err := fmt.Fprintf(w, "DELETE FROM %q", tm.tableName()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
_, keyParams, err := tm.whereSqlAndParams(w, key, 1) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
_, err = fmt.Fprintf(w, ";") | ||
return keyParams, err | ||
} | ||
|
||
// retainDeleteSqlAndParams generates an UPDATE statement to set the _deleted column to true for the provided key | ||
// which is used when the table is set to retain deletions mode. | ||
func (tm *objectIndexer) retainDeleteSqlAndParams(w io.Writer, key interface{}) ([]interface{}, error) { | ||
_, err := fmt.Fprintf(w, "UPDATE %q SET _deleted = TRUE", tm.tableName()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
_, keyParams, err := tm.whereSqlAndParams(w, key, 1) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
_, err = fmt.Fprintf(w, ";") | ||
return keyParams, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.