async function insertDocumentsIntoDocdb()

in src/commands/importDocuments.ts [115:143]


async function insertDocumentsIntoDocdb(collectionNode: DocDBCollectionTreeItem, documents: any[], uris: vscode.Uri[]): Promise<string> {
    const ids: string[] = [];
    let i = 0;
    const erroneousFiles: vscode.Uri[] = [];
    for (i = 0; i < documents.length; i++) {
        // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
        const document: ItemDefinition = documents[i];
        if (!collectionNode.documentsTreeItem.documentHasPartitionKey(document)) {
            erroneousFiles.push(uris[i]);
        }
    }
    if (erroneousFiles.length) {
        ext.outputChannel.appendLog(`The following documents do not contain the required partition key:`);
        erroneousFiles.forEach(file => ext.outputChannel.appendLine(file.path));
        ext.outputChannel.show();
        throw new Error(`See output for list of documents that do not contain the partition key '${nonNullProp(collectionNode, 'partitionKey').paths[0]}' required by collection '${collectionNode.label}'`);
    }
    for (const document of documents) {
        const retrieved: ItemDefinition = await collectionNode.documentsTreeItem.createDocument(document);
        if (retrieved.id) {
            ids.push(retrieved.id);
        }
    }
    const result: string = `Import into SQL successful. Inserted ${ids.length} document(s). See output for more details.`;
    for (const id of ids) {
        ext.outputChannel.appendLine(`Inserted document: ${id}`);
    }
    return result;
}