UNPKG

aerospike

Version:
60 lines (45 loc) 1.99 kB
#!/usr/bin/env node // ***************************************************************************** // Copyright 2025 Aerospike, Inc. // // Licensed under the Apache License, Version 2.0 (the "License") // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // 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. // ***************************************************************************** // const Aerospike = require('aerospike') const shared = require('./shared') const Context = Aerospike.cdt.Context shared.runner() async function pathExpressions (client, argv) { const key = new Aerospike.Key(argv.namespace, argv.set, argv.key) const bins = { floatList: [2.4, 4.8, 7.2] } if (!argv.multiplier) { argv.multiplier = 0.5 } await client.put(key, bins) const addAllChildren = new Context().addAllChildren() const modExpression = Aerospike.exp.mul(Aerospike.exp.loopVarFloat(Aerospike.exp.loopVarPart.VALUE), Aerospike.exp.float(argv.multiplier)) const modifyByPath = Aerospike.exp.modifyByPath(Aerospike.exp.binList('floatList'), Aerospike.exp.type.LIST, modExpression, Aerospike.exp.pathModifyFlags.DEFAULT, addAllChildren) const ops = [ Aerospike.exp.operations.write('floatList', modifyByPath, Aerospike.exp.expWriteFlags.DEFAULT) ] await client.operate(key, ops) const result = await client.get(key) console.log(result.bins) // { floatList: [ 8.88, 17.76, 26.64 ] } await client.close() } exports.command = 'pathExpressions <key> <multiplier>' exports.describe = 'Path Expressions' exports.handler = shared.run(pathExpressions) exports.builder = {}