mongodb command line client supports specifying fields without quotes:
{foo: "bar"} can be used instead of: {"foo": "bar"}
I'm wondering whether this idea could be used in nimongo/bson to simplify BSON construction, using an appropriate macro that would understand untyped params
simplified example
import macros
macro foo(bar: untyped): untyped=
let temp = repr(bar)
result = quote do:
var ret = ""
ret.addQuoted `temp`
ret
echo foo(hello_world) # prints: "hello_world"
echo foo(helloWorld) # prints: "helloWorld"
note
obviously, this would only be used for fields that are valid symbols
let doc = toBsonMagicFields{
foo1: "bar1",
"foo2-special", "bar2", # here, we can't use foo2-special, "bar2"
}
note
note that toBsonMagicFields would ignore variables in scope for the "key" positions of each field definition, eg:
let foo1 = "bar"
let doc = toBsonMagicFields{
foo1: foo1,
}
# transforms to:
let foo1 = "bar"
let doc = toBson{
"foo1": foo1,
}
mongodb command line client supports specifying fields without quotes:
I'm wondering whether this idea could be used in nimongo/bson to simplify BSON construction, using an appropriate macro that would understand untyped params
simplified example
note
obviously, this would only be used for fields that are valid symbols
note
note that
toBsonMagicFields
would ignore variables in scope for the "key" positions of each field definition, eg: