24 ms·
Interesting project -- I built a very similar thing maybe 5 years ago with validation. There was a similar _fields structure, but it was a dict of field name a
by mattbillenstein 10y ago
Interesting project -- I built a very similar thing maybe 5 years ago with validation. There was a similar _fields structure, but it was a dict of field name and type which could also a be a callable to validate and coerce to the proper type, but by default, we just made sure a given field had the proper type -- we could also inject a default here as well.
This enforced a schema in the collection which I've found is usually very desirable. I used collection son manipulators and a _type field in the document to do mapping to and from the db. I think there was eventually a SubDocument type for embedded documents, but there was intentionally no dereferencing or lazy loading of embedded ids -- that's a slippery slope to building an ORM and fighting all the battles therein. The object mapping was a very nice feature though and I think that code is still in use today.
So +1 on keep it simple and -0 on not doing validation by default.