MCPcopy Index your code
hub / github.com/coder/coder / NullableBoolean

Method NullableBoolean

coderd/httpapi/queryparams.go:147–163  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

145// SQLc still uses sql.NullBool rather than the generic type. So converting from
146// the generic type is required.
147func (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
165func (p *QueryParamParser) Boolean(vals url.Values, def bool, queryParam string) bool {
166 v, err := parseQueryParam(p, vals, strconv.ParseBool, def, queryParam)

Callers 5

provisionerDaemonsMethod · 0.95
UsersFunction · 0.95
WorkspacesFunction · 0.95
TemplatesFunction · 0.95
ChatsFunction · 0.95

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected