Hi Christian,
The proposed signatures make sense to me. Copied from the github ticket:
db:properties($db as xs:string) as element(properties)* db:properties($db as xs:string, $path as xs:string) as element(properties)* db:property($db as xs:string, $path as xs:string, $key as xs:string) as xs:string db:set-property($db as xs:string, $path as xs:string, $key as xs:string, $value as xs:string) as empty-sequence() PROP GET PROP GET [path] PROP GET [path] [key] PROP SET [path] [key] [value]
Possibly add signatures to allow removing a previously set property:
db:set-property($db as xs:string, $path as xs:string, $key as xs:string) as empty-sequence() PROP SET [path] [key]
Allowing arbitrary strings as keys is definitely helpful. The returned values of db:properties and PROP GET could be like:
<properties resource="/path/to/file.xml"> <property name="prop1">value1</property> <property name="prop2">value2</property> </properties>
Any number of property key-value pairs could be set by users. The resource attribute would be unmodifiable, of course.
Thinking of possible use cases, one might use something like the below example to find all documents with a specific property value:
for $a in db:properties('testdb')[properties/property[@name = 'prop1'][string() = 'value1'] return if (db:is-xml('testdb', $a/@resource)) then db:open('testdb', $a/@resource) else ()
Thanks, Vincent
-----Original Message----- From: basex-talk-bounces@mailman.uni-konstanz.de [mailto:basex-talk-bounces@mailman.uni-konstanz.de] On Behalf Of Christian GrĂ¼n Sent: Wednesday, September 03, 2014 9:43 AM To: Marco Lettere Cc: BaseX Subject: Re: [basex-talk] db documents metadata
Maybe something like the following could be a good compromise?
<resource raw="false" content-type="application/xml" modified-date="2012-02-02T19:13:42.000Z" name="file.xml"> <property name="prop1">value1</property> <property name="prop2">value2</property> </resource>
Funny, I also thought about this solution.. One advantage would be that we could use arbitrary strings as keys. However, it would make the output incompatible to previous versions (..unless we use another function for it).
More suggestions are welcome, C.