AddFunction adds a new function.
(ctx context.Context, f Function)
| 107 | |
| 108 | // AddFunction adds a new function. |
| 109 | func (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. |
| 138 | func (pgf *Collection) DropFunction(ctx context.Context, funcIDs ...id.Function) error { |
no test coverage detected