JSON Patch data.
Arguments | Description | ||
---|---|---|---|
thing required | The table name or the specific | ||
data optional | The JSON Patch data with which to patch the records. |
type PatchData struct { Op string `json:"op"` // Operation type: "add", "remove", "replace", etc. Path string `json:"path"` // Path to the field to modify Value interface{} `json:"value"` // New value for the field (only for "add" or "replace") } // Define the patch operations patches := []PatchData{ {Op: "replace", Path: "/name", Value: "John Smith"}, {Op: "add", Path: "/tags", Value: []string{"developer", "engineer"}}, {Op: "remove", Path: "/oldField"}, } // Specify the target record recordID := models.NewRecordID("person", "tobie") // Perform the patch operation updatedPatches, err := surrealdb.Patch(db, recordID, patches) if err != nil { panic(err) } fmt.Printf("Patched person record with patches: %+v\n", updatedPatches)