I use JSV in my validation functions, though I had to modify JSV a bit to get it to cooperate. you also can't throw arrays from the validate doc update function so you have to work around that, see here: https://issues.apache.org/jira/browse/COUCHDB-1635
I can't comment on performance since I'm not doing anything crazy, but it works. I'll try to put an example of what I'm doing on github after work and reply here. On Tue, Feb 5, 2013 at 4:20 AM, Dave Cottlehuber <[email protected]> wrote: > On 5 February 2013 09:52, Ian Mayo <[email protected]> wrote: > > I'm familiar with the use of a validate function in CouchDb, and have a > > js-crafted one doing a good job right now. > > > > But, I'm interested in moving to a higher-level validation, through use > of > > a json-schema: > > http://json-schema.org/ > > > > I've only just become aware of the JSV validator, written in Javascript: > > https://github.com/garycourt/JSV > > > > Has anybody managed to use JSV in a CouchDb validate function? Are there > > any examples online? > > > > Personally, I think there would be great merit in providing 'native' json > > schema validation within CouchDb - it really seems a "grown-up" way of > > maintaining the quality of a document database (accepting that there are > > still many use cases that rely on a completely schema free design). > > > > Cheers, > > Ian > > Hi Ian, > > TL;DR this should not be difficult to do within a validation function, > *but* you might find performance takes a hit. > > I have some old links on this but don't recall anybody posting > anything concrete, and I found a way not to need it. > > > http://mail-archives.apache.org/mod_mbox/couchdb-user/201104.mbox/%[email protected]%3E > > This person had a crack but never revealed any secret sauce: > > http://daemon.co.za/2012/05/dynamic-forms-json-schema/ > http://daemon.co.za/2012/05/replacing-couchdb-views-with-elasticsearch/ > > Simon might have more details to share: > https://cloudant.com/blog/schemas-in-couchdb/ > > From a performance perspective you are likely to find this painful. > > https://github.com/k3nn7/json-validator > > Would likely work as an erlang validation function, with some work > required. But at least its mochiweb based already. > > A+ > Dave >
