* Serializes the IndexSpec to a bson compatible response. * For GetIndexes this formats it into a user friendly version. * Otherwise (for Shard_collection etc.) it retains the original format. */
| 2592 | * Otherwise (for Shard_collection etc.) it retains the original format. |
| 2593 | */ |
| 2594 | static pgbson * |
| 2595 | SerializeIndexSpec(const IndexSpec *indexSpec, bool isGetIndexes, |
| 2596 | const char *namespaceName) |
| 2597 | { |
| 2598 | pgbson_writer finalWriter; |
| 2599 | PgbsonWriterInit(&finalWriter); |
| 2600 | PgbsonWriterAppendInt32(&finalWriter, "v", 1, indexSpec->indexVersion); |
| 2601 | |
| 2602 | List *textColumns = NIL; |
| 2603 | const char *languageOverride = "language"; |
| 2604 | if (isGetIndexes) |
| 2605 | { |
| 2606 | /* For GetIndexes, we may need to rewrite the key if there's non-regular indexes (e.g. text ) */ |
| 2607 | textColumns = WriteIndexKeyForGetIndexes(&finalWriter, |
| 2608 | indexSpec->indexKeyDocument); |
| 2609 | } |
| 2610 | else |
| 2611 | { |
| 2612 | PgbsonWriterAppendDocument(&finalWriter, "key", 3, indexSpec->indexKeyDocument); |
| 2613 | } |
| 2614 | |
| 2615 | PgbsonWriterAppendUtf8(&finalWriter, "name", 4, indexSpec->indexName); |
| 2616 | |
| 2617 | if (indexSpec->indexPFEDocument != NULL) |
| 2618 | { |
| 2619 | PgbsonWriterAppendDocument(&finalWriter, "partialFilterExpression", -1, |
| 2620 | indexSpec->indexPFEDocument); |
| 2621 | } |
| 2622 | |
| 2623 | if (indexSpec->indexWPDocument != NULL) |
| 2624 | { |
| 2625 | PgbsonWriterAppendDocument(&finalWriter, "wildcardProjection", -1, |
| 2626 | indexSpec->indexWPDocument); |
| 2627 | } |
| 2628 | |
| 2629 | if (indexSpec->indexSparse != BoolIndexOption_Undefined) |
| 2630 | { |
| 2631 | PgbsonWriterAppendBool(&finalWriter, "sparse", 6, indexSpec->indexSparse == |
| 2632 | BoolIndexOption_True); |
| 2633 | } |
| 2634 | |
| 2635 | if (indexSpec->indexUnique != BoolIndexOption_Undefined) |
| 2636 | { |
| 2637 | /* |
| 2638 | * Unique is only tracked for getIndexes if it's explicitly set to true. |
| 2639 | */ |
| 2640 | if (!isGetIndexes || indexSpec->indexUnique == BoolIndexOption_True) |
| 2641 | { |
| 2642 | PgbsonWriterAppendBool(&finalWriter, "unique", 6, indexSpec->indexUnique == |
| 2643 | BoolIndexOption_True); |
| 2644 | } |
| 2645 | } |
| 2646 | |
| 2647 | if (indexSpec->indexExpireAfterSeconds != NULL) |
| 2648 | { |
| 2649 | PgbsonWriterAppendInt32(&finalWriter, "expireAfterSeconds", -1, |
| 2650 | *indexSpec->indexExpireAfterSeconds); |
| 2651 | } |
no test coverage detected