dba/databases
library moduleURA
Summary
Create new database.
- Tags
Author: Christian Grün, BaseX Team 2005-21, BSD License
__source : databases/db-create.xqm
Imports
This module is imported by 0 modules. It imports 2 modules.
Variables
Functions
4.1 dba:db-create
Arities: dba:db-create#3URdba:db-create#4RA
dba:db-create
(
$name
as
xs:string
, $opts
as
xs:string*
, $lang
as
xs:string?
)
as
empty-sequence()
dba:db-create
(
$name
as
xs:string?
, $opts
as
xs:string*
, $lang
as
xs:string?
, $error
as
xs:string?
)
as
element(html)
- name
as
xs:string
database - opts
as
xs:string*
database options - lang
as
xs:string?
language
empty-sequence()
redirection
Invokes 11 functions from 5 modules
- html:button#2
- html:focus#1
- html:link#2
- html:option#3
- html:wrap#2
- util:redirect#2
- {http://basex.org/modules/db}create#4
- {http://basex.org/modules/db}exists#1
- {http://www.w3.org/2005/xpath-functions/map}entry#2
- {http://www.w3.org/2005/xpath-functions/map}merge#1
- {http://www.w3.org/2005/xpath-functions}error#2
Invoked by 0 functions from 0 modules
Annotations
%rest:GET | () |
%rest:path | ('/dba/db-create') |
%rest:query-param | ('name','{$name}') |
%rest:query-param | ('opts','{$opts}') |
%rest:query-param | ('lang','{$lang}','en') |
%rest:query-param | ('error','{$error}') |
%output:method | ('html') |
Annotations
%updating | () |
%rest:POST | () |
%rest:path | ('/dba/db-create') |
%rest:query-param | ('name','{$name}') |
%rest:query-param | ('opts','{$opts}') |
%rest:query-param | ('lang','{$lang}') |
Source ( 78 lines)
function dba:db-create(
$name as xs:string,
$opts as xs:string*,
$lang as xs:string?
) as empty-sequence() {
try {
if(db:exists($name)) then (
error((), 'Database already exists.')
) else (
db:create($name, (), (), map:merge((
for $option in ('textindex', 'attrindex', 'tokenindex', 'ftindex',
'stemming', 'casesens', 'diacritics', 'updindex')
return map:entry($option, $opts = $option),
$lang ! map:entry('language', .)))
),
util:redirect($dba:SUB, map { 'name': $name,
'info': 'Database "' || $name || '" was created.' })
)
} catch * {
util:redirect('db-create', map {
'name': $name, 'opts': $opts, 'lang': $lang, 'error': $err:description
})
}
}
function dba:db-create(
$name as xs:string?,
$opts as xs:string*,
$lang as xs:string?,
$error as xs:string?
) as element(html) {
let $opts := if($opts = 'x') then $opts else ('textindex', 'attrindex')
return html:wrap(map { 'header': $dba:CAT, 'error': $error },
<tr>
<td>
<form action='db-create' method='post' autocomplete='off'>
<h2>{
html:link('Databases', $dba:CAT), ' » ',
html:button('create', 'Create')
}</h2>
<!-- dummy value; prevents reset of options when nothing is selected -->
<input type='hidden' name='opts' value='x'/>
<table>
<tr>
<td>Name:</td>
<td>
<input type='hidden' name='opts' value='x'/>
<input type='text' name='name' value='{ $name }' id='name'/>
{ html:focus('name') }
<div class='small'/>
</td>
</tr>
<tr>
<td colspan='2'>{
<h3>{ html:option('textindex', 'Text Index', $opts) }</h3>,
<h3>{ html:option('attrindex', 'Attribute Index', $opts) }</h3>,
<h3>{ html:option('tokenindex', 'Token Index', $opts) }</h3>,
html:option('updindex', 'Incremental Indexing', $opts),
<div class='small'/>,
<h3>{ html:option('ftindex', 'Fulltext Indexing', $opts) }</h3>
}</td>
</tr>
<tr>
<td colspan='2'>{
html:option('stemming', 'Stemming', $opts),
html:option('casesens', 'Case Sensitivity', $opts),
html:option('diacritics', 'Diacritics', $opts)
}</td>
</tr>
<tr>
<td>Language:</td>
<td><input type='text' name='language' value='{ $lang }'/></td>
</tr>
</table>
</form>
</td>
</tr>
)
}
Namespaces
The following namespaces are defined:
Prefix | Uri |
---|---|
ann | http://www.w3.org/2012/xquery |
dba | dba/databases 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
html | dba/html |
output | http://www.w3.org/2010/xslt-xquery-serialization |
rest | http://exquery.org/ns/restxq |
util | dba/util |
6 RestXQ
Paths defined 2.
Path | Method | Function |
---|---|---|
/dba/db-create | GET | dba:db-create#4 |
/dba/db-create | POST | dba:db-create#3 |
Source Code
(:~
: Create new database.
:
: @author Christian Grün, BaseX Team 2005-21, BSD License
:)
module namespace dba = 'dba/databases';
import module namespace html = 'dba/html' at '../lib/html.xqm';
import module namespace util = 'dba/util' at '../lib/util.xqm';
(:~ Top category :)
declare variable $dba:CAT := 'databases';
(:~ Sub category :)
declare variable $dba:SUB := 'database';
(:~
: Form for creating a new database.
: @param $name entered name
: @param $opts chosen database options
: @param $lang entered language
: @param $error error string
: @return page
:)
declare
%rest:GET
%rest:path('/dba/db-create')
%rest:query-param('name', '{$name}')
%rest:query-param('opts', '{$opts}')
%rest:query-param('lang', '{$lang}', 'en')
%rest:query-param('error', '{$error}')
%output:method('html')
function dba:db-create(
$name as xs:string?,
$opts as xs:string*,
$lang as xs:string?,
$error as xs:string?
) as element(html) {
let $opts := if($opts = 'x') then $opts else ('textindex', 'attrindex')
return html:wrap(map { 'header': $dba:CAT, 'error': $error },
<tr>
<td>
<form action='db-create' method='post' autocomplete='off'>
<h2>{
html:link('Databases', $dba:CAT), ' » ',
html:button('create', 'Create')
}</h2>
<!-- dummy value; prevents reset of options when nothing is selected -->
<input type='hidden' name='opts' value='x'/>
<table>
<tr>
<td>Name:</td>
<td>
<input type='hidden' name='opts' value='x'/>
<input type='text' name='name' value='{ $name }' id='name'/>
{ html:focus('name') }
<div class='small'/>
</td>
</tr>
<tr>
<td colspan='2'>{
<h3>{ html:option('textindex', 'Text Index', $opts) }</h3>,
<h3>{ html:option('attrindex', 'Attribute Index', $opts) }</h3>,
<h3>{ html:option('tokenindex', 'Token Index', $opts) }</h3>,
html:option('updindex', 'Incremental Indexing', $opts),
<div class='small'/>,
<h3>{ html:option('ftindex', 'Fulltext Indexing', $opts) }</h3>
}</td>
</tr>
<tr>
<td colspan='2'>{
html:option('stemming', 'Stemming', $opts),
html:option('casesens', 'Case Sensitivity', $opts),
html:option('diacritics', 'Diacritics', $opts)
}</td>
</tr>
<tr>
<td>Language:</td>
<td><input type='text' name='language' value='{ $lang }'/></td>
</tr>
</table>
</form>
</td>
</tr>
)
};
(:~
: Creates a database.
: @param $name database
: @param $opts database options
: @param $lang language
: @return redirection
:)
declare
%updating
%rest:POST
%rest:path('/dba/db-create')
%rest:query-param('name', '{$name}')
%rest:query-param('opts', '{$opts}')
%rest:query-param('lang', '{$lang}')
function dba:db-create(
$name as xs:string,
$opts as xs:string*,
$lang as xs:string?
) as empty-sequence() {
try {
if(db:exists($name)) then (
error((), 'Database already exists.')
) else (
db:create($name, (), (), map:merge((
for $option in ('textindex', 'attrindex', 'tokenindex', 'ftindex',
'stemming', 'casesens', 'diacritics', 'updindex')
return map:entry($option, $opts = $option),
$lang ! map:entry('language', .)))
),
util:redirect($dba:SUB, map { 'name': $name,
'info': 'Database "' || $name || '" was created.' })
)
} catch * {
util:redirect('db-create', map {
'name': $name, 'opts': $opts, 'lang': $lang, 'error': $err:description
})
}
};