NullableBoolean will return a null sql value if no input is provided. SQLc still uses sql.NullBool rather than the generic type. So converting from the generic type is required.
(vals url.Values, def sql.NullBool, queryParam string)
| 145 | // SQLc still uses sql.NullBool rather than the generic type. So converting from |
| 146 | // the generic type is required. |
| 147 | func (p *QueryParamParser) NullableBoolean(vals url.Values, def sql.NullBool, queryParam string) sql.NullBool { |
| 148 | v, err := parseNullableQueryParam[bool](p, vals, strconv.ParseBool, sql.Null[bool]{ |
| 149 | V: def.Bool, |
| 150 | Valid: def.Valid, |
| 151 | }, queryParam) |
| 152 | if err != nil { |
| 153 | p.Errors = append(p.Errors, codersdk.ValidationError{ |
| 154 | Field: queryParam, |
| 155 | Detail: fmt.Sprintf("Query param %q must be a valid boolean: %s", queryParam, err.Error()), |
| 156 | }) |
| 157 | } |
| 158 | |
| 159 | return sql.NullBool{ |
| 160 | Bool: v.V, |
| 161 | Valid: v.Valid, |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | func (p *QueryParamParser) Boolean(vals url.Values, def bool, queryParam string) bool { |
| 166 | v, err := parseQueryParam(p, vals, strconv.ParseBool, def, queryParam) |
no test coverage detected