exist
exist copied to clipboard
[feature] add `mkdir -p` like function to xmldb XQuery module
I've seen one-off implementations - and built one of my own - to solve a common problem:
Create an collection where missing parent collections will be created.
On the linux command line this is possible by setting the -p flag on mkdir.
mkdir -p `/this/is/a/deeply/nested/directory`
nodeJS for example mimics this behaviour by setting the recursive option on the builtin fs.mkdir method.
There is no such facility present in eXistdb to my knowledge. That is why I propose to add that by either
- a new function
xmldb:create-collection-recursiveaccepting one parameter:
- collectionUri as xs:string
- or add a signature to
xmldb:create-collectionaccepting two parameters:
- collectionUri as xs:string
- options as xs:map
- create a new builtin XQuery module that will handle this and all other collection operations. This module would then deprecate
currently available functions
xmldb:create-collection,xmldb:collection-availableand the like. While this is definitely a controversial proposal it also has the potential to rethink our current approach while maintaining backwards compatibility.
The fact that xmldb:create-collection already has a two parameter signature does rule out option 2 unless we choose to also
introduce a breaking change. The current xmldb:create-collection#2 would have to be changed to
xmldb:create-collection($collectionUri as xs:string) as xs:string removing the parent collection parameter that is currently expected.
I personally favor having the collection URIs to be in one parameter but certainly am open to discuss the motivation behind the current implementation.
I agree this is a worthy addition to be added to the core in Java. In the past almost all projects that I undertook required me to write a function in XQuery like: dbu:create-collection($collection-uri).
I think the best solution would be to add an xmldb:create-collection#1 function to XMLDBModule.java and add its implementation to XMLDBCreateCollection.java, e.g.:
xmldb:create-collection($collection-uri as xs:string) as xs:string?