diff --git a/database/sql_helper.go b/database/sql_helper.go index f6841cca7df532a1e281166efab5e344e3a451af_ZGF0YWJhc2Uvc3FsX2hlbHBlci5nbw==..71b3c94262a3927944800dd03904734c6429b408_ZGF0YWJhc2Uvc3FsX2hlbHBlci5nbw== 100644 --- a/database/sql_helper.go +++ b/database/sql_helper.go @@ -54,6 +54,7 @@ } // GetWhere loads a mapped structure +// ex: GetWhere(account, squirrel.Eq{models.AccountDBNameColumn: "somename"}) func (h *SQLHelper) GetWhere(obj Mapped, pred interface{}, args ...interface{}) error { query := SQ. Select(obj.Columns(true)...). @@ -63,6 +64,17 @@ return h.Get(obj, query) } +// DeleteWhere deletes from a table corresponding to a mapped structure using the predicate and args +// ex: DeleteWhere(account, squirrel.Eq{models.AccountDBNameColumn: "somename"}) +func (h *SQLHelper) DeleteWhere(obj Mapped, pred interface{}, args ...interface{}) error { + query := SQ. + Delete(obj.Table()). + Where(pred, args...) + + _, err := h.Exec(query) + return err +} + // GetWhereForUpdate loads a mapped structure and get a lock // (see https://www.postgresql.org/docs/current/sql-select.html#SQL-FOR-UPDATE-SHARE) func (h *SQLHelper) GetWhereForUpdate(obj Mapped, pred interface{}, args ...interface{}) error {