db:open() - other ways to set context or declare the db?

Monday, 5 November 2012 · 3 messages · last reply 6 Nov 2012
CM
Colin McEnearney5 Nov 2012 18:40 #
Hi, Using restxq, do all queries have to begin with db:open('web_app_db')//myquery/here , or can the database be declared? Or set as default somewhere? Thanks, Colin
AH
Alexander Holupirek5 Nov 2012 23:07 #
Quoted text · Colin McEnearney · 7 lines
On 05.11.2012, at 17:40, Colin McEnearney wrote: > Hi, > > Using restxq, do all queries have to begin with db:open('web_app_db')//myquery/here , or can the database be declared? Or set as default somewhere? > > Thanks, > Colin
Hi Colin, we use db:open all over the place.
(: ----------------------------------------------------- :)
module namespace _ = 'com.gmail.colinmcenearney.db';

declare namespace restxq = "http://exquery.org/ns/restxq";

(: Database name used throughout the application. :)
declare variable $_:MY-DB := '_catalog';

(:~ Show users page. :)
declare
  %restxq:path("/show-users")
  %output:method("html")
function _:show-users()
{
  <div> {
    serialize(db:open($_:MY-DB)//user/@id)
  } </div>
};
(: ----------------------------------------------------- :)
Database name declarations often go to a constants.xqm. Cheers, Alex
CM
Colin McEnearney6 Nov 2012 00:27 #
Thanks Alex! Good to know you use that construct a lot, and that it's not a bad practice for any reason
Quoted text · Alexander Holupirek · 41 lines
On Mon, Nov 5, 2012 at 5:07 PM, Alexander Holupirek < alexander.holupirek at uni-konstanz.de> wrote: > On 05.11.2012, at 17:40, Colin McEnearney wrote: > > > Hi, > > > > Using restxq, do all queries have to begin with > db:open('web_app_db')//myquery/here , or can the database be declared? Or > set as default somewhere? > > > > Thanks, > > Colin > > Hi Colin, > > we use db:open all over the place. > > (: ----------------------------------------------------- :) > module namespace _ = 'com.gmail.colinmcenearney.db'; > > declare namespace restxq = "http://exquery.org/ns/restxq"; > > (: Database name used throughout the application. :) > declare variable $_:MY-DB := '_catalog'; > > (:~ Show users page. :) > declare > %restxq:path("/show-users") > %output:method("html") > function _:show-users() > { > <div> { > serialize(db:open($_:MY-DB)//user/@id) > } </div> > }; > (: ----------------------------------------------------- :) > > Database name declarations often go to a constants.xqm. > > Cheers, > Alex

⚡Generated with XQuery