Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validation at CT and (de)serialization of Bson against a Nim type #60

Open
timotheecour opened this issue Nov 16, 2018 · 2 comments
Open

Comments

@timotheecour
Copy link
Contributor

validation at CT

to make programs more type safe and prevent errors due to field name or type, the following would be very useful:

type Doc = object
  kind: string
  nimid: int
  # badfield  not present
  badtype: int
  ommittedfield: string  # not all fields need to be present for validate to succeed

let doc = %*{
  "kind": "foo",
  "nimid": 32,
  "badfield": 123,
  "badtype": 12.3, # float instead of int
}

doc.validate(Doc) # CT failure because of badfield and badtype

serialization/deserialization

similar to above but I don't think it can be reduced to a common use case in Bson which is to specify only a subset of fields

var doc: Bson = ... # see above
var doc2: Doc = doc.to(Doc)
var doc3: Bson = doc2.to(Bson)
doAssert doc3 == doc

Note: this is implemented in D in vibe.d

@yglukhov
Copy link
Contributor

Is it in scope of a mongodb driver though, which nimongo is? Could be well implemented separately.

@timotheecour
Copy link
Contributor Author

yes, it could be a separate nimble package (that would depend on nimongo/bson); but can we keep it open as placeholder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants