mirror of
https://github.com/documize/community.git
synced 2025-08-04 21:15:24 +02:00
[WIP] Backup process outline
This commit is contained in:
parent
8bbb0d3e82
commit
4094677792
18 changed files with 678 additions and 220 deletions
|
@ -43,61 +43,57 @@ func (c *Context) Bind(sql string) string {
|
|||
|
||||
// Delete record.
|
||||
func (c *Context) Delete(tx *sqlx.Tx, table string, id string) (rows int64, err error) {
|
||||
result, err := tx.Exec(c.Bind("DELETE FROM "+table+" WHERE c_refid=?"), id)
|
||||
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
_, err = tx.Exec(c.Bind("DELETE FROM "+table+" WHERE c_refid=?"), id)
|
||||
if err == sql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, fmt.Sprintf("unable to delete row in table %s", table))
|
||||
return
|
||||
}
|
||||
|
||||
rows, err = result.RowsAffected()
|
||||
err = nil
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteConstrained record constrained to Organization using refid.
|
||||
func (c *Context) DeleteConstrained(tx *sqlx.Tx, table string, orgID, id string) (rows int64, err error) {
|
||||
result, err := tx.Exec(c.Bind("DELETE FROM "+table+" WHERE c_orgid=? AND c_refid=?"), orgID, id)
|
||||
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
_, err = tx.Exec(c.Bind("DELETE FROM "+table+" WHERE c_orgid=? AND c_refid=?"), orgID, id)
|
||||
if err == sql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, fmt.Sprintf("unable to delete row in table %s", table))
|
||||
return
|
||||
}
|
||||
|
||||
rows, err = result.RowsAffected()
|
||||
err = nil
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteConstrainedWithID record constrained to Organization using non refid.
|
||||
func (c *Context) DeleteConstrainedWithID(tx *sqlx.Tx, table string, orgID, id string) (rows int64, err error) {
|
||||
result, err := tx.Exec(c.Bind("DELETE FROM "+table+" WHERE c_orgid=? AND id=?"), orgID, id)
|
||||
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
err = errors.Wrap(err, fmt.Sprintf("unable to delete row in table %s", table))
|
||||
_, err = tx.Exec(c.Bind("DELETE FROM "+table+" WHERE c_orgid=? AND id=?"), orgID, id)
|
||||
if err == sql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, fmt.Sprintf("unable to delete rows by id: %s", id))
|
||||
return
|
||||
}
|
||||
|
||||
rows, err = result.RowsAffected()
|
||||
err = nil
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteWhere free form query.
|
||||
func (c *Context) DeleteWhere(tx *sqlx.Tx, statement string) (rows int64, err error) {
|
||||
result, err := tx.Exec(statement)
|
||||
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
_, err = tx.Exec(statement)
|
||||
if err == sql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, fmt.Sprintf("unable to delete rows: %s", statement))
|
||||
return
|
||||
}
|
||||
|
||||
rows, err = result.RowsAffected()
|
||||
err = nil
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue