Ejemplo n.º 1
0
func SelectWhere(db *sql.DB, val PtrRecord, conds WhereMap) (interface{}, *Result) {
	var whereSql, args = sqlutils.BuildWhereClauseWithAndOp(conds, GetHolderTypeByDriver(driverType))
	var sql = sqlutils.BuildSelectClause(val) + whereSql
	var rows, err = db.Query(sql, args...)
	if err != nil {
		return nil, NewErrorResult(err, sql)
	}
	defer rows.Close()

	slice, err := CreateStructSliceFromRows(val, rows)
	if err != nil {
		return slice, NewErrorResult(err, sql)
	}
	return slice, NewResult(sql)
}
Ejemplo n.º 2
0
/*
Load record from a where condition map
*/
func LoadByCols(db *sql.DB, val PtrRecord, cols WhereMap) *Result {
	var sqlstring = sqlutils.BuildSelectClause(val)
	whereSql, args := sqlutils.BuildWhereClauseWithAndOp(cols, GetHolderTypeByDriver(driverType))
	sqlstring += whereSql + sqlutils.BuildLimitClause(1)
	return LoadFromQueryRow(db, val, sqlstring, args...)
}