xqerl icon indicating copy to clipboard operation
xqerl copied to clipboard

tabular data and the xqerl rest db api

Open grantmacken opened this issue 2 years ago • 0 comments

  • [x] feat: create tabular data: csv data is posted and stored csv data as array into db, along with csvw meta data about array. The presence of the meta data, associates the stored array as being a tabular data resource
  • [x] feat: retrieve tabular data. Accept header determines representation
  • [x] fix: remove redundant gh actions yml file
  • [x] fix: remove superficial domain constraint check in db_create.xq

As part of the rest db service #53 issue

more post items: csv content-type stored as a XDM array item, could be retrieved with Accept header as either a serialized JSON array or text or maybe a standard XML csv serialization if there is one

Notes:

  • https://www.rfc-editor.org/rfc/rfc4180
  • https://www.w3.org/TR/2016/NOTE-tabular-data-primer-20160225/

Creating tabular data

  • POST csv data with content-header text/csv. Data stored as XDM array item however the stored item is not just a product of csv:parse()
let $toTabularDataModel := function( $csvData  ){
  let $data := $csvData=> csv:parse()
  let $names :=  $data => array:head()
  let $records :=  $data => array:tail()
  return
  $records => array:for-each( function($record){
   array {
     for $field at $i in $record?*
     let $key := array:get($names,$i)
     return map:entry( $key , $field)}})
}

The stored XDM item is a representation of the csv-to-json minimal mode as outlined in

  • https://www.w3.org/TR/csv2json/
  • https://www.w3.org/TR/2016/NOTE-tabular-data-primer-20160225/

Metadata about the item is also created and stored in the db using a URI template pattern outlined by the W3C Working Group.

 map { 
      "@context": "http://www.w3.org/ns/csvw",
      "url": $uri
      } => db:put( $uri || '-metadata.json' ),

For our purposes this tags the XDM array item as having originated from csv data and can be treated as tabular data

Retrieving tabular data

tabular data resource content negotiation via accept header

  • GET - accept header application/json
    serialize as json
  • GET - accept header text/csv
    serialize as csv text only if db contains $uri || '-metadata.json' otherwise request not acceptable
  • GET - accept header text/html
    serialize as html table only if db contains $uri || '-metadata.json' otherwise request not acceptable

grantmacken avatar Oct 13 '22 21:10 grantmacken