@@ -744,8 +744,28 @@ const json = [{ "@type" : "Class",
744
744
" name" : " xsd:string" ,
745
745
" perimeter" : { " @type" : " List" ,
746
746
" @class" : " Coordinate" } }]
747
- client .addDocument (json,{" graph_type" : " schema" }," mydb" ," add new schema" )
747
+ client .addDocument (json,{" graph_type" : " schema" }," mydb" ," add new schema documents" )
748
+
749
+ // if we would like to override the entire schema
750
+ const json = [
751
+ {" @base" : " terminusdb:///data/" ,
752
+ " @schema" : " terminusdb:///schema#" ,
753
+ " @type" : " @context"
754
+ },
755
+ {
756
+ " @id" : " Person" ,
757
+ " @key" : {
758
+ " @type" : " Random"
759
+ },
760
+ " @type" : " Class" ,
761
+ " name" : {
762
+ " @class" : " xsd:string" ,
763
+ " @type" : " Optional"
764
+ }
765
+ }]
748
766
767
+ // client.addDocument(json,{"graph_type":"schema","full_replace:true"},
768
+ " mydb" ," update the all schema" );
749
769
750
770
// Here we will pass true to show how to get dataVersion
751
771
@@ -1184,6 +1204,81 @@ async funtion callGetUserOrganizations(){
1184
1204
}
1185
1205
` ` `
1186
1206
1207
+ ## patch
1208
+ ##### woqlClient.patch(before, patch) ⇒ <code>Promise</code>
1209
+ Apply a patch object to another object
1210
+
1211
+ **Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
1212
+
1213
+ | Param | Type | Description |
1214
+ | --- | --- | --- |
1215
+ | before | <code>object</code> | The current state of JSON document |
1216
+ | patch | <code>object</code> | The patch object |
1217
+
1218
+ **Example**
1219
+ ` ` ` javascript
1220
+ client .patch (
1221
+ { " @id" : " Person/Jane" , " @type" : " Person" , " name" : " Jane" },
1222
+ { " name" : { " @op" : " ValueSwap" , " @before" : " Jane" , " @after" : " Janine" }}
1223
+ ).then (patchResult => {
1224
+ console .log (patchResult)
1225
+ })
1226
+ // result example
1227
+ // { "@id" : "Person/Jane", "@type" : "Person", "name" : "Jannet"}
1228
+ ` ` `
1229
+
1230
+ ## patchResource
1231
+ ##### woqlClient.patchResource(patch, message) ⇒ <code>Promise</code>
1232
+ Apply a patch object to the current resource
1233
+
1234
+ **Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
1235
+
1236
+ | Param | Type | Description |
1237
+ | --- | --- | --- |
1238
+ | patch | <code>array</code> | The patch object |
1239
+ | message | <code>string</code> | The commit message |
1240
+
1241
+ **Example**
1242
+ ` ` ` javascript
1243
+ const patch = [
1244
+ {
1245
+ " @id" : " Obj/id1" ,
1246
+ " name" : {
1247
+ " @op" : " SwapValue" ,
1248
+ " @before" : " foo" ,
1249
+ " @after" : " bar"
1250
+ }
1251
+ },
1252
+ {
1253
+ " @id" : " Obj/id2" ,
1254
+ " name" : {
1255
+ " @op" : " SwapValue" ,
1256
+ " @before" : " foo" ,
1257
+ " @after" : " bar"
1258
+ }
1259
+ }
1260
+ ]
1261
+ client .db (" mydb" )
1262
+ client .checkout (" mybranch" )
1263
+ client .patchResource (patch," apply patch to mybranch" ).then (patchResult => {
1264
+ console .log (patchResult)
1265
+ })
1266
+ // result example
1267
+ // ["Obj/id1",
1268
+ // "Obj/id2"]
1269
+ // or conflict error 409
1270
+ // {
1271
+ // "@type": "api:PatchError",
1272
+ // "api:status": "api:conflict",
1273
+ // "api:witnesses": [
1274
+ // {
1275
+ // "@op": "InsertConflict",
1276
+ // "@id_already_exists": "Person/Jane"
1277
+ // }
1278
+ // ]
1279
+ // }
1280
+ ` ` `
1281
+
1187
1282
## getJSONDiff
1188
1283
##### woqlClient.getJSONDiff(before, after, [options]) ⇒ <code>Promise</code>
1189
1284
Get the patch of difference between two documents.
@@ -1293,28 +1388,6 @@ client.apply("main","mybranch","merge main").then(result=>{
1293
1388
})
1294
1389
` ` `
1295
1390
1296
- ## patch
1297
- ##### woqlClient.patch(before, patch) ⇒ <code>Promise</code>
1298
- Patch the difference between two documents.
1299
-
1300
- **Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
1301
-
1302
- | Param | Type | Description |
1303
- | --- | --- | --- |
1304
- | before | <code>object</code> | The current state of JSON document |
1305
- | patch | <code>object</code> | The patch object |
1306
-
1307
- **Example**
1308
- ` ` ` javascript
1309
- let diffPatch = await client .getJSONDiff (
1310
- { " @id" : " Person/Jane" , " @type" : " Person" , name: " Jane" },
1311
- { " @id" : " Person/Jane" , " @type" : " Person" , name: " Janine" }
1312
- );
1313
-
1314
- let patch = await client .patch ( { " @id" : " Person/Jane" , " @type" : " Person" , name: " Jane" },
1315
- diffPatch);
1316
- ` ` `
1317
-
1318
1391
## sendCustomRequest
1319
1392
##### woqlClient.sendCustomRequest(requestType, customRequestURL, [payload]) ⇒ <code>Promise</code>
1320
1393
Call a custom Api endpoit
0 commit comments