Closed mrbar42 closed 8 years ago
Thanks for the feedback. Unfortunately boolean is not a supported data type at the moment. The Node.js client could convert boolean values to an integer value. But when reading back the bin value it would be returned as an integer. Since the information about the actual data type would be lost, the client would not be able to automatically convert the value back to a boolean. Therefore it is recommended that you convert boolean data types to another supported data type within your app, before passing it to the aerospike client. Since your app has knowledge of the semantics of each bin, it can do the appropriate conversion back to boolean data type when reading the value from the DB.
Setting a bin value to null
already deletes the bin as this small demo shows:
var as = require('aerospike')
function check (err) {
if (err && err.code !== as.status.AEROSPIKE_OK) {
throw new Error(err.message)
}
}
var client = as.client({hosts: [{addr: '192.168.33.10', port: 3000}]}).connect(check)
var key = {ns: 'test', set: 'test', key: 'test'}
client.put(key, {i: 1, s: 'foo'}, function (err) {
check(err)
client.get(key, function (err, record) {
check(err)
console.log(record)
client.put(key, {i: 1, s: null}, function (err) {
check(err)
client.get(key, function (err, record) {
check(err)
console.log(record)
})
})
})
})
$ node test_null
{ i: 1, s: 'foo' }
{ i: 1 }
When attempting to set a bin to an undefined
value the client currently returns a parameter error. I am not convinced that silently ignoring undefined
bin values would be the right thing to do. It could lead to hard to find application errors if a record gets partially updated because some bin values are undefined. As this would be a backward incompatible changes I would like to hear some stronger arguments than just that it's inconvenient for the programmer to check for undefined values before passing them to the aerospike client.
I think that we can agree that the user should be aware to the fact that boolean is not supported. the difference is that i think that it should be learned from the docs while at the moment its returns an error. same for undefined.
the gain is that the boiler plate is reduced. I am a big fan of easing where its obvious. such as: when an empty bin is incremented - automatically create and start from 0 etc...
But I understand your point of view. Perhaps these modifications should not be part of the official base driver
Both the general docs on the supported aerospike data types as well as the specific documentation of the Node.js client's data model clearly state the supported data types. And Boolean is not among the supported data types at the moment. I can add a note to state that no automatic type conversion is being performed either.
I do not believe there is currently any documentation that states the behaviour when a bin value is set to null
or undefined
. I will add that if it doesn't exist yet.
Are you ok to close this issue?
yes.
thanks for the responses
I've added notes to the data types and put
command documentation.
At the moment, passing a Boolean as a bin value will result in this error
Boolean datatype not supported
As can be seen here src/main/util/conversions.cc Snippet:
I see no reason why Boolean should not be converted to a number. it can't be that such a complex types are support such as List and Map and the simplest of them all isn't. after all a Boolean is probably the closest thing to a number anyways.
further more, enforcing non undefined values wrongly forces the programmer to remove undefined values from its record - a non-javascript'ish pattern. the most logical thing would be to simply ignore the bin.
final suggestion for handling input record:
null
- explicitly empty the bin (e.g delete)undefined
- ignore the bin as if it wasn't thereboolean
- convert to number (MUST be mentioned in the docs - though will not bother most of the programmers)Leading agenda - the most important thing is to bootstrap the db for most of the cases out of the box. the advances programmer will find advanced ways to achieve his advances goals.