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

Method AddFunction

core/functions/collection.go:109–135  ·  view source on GitHub ↗

AddFunction adds a new function.

(ctx context.Context, f Function)

Source from the content-addressed store, hash-verified

107
108// AddFunction adds a new function.
109func (pgf *Collection) AddFunction(ctx context.Context, f Function) error {
110 // First we'll check to see if it exists
111 if _, ok := pgf.accessCache[f.ID]; ok {
112 return errors.Errorf(`function "%s" already exists with same argument types`, f.ID.FunctionName())
113 }
114
115 // Now we'll add the function to our map
116 data, err := f.Serialize(ctx)
117 if err != nil {
118 return err
119 }
120 h, err := pgf.ns.WriteBytes(ctx, data)
121 if err != nil {
122 return err
123 }
124 mapEditor := pgf.underlyingMap.Editor()
125 if err = mapEditor.Add(ctx, string(f.ID), h); err != nil {
126 return err
127 }
128 newMap, err := mapEditor.Flush(ctx)
129 if err != nil {
130 return err
131 }
132 pgf.underlyingMap = newMap
133 pgf.mapHash = pgf.underlyingMap.HashOf()
134 return pgf.reloadCaches(ctx)
135}
136
137// DropFunction drops an existing function.
138func (pgf *Collection) DropFunction(ctx context.Context, funcIDs ...id.Function) error {

Callers 3

PutRootObjectMethod · 0.95
RenameRootObjectMethod · 0.95
RowIterMethod · 0.80

Calls 8

reloadCachesMethod · 0.95
WriteBytesMethod · 0.80
FlushMethod · 0.80
ErrorfMethod · 0.65
SerializeMethod · 0.65
FunctionNameMethod · 0.45
AddMethod · 0.45
HashOfMethod · 0.45

Tested by

no test coverage detected