MCPcopy Create free account
hub / github.com/documentdb/documentdb / BuildResponseMessage

Function BuildResponseMessage

pg_documentdb/src/commands/insert.c:1445–1475  ·  view source on GitHub ↗

* BuildResponseMessage builds the response BSON for an insert command. */

Source from the content-addressed store, hash-verified

1443 * BuildResponseMessage builds the response BSON for an insert command.
1444 */
1445static pgbson *
1446BuildResponseMessage(BatchInsertionResult *batchResult)
1447{
1448 pgbson_writer resultWriter;
1449 PgbsonWriterInit(&resultWriter);
1450 PgbsonWriterAppendInt32(&resultWriter, "n", 1, batchResult->rowsInserted);
1451 PgbsonWriterAppendDouble(&resultWriter, "ok", 2, batchResult->ok);
1452
1453 if (batchResult->writeErrors != NIL)
1454 {
1455 pgbson_array_writer writeErrorsArrayWriter;
1456 PgbsonWriterStartArray(&resultWriter, "writeErrors", 11, &writeErrorsArrayWriter);
1457
1458 ListCell *writeErrorCell = NULL;
1459 foreach(writeErrorCell, batchResult->writeErrors)
1460 {
1461 WriteError *writeError = lfirst(writeErrorCell);
1462
1463 pgbson_writer writeErrorWriter;
1464 PgbsonArrayWriterStartDocument(&writeErrorsArrayWriter, &writeErrorWriter);
1465 PgbsonWriterAppendInt32(&writeErrorWriter, "index", 5, writeError->index);
1466 PgbsonWriterAppendInt32(&writeErrorWriter, "code", 4, writeError->code);
1467 PgbsonWriterAppendUtf8(&writeErrorWriter, "errmsg", 6, writeError->errmsg);
1468 PgbsonArrayWriterEndDocument(&writeErrorsArrayWriter, &writeErrorWriter);
1469 }
1470
1471 PgbsonWriterEndArray(&resultWriter, &writeErrorsArrayWriter);
1472 }
1473
1474 return PgbsonWriterGetPgbson(&resultWriter);
1475}
1476
1477
1478/*

Callers 1

CommandInsertCoreFunction · 0.70

Calls 10

PgbsonWriterInitFunction · 0.85
PgbsonWriterAppendInt32Function · 0.85
PgbsonWriterAppendDoubleFunction · 0.85
PgbsonWriterStartArrayFunction · 0.85
PgbsonWriterAppendUtf8Function · 0.85
PgbsonWriterEndArrayFunction · 0.85
PgbsonWriterGetPgbsonFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected