exist icon indicating copy to clipboard operation
exist copied to clipboard

[feature] add `mkdir -p` like function to xmldb XQuery module

Open line-o opened this issue 3 years ago • 1 comments

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

  1. a new function xmldb:create-collection-recursive accepting one parameter:
  • collectionUri as xs:string
  1. or add a signature to xmldb:create-collection accepting two parameters:
  • collectionUri as xs:string
  • options as xs:map
  1. 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-available and 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.

line-o avatar Feb 11 '22 11:02 line-o

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?

adamretter avatar Sep 16 '23 09:09 adamretter