WithReplacements adds sqlctemplate templates to the given context (they go in context because it's the only way to get them down into the innards of sqlc). namedArgs can also be passed in to replace arguments found in If sqlctemplate params are already present in context, the two sets are merged, w
(ctx context.Context, replacements map[string]Replacement, namedArgs map[string]any)
| 256 | // If sqlctemplate params are already present in context, the two sets are |
| 257 | // merged, with the new params taking precedent. |
| 258 | func WithReplacements(ctx context.Context, replacements map[string]Replacement, namedArgs map[string]any) context.Context { |
| 259 | if container, ok := ctx.Value(contextKey{}).(*contextContainer); ok { |
| 260 | maps.Copy(container.NamedArgs, namedArgs) |
| 261 | maps.Copy(container.Replacements, replacements) |
| 262 | return ctx |
| 263 | } |
| 264 | |
| 265 | if namedArgs == nil { |
| 266 | namedArgs = make(map[string]any) |
| 267 | } |
| 268 | |
| 269 | return context.WithValue(ctx, contextKey{}, &contextContainer{ |
| 270 | NamedArgs: namedArgs, |
| 271 | Replacements: replacements, |
| 272 | }) |
| 273 | } |
| 274 | |
| 275 | // Comparable struct that's used as a key for template caching. |
| 276 | type replacerCacheKey struct { |
searching dependent graphs…