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

Method WithResolvedChildren

server/node/create_domain.go:157–209  ·  view source on GitHub ↗

WithResolvedChildren implements the interface vitess.Injectable.

(ctx context.Context, children []any)

Source from the content-addressed store, hash-verified

155
156// WithResolvedChildren implements the interface vitess.Injectable.
157func (c *CreateDomain) WithResolvedChildren(ctx context.Context, children []any) (any, error) {
158 checksStartAt := 0
159 var defExpr sql.Expression
160 if c.HasDefault {
161 expr, ok := children[0].(sql.Expression)
162 if !ok {
163 return nil, errors.Errorf("invalid vitess child, expected sql.Expression for Default value but got %t", children[0])
164 }
165 defExpr = expr
166 checksStartAt = 1
167 }
168 var checks sql.CheckConstraints
169 for i, child := range children[checksStartAt:] {
170 expr, ok := child.(sql.Expression)
171 if !ok {
172 return nil, errors.Errorf("invalid vitess child, expected sql.Expression for Check constraint value but got %t", children[0])
173 }
174 checks = append(checks, &sql.CheckConstraint{
175 Name: c.CheckConstraintNames[i],
176 Expr: expr,
177 Enforced: true,
178 })
179 }
180 if !c.AsType.IsResolvedType() {
181 sqlCtx, ok := ctx.(*sql.Context)
182 if !ok {
183 return nil, errors.Errorf("%T requires a SQL context for type resolution", c)
184 }
185 typeColl, err := core.GetTypesCollectionFromContext(sqlCtx, "")
186 if err != nil {
187 return nil, err
188 }
189 resolvedType, err := typeColl.ResolveType(sqlCtx, c.AsType.ID)
190 if err != nil {
191 return nil, err
192 }
193 c.AsType = resolvedType
194 }
195 if !c.AsType.IsDefined {
196 return nil, pgtypes.ErrTypeIsOnlyAShell.New(c.AsType.Name())
197 }
198 return &CreateDomain{
199 SchemaName: c.SchemaName,
200 Name: c.Name,
201 AsType: c.AsType,
202 Collation: c.Collation,
203 HasDefault: c.HasDefault,
204 DefaultExpr: defExpr,
205 IsNotNull: c.IsNotNull,
206 CheckConstraintNames: c.CheckConstraintNames,
207 CheckConstraints: checks,
208 }, nil
209}
210
211// DomainColumn represents the column name `VALUE.
212// It is a placeholder column reference later

Callers

nothing calls this directly

Calls 5

IsResolvedTypeMethod · 0.80
ErrorfMethod · 0.65
ResolveTypeMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected