Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
inquirer.prompt( questions, function( answers ) {
var statement = {filters:[aerospike.filter.range('tweetcount', answers.min, answers.max)]};
statement.select = ['username', 'tweetcount'];
var query = client.query('test', 'users', statement);
var stream = query.execute();
stream.on('data', function(record) {
console.log(record.bins.username + ' === ' + record.bins.tweetcount);
});
stream.on('error', function(err) {
console.log('ERROR: Query Users By Tweet Count Range failed:\n',err);
});
stream.on('end', function() {
// console.log('INFO: Query Users By Tweet Count Range completed!');
});
});
client.get(user_key, function(err, userrecord, meta) {
// Check for errors
if ( err == null ) {
// Create Query and Set equality Filter on username
// Exercise Q3
var statement = {filters:[aerospike.filter.equal('username', answer.username)]};
var query = client.query('test', 'tweets', statement);
// Execute the query
// Exercise Q3
var stream = query.foreach(null); //Query Policy = null
stream.on('data', function(record) {
// Handle 'data' event. Print Tweets for given Username
// Exercise Q3
console.log(record.tweet);
});
stream.on('error', function(err) {
// Handle 'error' event.
// Exercise Q3
console.log('ERROR: Query Tweets By Username failed: ',err);
callback();
});
stream.on('end', function() {
client.get(user_key, function(err, userrecord, meta) {
// Check for errors
if ( err.code === 0 ) {
var statement = {filters:[aerospike.filter.equal('username', answer.username)]};
var query = client.query('test', 'tweets', statement);
var stream = query.execute();
stream.on('data', function(record) {
console.log(record.bins.tweet);
});
stream.on('error', function(err) {
console.log('ERROR: Query Tweets By Username failed: ',err);
});
stream.on('end', function() {
// console.log('INFO: Query Tweets By Username completed!');
queryUsersByTweetCount(client);
});
}
else {
console.log("ERROR: User record not found!");
client.udfRegister('udfs/aggregationByRegion.lua', function(err) {
if ( err.code === 0 ) {
var statement = {filters:[aerospike.filter.range('tweetcount', answers.min, answers.max)], aggregationUDF: {module: 'aggregationByRegion', funcname: 'sum'}};
var query = client.query('test', 'users', statement);
var stream = query.execute();
stream.on('data', function(result) {
console.log('Total Users In East: ', result.e);
console.log('Total Users In West: ', result.w);
console.log('Total Users In North: ', result.n);
console.log('Total Users In South: ', result.s);
});
stream.on('error', function(err) {
console.log('ERROR: Aggregation Based on Tweet Count By Region failed: ',err);
});
stream.on('end', function() {
// console.log('INFO: Aggregation Based on Tweet Count By Region completed!');
});
} else {
// An error occurred
inquirer.prompt( questions, function( answers ) {
var statement = {filters:[aerospike.filter.range('tweetcount', answers.min, answers.max)]};
statement.select = ['username', 'tweetcount'];
var query = client.query('test', 'users', statement);
var stream = query.execute();
stream.on('data', function(record) {
console.log(record.bins.username + ' === ' + record.bins.tweetcount);
});
stream.on('error', function(err) {
console.log('ERROR: Query Users By Tweet Count Range failed:\n',err);
});
stream.on('end', function() {
// console.log('INFO: Query Users By Tweet Count Range completed!');
});
});
client.udfRegister('udf/aggregationByRegion.lua', function(err1) {
if ( err1 == null ) {
// Prepare query statement - Set range Filter on tweetcount
// Exercise A2
var statement = {filters:[aerospike.filter.range('tweetcount', parseInt(answers.min), parseInt(answers.max))]};
// Create query
// Exercise A2
var query = client.query('test', 'users', statement);
//Or you can also use the construct below using 'where' to create the query object:
//var query = client.query('test', 'users');
//query.where(aerospike.filter.range('tweetcount', parseInt(answers.min), parseInt(answers.max)));
// Execute the query, invoking stream Aggregation UDF on the results of the query
// UDF returns aggregated result
// Exercise A2
query.apply('aggregationByRegion', 'sum', function(err2, result) {
if (err2 == null) {
// Display desired result: "Total Users In : <#>"
// Exercise A2
inquirer.prompt( questions, function( answers ) {
// Prepare query statement - Set range Filter on tweetcount
// Exercise Q4
var statement = {filters:[aerospike.filter.range('tweetcount', parseInt(answers.min), parseInt(answers.max))]};
// Select bins of interest to retrieve from the query
// Exercise Q4
statement.select = ['username', 'tweetcount'];
// Create query
// Exercise Q4
var query = client.query('test', 'users', statement);
// Execute the query
// Exercise Q4
var stream = query.foreach(null); //Query Policy = null
// Handle 'data' event returned by the query
// Exercise Q4
stream.on('data', function(record) {
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
// *****************************************************************************
// Write a record
// *****************************************************************************
const Aerospike = require('aerospike')
const fs = require('fs')
const yargs = require('yargs')
const status = Aerospike.status
const filter = Aerospike.filter
const GeoJSON = Aerospike.GeoJSON
const Key = Aerospike.Key
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage('$0 [options] key')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
host: {
alias: 'h',
function queryWorkerJob (worker, id) {
var stmt = {}
var queryConfig = argv.querySpec[id]
if (queryConfig.qtype === 'Range') {
stmt.filters = [aerospike.filter.range(queryConfig.bin, queryConfig.min, queryConfig.max)]
} else if (queryConfig.qtype === 'Equal') {
stmt.filters = [aerospike.filter.equal(queryConfig.bin, queryConfig.value)]
}
var options = {
namespace: argv.namespace,
set: argv.set,
statement: stmt
}
worker.send(['query', options])
}