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

Function DiffFromRow

core/rootobject/objinterface/root_object.go:146–208  ·  view source on GitHub ↗

DiffFromRow converts a row to a conflict diff.

(ctx *sql.Context, conflict doltdb.ConflictRootObject, row sql.Row)

Source from the content-addressed store, hash-verified

144
145// DiffFromRow converts a row to a conflict diff.
146func DiffFromRow(ctx *sql.Context, conflict doltdb.ConflictRootObject, row sql.Row) (_ doltdb.RootObjectDiff, err error) {
147 if len(row) != len(RootObjectDiffSchema) {
148 return nil, errors.Newf("expected root object row diff to have %d columns but had %d", len(RootObjectDiffSchema), len(row))
149 }
150 fieldName := row[6].(string)
151 typ := conflict.(Conflict).FieldType(ctx, fieldName)
152 if typ == nil {
153 return nil, errors.Newf("cannot find a field named `%s`", fieldName)
154 }
155 var baseValue any
156 var ourValue any
157 var theirValue any
158 var ourChange RootObjectDiffChange
159 var theirChange RootObjectDiffChange
160 if row[1] != nil {
161 baseValue, err = typ.IoInput(ctx, row[1].(string))
162 if err != nil {
163 return nil, err
164 }
165 }
166 if row[2] != nil {
167 ourValue, err = typ.IoInput(ctx, row[2].(string))
168 if err != nil {
169 return nil, err
170 }
171 }
172 if row[4] != nil {
173 theirValue, err = typ.IoInput(ctx, row[4].(string))
174 if err != nil {
175 return nil, err
176 }
177 }
178 switch row[3].(string) {
179 case "added":
180 ourChange = RootObjectDiffChange_Added
181 case "deleted":
182 ourChange = RootObjectDiffChange_Deleted
183 case "modified":
184 ourChange = RootObjectDiffChange_Modified
185 case "no_change":
186 ourChange = RootObjectDiffChange_NoChange
187 }
188 switch row[5].(string) {
189 case "added":
190 theirChange = RootObjectDiffChange_Added
191 case "deleted":
192 theirChange = RootObjectDiffChange_Deleted
193 case "modified":
194 theirChange = RootObjectDiffChange_Modified
195 case "no_change":
196 ourChange = RootObjectDiffChange_NoChange
197 }
198 return RootObjectDiff{
199 Type: typ,
200 FromHash: row[0].(string),
201 FieldName: fieldName,
202 AncestorValue: baseValue,
203 OurValue: ourValue,

Callers

nothing calls this directly

Calls 2

IoInputMethod · 0.80
FieldTypeMethod · 0.65

Tested by

no test coverage detected