Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
storageClient.deleteEntity(tableName, customer, function entitiesQueried(error, result) {
if (error) return callback(error);
console.log(" deleteEntity succeeded.");
// Demonstrates upsert and batch table operations
console.log("5. Inserting a batch of entities. ");
// create batch operation
var batch = new storage.TableBatch();
var lastName = "Smith";
// The following code generates test data for use during the query samples.
for (var i = 0; i < 100; i++) {
var name = zeroPaddingString(i, 4);
var customerToInsert = createCustomerEntityDescriptor(lastName, name, name + "@contoso.com", "425-555-" + name)
batch.insertEntity(customerToInsert);
}
// Demonstrate inserting of a large batch of entities. Some considerations for batch operations:
// 1. You can perform updates, deletes, and inserts in the same single batch operation.
// 2. A single batch operation can include up to 100 entities.
// 3. All entities in a single batch operation must have the same partition key.
// 4. While it is possible to perform a query as a batch operation, it must be the only operation in the batch.
// 5. Batch size must be <= 4MB
tableService.createTableIfNotExists('Repositories', error => {
if (error) {
console.error(error)
return
}
// creates a batch of operation to be executed
var batch = new storage.TableBatch()
for (var i = 0; i < input.length; i++) {
var repository = input[i]
// Creates an operation to add the repository to Table Storage
batch.insertOrReplaceEntity({
PartitionKey: { _: 'Default' },
RowKey: { _: repository.id.toString() },
OpenedIssues: { _: repository.openedIssues },
RepositoryName: { _: repository.name }
})
}
// execute the batch of operations
tableService.executeBatch('Repositories', batch, error => {
if (error) {
console.error(error)
}
function GetAzureTblBatchAction(offset, partitionKey, tasks, action){
const batch = new azureStorage.TableBatch();
if(Array.isArray(tasks) && offset < tasks.length){
const upperBounds = offset + AZURE_TABLE_BATCH_MAX_OPERATIONS < tasks.length ? offset + AZURE_TABLE_BATCH_MAX_OPERATIONS : tasks.length;
const batchTasks = tasks.slice(offset, upperBounds);
batchTasks.forEach(operation => {
const task = Object.assign({}, operation);
if(action === AZURE_TABLE_BATCH_ACTIONS.DELETE){
batch.deleteEntity(task);
}else if(action === AZURE_TABLE_BATCH_ACTIONS.INSERT_OR_MODIFY){
batch.insertOrReplaceEntity(task);
}else{
console.error(`${action} is an unsupported azure table action`);
}
});
}
.then(([githubIssues, knownIssues]) => {
console.log(`Synchronising ${githubIssues.length} github issues with ${knownIssues.length} known issues`)
var existing = _.indexBy(knownIssues, 'issueNumber')
var toAdd = _.filter(githubIssues, r => !existing[r.number])
var toUpdate = _.filter(githubIssues, r => existing[r.number])
var batches = []
var batch = new azure.TableBatch()
batches.push(batch)
var addPromise = enrichWithComments(githubToken, toAdd, repoName)
.then(toAddWithComments => {
_.forEach(toAddWithComments, i => {
if (batch.size() === 100) {
batch = new azure.TableBatch()
batches.push(batch)
}
batch.insertEntity(toTableIssue(i, userId, repoId))
})
})
var updatePromise = enrichWithComments(githubToken, toUpdate, repoName)
.then(toUpdateWithComments => {
_.forEach(toUpdateWithComments, i => {
if (batch.size() === 100) {
.then(([ githubRepos, savedRepos ]) => {
githubRepos = _.filter(githubRepos, r => r.permissions.admin)
console.log('Syncing repos')
var existing = _.indexBy(savedRepos, 'repoName')
console.log('From github', githubRepos.map(r => r.full_name))
console.log('Existing', Object.keys(existing))
var toAdd = _.filter(githubRepos, r => {
var exists = !existing[r.full_name]
return exists
})
if (toAdd.length === 0) {
return getAllRepositories(userId)
}
console.log(`Adding ${toAdd.length} new repositories`)
var batches = []
var batch = new azure.TableBatch()
batches.push(batch)
try {
_.forEach(toAdd, r => {
var entity = {
PartitionKey: entGen.String(userId.toString()),
RowKey: entGen.String(r.id.toString()),
RepoName: entGen.String(r.full_name),
Selected: entGen.Boolean(false)
}
if (batch.size() === 100) {
batch = new azure.TableBatch()
batches.push(batch)
}
batch.insertEntity(entity)
})
_.forEach(toUpdateWithComments, i => {
if (batch.size() === 100) {
batch = new azure.TableBatch()
batches.push(batch)
}
batch.mergeEntity(toTableIssue(i, userId, repoId))
})
})
function createBatches() {
var batches = [];
var entGen = azure.TableUtilities.entityGenerator
for (var batchIndex = 0; batchIndex < 20; batchIndex++) {
var batch = new azure.TableBatch()
var partitionKey = new Date().getTime().toString()
var rowKeySeed = new Date().getTime()
for (var index = 0; index < 99; index++) {
rowKeySeed++
var check = createPupilCheck(partitionKey, rowKeySeed.toString())
batch.insertEntity(check)
}
batches.push(batch)
}
return batches;
}
_.forEach(toAddWithComments, i => {
if (batch.size() === 100) {
batch = new azure.TableBatch()
batches.push(batch)
}
batch.insertEntity(toTableIssue(i, userId, repoId))
})
})
export function deleteIssuesList(userId, repoId) {
var batches = []
var batch = new azure.TableBatch()
batches.push(batch)
return getAllIssues(userId, repoId)
.then(issues => {
if (issues.length === 0)
return
_.forEach(issues, i => {
if (batch.size() === 100) {
batch = new azure.TableBatch()
batches.push(batch)
}
batch.deleteEntity({
PartitionKey: entGen.String(userId.toString()),
RowKey: entGen.String(getIssueRowKey(repoId, i.issueNumber))
})
})
return executeBatches('issuesList', batches)
async function process (context, v2Message) {
validate(context, v2Message)
const batch = new azure.TableBatch()
let processCount = 0
for (const preparedCheck of v2Message.messages) {
context.log.verbose(`prepare-check: v2 process(): checkCode: ${preparedCheck.checkCode}`)
batch.insertEntity(prepareEntity(preparedCheck))
processCount += 1
}
const batchResult = await azureTableService.executeBatchAsync(preparedCheckTable, batch)
if (batchResult.response.isSuccessful !== true) {
context.error('prepare-check: v2 process(): there were one or more errors in the batch', batchResult.result)
for (const result of batchResult.result) {
if (result.error) {
context.log.error(`prepare-check: v2 process(): error in checkCode ${result.entity.checkCode}: ${result.error}`)
}