Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function runPageQuery(pageCursor) {
let query = datastore.createQuery('Task').limit(pageSize);
if (pageCursor) {
query = query.start(pageCursor);
}
const results = await datastore.runQuery(query);
const entities = results[0];
const info = results[1];
if (info.moreResults !== Datastore.NO_MORE_RESULTS) {
// If there are more results to retrieve, the end cursor is
// automatically set on `info`. To get this value directly, access
// the `endCursor` property.
const results = await runPageQuery(info.endCursor);
// Concatenate entities
results[0] = entities.concat(results[0]);
return results;
}
return [entities, info];
}
// [END datastore_cursor_paging]
const list = async (limit, token, orderBy) => {
const order = orderBy || 'views';
const q = ds
.createQuery([kind])
.limit(limit)
.order(order, {descending: true})
.start(token);
const [rows, nextQuery] = await ds.runQuery(q);
return {
templates: rows.map(fromDatastore),
hasMore: nextQuery.moreResults !== Datastore.NO_MORE_RESULTS
? nextQuery.endCursor
: false
};
};
ds.runQuery(q, (err, entities, nextQuery) => {
if (err) {
cb(err);
return;
}
const hasMore =
nextQuery.moreResults !== Datastore.NO_MORE_RESULTS
? nextQuery.endCursor
: false;
cb(null, entities.map(fromDatastore), hasMore);
});
}
ds.runQuery(q, (err, entities, nextQuery) => {
if (err) {
cb(err);
return;
}
const hasMore =
nextQuery.moreResults !== Datastore.NO_MORE_RESULTS
? nextQuery.endCursor
: false;
cb(null, entities.map(fromDatastore), hasMore);
});
}
ds.runQuery(q, (err, entities, nextQuery) => {
if (err) {
cb(err);
return;
}
const hasMore =
nextQuery.moreResults !== Datastore.NO_MORE_RESULTS
? nextQuery.endCursor
: false;
cb(null, entities.map(fromDatastore), hasMore);
});
}
ds.runQuery(q, (err, entities, nextQuery) => {
if (err) {
cb(err);
return;
}
const hasMore =
nextQuery.moreResults !== Datastore.NO_MORE_RESULTS
? nextQuery.endCursor
: false;
cb(null, entities.map(fromDatastore), hasMore);
});
}
ds.runQuery(q, (err, entities, nextQuery) => {
if (err) {
cb(err);
return;
}
const hasMore =
nextQuery.moreResults !== Datastore.NO_MORE_RESULTS
? nextQuery.endCursor
: false;
cb(null, entities.map(fromDatastore), hasMore);
});
}