MCPcopy Create free account
hub / github.com/dolthub/doltgresql / boolAssignment

Function boolAssignment

server/cast/bool.go:49–94  ·  view source on GitHub ↗

boolAssignment registers all assignment casts. This comprises only the source types.

(builtInCasts map[id.Cast]casts.Cast)

Source from the content-addressed store, hash-verified

47
48// boolAssignment registers all assignment casts. This comprises only the source types.
49func boolAssignment(builtInCasts map[id.Cast]casts.Cast) {
50 framework.MustAddAssignmentTypeCast(builtInCasts, framework.TypeCast{
51 FromType: pgtypes.Bool,
52 ToType: pgtypes.BpChar,
53 Function: func(ctx *sql.Context, val any, _, targetType *pgtypes.DoltgresType) (any, error) {
54 str := "false"
55 if val.(bool) {
56 str = "true"
57 }
58 return handleStringCast(str, targetType)
59 },
60 })
61 framework.MustAddAssignmentTypeCast(builtInCasts, framework.TypeCast{
62 FromType: pgtypes.Bool,
63 ToType: pgtypes.Name,
64 Function: func(ctx *sql.Context, val any, _, targetType *pgtypes.DoltgresType) (any, error) {
65 str := "f"
66 if val.(bool) {
67 str = "t"
68 }
69 return handleStringCast(str, targetType)
70 },
71 })
72 framework.MustAddAssignmentTypeCast(builtInCasts, framework.TypeCast{
73 FromType: pgtypes.Bool,
74 ToType: pgtypes.Text,
75 Function: func(ctx *sql.Context, val any, _, targetType *pgtypes.DoltgresType) (any, error) {
76 if val.(bool) {
77 return "true", nil
78 } else {
79 return "false", nil
80 }
81 },
82 })
83 framework.MustAddAssignmentTypeCast(builtInCasts, framework.TypeCast{
84 FromType: pgtypes.Bool,
85 ToType: pgtypes.VarChar,
86 Function: func(ctx *sql.Context, val any, _, targetType *pgtypes.DoltgresType) (any, error) {
87 str := "false"
88 if val.(bool) {
89 str = "true"
90 }
91 return handleStringCast(str, targetType)
92 },
93 })
94}

Callers 1

initBoolFunction · 0.85

Calls 2

handleStringCastFunction · 0.85

Tested by

no test coverage detected