MCPcopy
hub / github.com/sqlc-dev/sqlc / mysqlDefaultValue

Function mysqlDefaultValue

internal/cmd/vet.go:268–306  ·  view source on GitHub ↗

Return a default value for a MySQL column based on its type. Returns nil if the type is unknown.

(col *plugin.Column)

Source from the content-addressed store, hash-verified

266// Return a default value for a MySQL column based on its type. Returns nil
267// if the type is unknown.
268func mysqlDefaultValue(col *plugin.Column) any {
269 if col == nil {
270 return nil
271 }
272 if col.Type == nil {
273 return nil
274 }
275 switch col.Type.Name {
276 case "any":
277 return nil
278 case "bool":
279 return false
280 case "int", "bigint", "mediumint", "smallint", "tinyint", "bit":
281 return 1
282 case "decimal": // "numeric", "dec", "fixed"
283 // No perfect choice here to avoid "Impossible WHERE" but I think
284 // 0.1 is decent. It works for all cases where `scale` > 0 which
285 // should be the majority. For more information refer to
286 // https://dev.mysql.com/doc/refman/8.1/en/fixed-point-types.html.
287 return 0.1
288 case "float", "double":
289 return 0.1
290 case "date":
291 return "0000-00-00"
292 case "datetime", "timestamp":
293 return "0000-00-00 00:00:00"
294 case "time":
295 return "00:00:00"
296 case "year":
297 return "0000"
298 case "char", "varchar", "binary", "varbinary", "tinyblob", "blob",
299 "mediumblob", "longblob", "tinytext", "text", "mediumtext", "longtext":
300 return ""
301 case "json":
302 return "{}"
303 default:
304 return nil
305 }
306}
307
308func (p *pgxConn) Explain(ctx context.Context, query string, args ...*plugin.Parameter) (*vetEngineOutput, error) {
309 eQuery := "EXPLAIN (ANALYZE false, VERBOSE, COSTS, SETTINGS, BUFFERS, FORMAT JSON) " + query

Callers 1

ExplainMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected