Esempio n. 1
0
File: delete.go Progetto: rjp/crud
func Delete(exec ExecFn, record interface{}) (stdsql.Result, error) {
	table, err := NewTable(record)
	if err != nil {
		return nil, err
	}

	pk := table.PrimaryKeyField()
	if pk == nil {
		return nil, errors.New(fmt.Sprintf("Table '%s' (%s) doesn't have a primary-key field", table.Name, table.SQLName))
	}

	return exec(sql.DeleteQuery(table.SQLName, pk.SQL.Name), pk.Value)
}
Esempio n. 2
0
func TestDeleteQuery(t *testing.T) {
	assert.Equal(t, sql.DeleteQuery("yolo", "id"), "DELETE FROM yolo WHERE id=?")
}