Exemplo n.º 1
0
func DeleteById(DB db.IDb, table *db.Table, id int64) (bool, error) {
	logger.CallerAt(1).Debugf("DAOUtils.deleteById: %v", id)

	keyColumn := table.GetKeyColumns().Enumerator().Next().(*db.Column)

	result, err := DB.Delete(table).
		Where(keyColumn.Matches(id)).
		Execute()

	return result != 0, err
}
Exemplo n.º 2
0
func DeleteByIdAndVersion(DB db.IDb, table *db.Table, id int64, version int64) error {
	logger.CallerAt(1).Debugf("DAOUtils.removeByIdVersion: id: %v, version: %v", id, version)

	keyColumn := table.GetKeyColumns().Enumerator().Next().(*db.Column)
	versionColumn := table.GetVersionColumn()

	result, err := DB.Delete(table).
		Where(
			keyColumn.Matches(id),
			versionColumn.Matches(version),
		).
		Execute()

	if err != nil {
		return err
	}

	if result == 0 {
		return dbx.NewOptimisticLockFail("DAOUtils.removeByIdVersion: Unable to delete by id and version for the table " + table.GetName())
	}

	return nil
}