Flask-SQLAlchemy is fun to use, incredibly easy for basic applications, andreadily extends for larger applications. For the complete guide, checkoutthe API documentation on the SQLAlchemy class.

A Minimal Application¶

For the common case of having one Flask application all you have to do isto create your Flask application, load the configuration of choice andthen create the SQLAlchemy object by passing it the application.

Once created, that object then contains all the functions and helpersfrom both sqlalchemy and sqlalchemy.orm. Furthermore itprovides a class called Model that is a declarative base which can beused to declare models:

To create the initial database, just import the db object from aninteractive Python shell and run theSQLAlchemy.create_all() method to create thetables and database:

Boom, and there is your database. Now to create some users:

But they are not yet in the database, so let’s make sure they are:

SQLAlchemy will use the Integer and String(32) type information when issuing a CREATE TABLE statement and will use it again when reading back rows SELECTed from the database. Functions that accept a type (such as Column) will typically accept a type class or instance; Integer is equivalent to Integer with no construction arguments in this ca. A Minimal Application¶. For the common case of having one Flask application all you have to do is to create your Flask application, load the configuration of choice and then create the SQLAlchemy object by passing it the application. Once created, that object then contains all the functions and helpers from both sqlalchemy and sqlalchemy.orm.

Accessing the data in database is easy as a pie:

Note how we never defined a __init__ method on the User class?That’s because SQLAlchemy adds an implicit constructor to all modelclasses which accepts keyword arguments for all its columns andrelationships. If you decide to override the constructor for anyreason, make sure to keep accepting **kwargs and call the superconstructor with those **kwargs to preserve this behavior:

Simple Relationships¶

SQLAlchemy connects to relational databases and what relational databasesare really good at are relations. As such, we shall have an example of anapplication that uses two tables that have a relationship to each other:

First let’s create some objects:

This is the DeafBlind text description of “Deaf World and Interpreting Conference” flyer. The upper half of the flyer is covered with a background image of a bridge sprouting out of two cliffsides. The ends of both bridges is illustrated with an ASL sign of “F” or “9.” These ends connect to make an ASL sign of “interpreter.”. This is the DeafBlind text description of “Deaf World and Interpreting Conference” flyer. The upper half of the flyer is covered with a background image of a bridge sprouting out of two cliffsides. The ends of both bridges is illustrated with an ASL sign of “F” or “9.” These ends connect to. DB-Text is a general use tool to open and edit data in text format on OS X, the most used way to distribute data organized by rows and columns. DB-Text is able to open import, edit, and manage text data organized by rows and columns in a more practical and effective way than any text editor.

As you can see, there is no need to add the Post objects to thesession. Since the Category is part of the session all objectsassociated with it through relationships will be added too. It doesnot matter whether db.session.add()is called before or after creating these objects. The association canalso be done on either side of the relationship - so a post can becreated with a category or it can be added to the list of posts ofthe category.

Let’s look at the posts. Accessing them will load them from the databasesince the relationship is lazy-loaded, but you will probably not noticethe difference - loading a list is quite fast:

While lazy-loading a relationship is fast, it can easily become a majorbottleneck when you end up triggering extra queries in a loop for morethan a few objects. For this case, SQLAlchemy lets you override theloading strategy on the query level. If you wanted a single query toload all categories and their posts, you could do it like this:

If you want to get a query object for that relationship, you can do sousing with_parent(). Let’s excludethat post about Snakes for example:

Road to Enlightenment¶

The only things you need to know compared to plain SQLAlchemy are:

  1. SQLAlchemy gives you access to the following things:

    • all the functions and classes from sqlalchemy andsqlalchemy.orm

    • a preconfigured scoped session called session

    • the metadata

    • the engine

    • a SQLAlchemy.create_all() and SQLAlchemy.drop_all()methods to create and drop tables according to the models. Wallpaper engine g2a.

    • a Model baseclass that is a configured declarative base.

  2. The Model declarative base class behaves like a regularPython class but has a query attribute attached that can be used toquery the model. (Model and BaseQuery)

  3. You have to commit the session, but you don’t have to remove it atthe end of the request, Flask-SQLAlchemy does that for you.

This XQuery Module contains functions for processing databases from within XQuery. Existing databases can be opened and listed, its contents can be directly accessed, documents can be added to and removed, etc.

  • 1Conventions
  • 2General Functions
  • 3Read Operations
  • 4Value Indexes
  • 5Updates
  • 6Helper Functions

All functions and errors in this module are assigned to the http://basex.org/modules/db namespace, which is statically bound to the db prefix.

Database Nodes[edit]

In BaseX, two internal representations exist for nodes.

  • XML fragments are generated by XQuery node constructors.
  • Database nodes are:
    • stored in a persistent database on disk;
    • nodes of a document that has been generated temporarily with fn:doc, fn:parse-xml and other functions; or
    • result of a main-memory update operation.

Some operations are restricted to database nodes, but you can convert XML fragments to database nodes by applying an empty update or transform operation to a node. Two examples:

  • Retrieve the internal node id of an XML fragment:
  • Puts a marker element around the result of a full-text request (see ft:mark for more details):

db:system[edit]

Signaturesdb:system() as element(system)
SummaryReturns general information on the database system the current values of all global and local Options. The INFO command returns similar output.

db:option[edit]

Signaturesdb:option($name as xs:string) as xs:string
SummaryReturns the current value (string, integer, boolean, map) of a global or local Option with the specified $name. The GET command works similar.
Errorsoption: the specified option is unknown.
Examples
  • db:option('dbpath') returns the database path string.
  • db:option('serializer') returns a map with the current serialization parameters.
  • declare option db:chop 'true'; db:option('chop') returns true (irrespective of the global value).

db:info[edit]

Signaturesdb:info($db as xs:string) as element(database)
SummaryReturns meta information on the database $db. The output is similar to the INFO DB command.
Errorsopen: the addressed database does not exist or could not be opened.

db:property[edit]

Signaturesdb:property($db as xs:string, $name as xs:string) as xs:anyAtomicType
SummaryReturns the value (string, boolean, integer) of a property with the specified $name in the database $db. The available properties are the ones returned by db:info.
Errorsproperty: the specified property is unknown.
Examples
  • db:property('db', 'size') returns the number of bytes occupied by the database db.
  • db:property('xmark', 'textindex') indicates if the xmark database has a text index.
  • db:property('discogs', 'uptodate') indicates if the database statistics and index structures of the discogs database are up-to-date.

db:list[edit]

Signaturesdb:list() as xs:string*
db:list($db as xs:string) as xs:string*
db:list($db as xs:string, $path as xs:string) as xs:string*
SummaryThe result of this function is dependent on the number of arguments:
  • Without arguments, the names of all databases are returned that are accessible to the current user.
  • If a database $db is specified, all documents and raw files of the specified database are returned.
  • The list of returned resources can be restricted by the $path argument.
Errorsopen: the addressed database does not exist or could not be opened.
Examples
  • db:list('docs') returns the names of all documents of a database named docs.

db:list-details[edit]

Signaturesdb:list-details() as element(database)*
db:list-details($db as xs:string) as element(resource)*
db:list-details($db as xs:string, $path as xs:string) as element(resource)*
SummaryWithout arguments, an element is returned for each database that is accessible to the current user:
  • An element has a value, which is the name of the database, and several attributes, which contain the number of stored resources, the modification date, the database size on disk (measured in bytes), and a path to the original database input.

If a database $db is specified, an element for each documents and raw file of the specified database is returned:

  • An element has a value, which is the name of the resource, and several attributes, which contain the content type, the modification date, the raw flag (which indicates if the resource is binary or XML), and the size of a resource.
  • The value of the size attribute depends on the resource type: for documents, it represents the number of nodes; for binary data, it represents the file size (measured in bytes).
  • Returned databases resources can be further restricted by the $path argument.
Errorsopen: the addressed database does not exist or could not be opened.
Examples
  • db:list-details('shop') returns the names plus additional info on all resources of a database named shop.

db:dir[edit]

Signaturesdb:dir($db as xs:string, $path as xs:string) as element()*
SummaryReturns meta data on all directories and resources of the database $db in the specified directory $path. Two types of elements are returned:
  • resource represents a resource. The element value is the directory path; content type, modification date, raw flag (which indicates if the resource is binary or XML), and size of the resource are returned as attributes.
  • dir represents a directory. The element value is the directory path; the modification date is returned as attribute.

Please note that directories are not stored in BaseX. Instead, they result implicitly from the paths of stored resources.

Errorsopen: the addressed database does not exist or could not be opened.
path: the specified path is invalid.
Examples
  • db:dir('shop', 'books') returns all entries of the books directory of a shop database.

db:backups[edit]

Signaturesdb:backups() as element(backup)*
db:backups($db as xs:string) as element(backup)*
SummaryReturns an element sequence containing all available database backups.
If a database $db is specified, the sequence will be restricted to the backups matching this database.
Examples
  • db:backups('factbook') returns all backups that have been made from the factbook database.

db:open[edit]

Signaturesdb:open($db as xs:string) as document-node()*
db:open($db as xs:string, $path as xs:string) as document-node()*
SummaryOpens the database $db and returns all document nodes.
The document nodes to be returned can be filtered with the $path argument.
Errorsopen: the addressed database does not exist or could not be opened.
Examples
  • db:open('docs') returns all documents from the database named docs.
  • db:open('db', 'one') returns all documents from the database named db located in the path one.
  • for $i in 1 to 3 return db:open('db' $i)//item returns all item elements from the databases db1, db2 and db3.

db:open-pre[edit]

Signaturesdb:open-pre($db as xs:string, $pres as xs:integer*) as node()*
SummaryOpens the database $db and returns all distinct nodes with the pre values $pres in document order.
The PRE value provides very fast access to an existing database node, but it will change whenever a node with a smaller pre values is added to or deleted from a database.
Errorsopen: the addressed database does not exist or could not be opened.
range: the specified pre value does not exist in the database.
Examples
  • db:open-pre('docs', 0) returns the first database node from the database named docs.

db:open-id[edit]

Signaturesdb:open-id($db as xs:string, $ids as xs:integer*) as node()*
SummaryOpens the database $db and returns all distinct nodes with the specified $ids in document order.
Each database node has a persistentID value. Access to the node id can be sped up by turning on the UPDINDEX option.
Errorsopen: the addressed database does not exist or could not be opened.
range: the specified id value does not exist in the database.

db:node-pre[edit]

Signaturesdb:node-pre($nodes as node()*) as xs:integer*
SummaryReturns the pre values of the specified $nodes, which must all be database nodes.
The PRE value provides very fast access to an existing database node, but it will change whenever a node with a smaller pre values is added to or deleted from a database.
Errorsnode: $nodes contains a node which is not stored in a database.
Examples
  • db:node-pre(doc('input')) returns 0 if the database input contains a single document.

db:node-id[edit]

Signaturesdb:node-id($nodes as node()*) as xs:integer*
SummaryReturns the id values of the specified $nodes, which must all be database nodes.
Each database node has a persistentID value. Access to the node id can be sped up by turning on the UPDINDEX option.
Errorsnode: $nodes contains a node which is not stored in a database.

db:retrieve[edit]

Signaturesdb:retrieve($db as xs:string, $path as xs:string) as xs:base64Binary
SummaryReturns a binary resource addressed by the database $db and $path as streamablexs:base64Binary.
Errorsopen: the addressed database does not exist or could not be opened.
mainmem: the database is not persistent (stored on disk).
Examples
  • db:retrieve('DB', 'music/01.mp3') returns the specified audio file as raw data.
  • stream:materialize(db:retrieve('DB', 'music/01.mp3')) materializes the streamable result in main-memory before returning it.
  • convert:binary-to-string(db:retrieve('DB', 'info.txt'), 'UTF-8') converts a binary database resource as UTF-8 text and returns a string.

db:export[edit]

Signaturesdb:export($db as xs:string, $path as xs:string) as empty-sequence()
db:export($db as xs:string, $path as xs:string, $params as item()) as empty-sequence()
SummaryExports the specified database $db to the specified file $path. Existing files will be overwritten.
The $params argument contains serialization parameters. As with fn:serialize(), the parameters can be specified
  • either as children of an <output:serialization-parameters/> element:
  • or as map, which contains all key/value pairs:
Errorsopen: the addressed database does not exist or could not be opened.
ExamplesExport all files as text:

The following query can be used to export parts of the database:

db:text[edit]

Signaturesdb:text($db as xs:string, $strings as xs:string*) as text()*
SummaryReturns all text nodes of the database $db that have one of the specified $strings as values and that are stored in the text index.
Errorsopen: the addressed database does not exist or could not be opened.
no-index: the index is not available.
Examples
  • db:text('DB', 'QUERY')/. returns the parents of all text nodes of the database DB that match the string QUERY.

db:text-range[edit]

Signaturesdb:text-range($db as xs:string, $min as xs:string, $max as xs:string) as text()*
SummaryReturns all text nodes of the database $db whose values are between $min and $max and that are stored in the text index.
Errorsopen: the addressed database does not exist or could not be opened.
no-index: the index is not available.
Examples
  • db:text-range('DB', '2000', '2001') returns all text nodes of the database DB that are found in between 2000 and 2001.

db:attribute[edit]

Signaturesdb:attribute($db as xs:string, $strings as xs:string*) as attribute()*
db:attribute($db as xs:string, $strings as xs:string*, $name as xs:string) as attribute()*
SummaryReturns all attribute nodes of the database $db that have one of the specified $strings as values and that are stored in the attribute index.
If $name is specified, the resulting attribute nodes are filtered by their attribute name.
Errorsopen: the addressed database does not exist or could not be opened.
no-index: the index is not available.
Examples
  • db:attribute('DB', 'QUERY', 'id')/. returns the parents of all id attribute nodes of the database DB that have QUERY as string value.

db:attribute-range[edit]

Signaturesdb:attribute-range($db as xs:string, $min as xs:string, $max as xs:string) as attribute()*
db:attribute-range($db as xs:string, $min as xs:string, $max as xs:string, $name as xs:string) as attribute()*
SummaryReturns all attributes of the database $db, the string values of which are larger than or equal to $min and smaller than or equal to $max and that are stored in the attribute index.
Errorsopen: the addressed database does not exist or could not be opened.
no-index: the index is not available.
Examples
  • db:attribute-range('DB', 'id456', 'id473', 'id') returns all @id attributes of the database DB that have a string value in between id456 and id473.

db:token[edit]

Signaturesdb:token($db as xs:string, $tokens as xs:string*) as attribute()*
db:token($db as xs:string, $tokens as xs:string*, $name as xs:string) as attribute()*
SummaryReturns all attribute nodes of the database $db the values of which contain one of the specified $tokens.
If $name is specified, the resulting attribute nodes are filtered by their attribute name.
Errorsopen: the addressed database does not exist or could not be opened.
no-index: the index is not available.
Examples
  • db:token('DB', 'row', 'class')/parent::div returns all div nodes of database DB with a class attribute that contains the token row.

Important note: All functions in this section are updating functions: they will not be immediately executed, but queued on the Pending Update List, which will be processed after the actual query has been evaluated. This means that the order in which the functions are specified in the query does usually not reflect the order in which the code will be evaluated.

db:create[edit]

Signaturesdb:create($db as xs:string) as empty-sequence()
db:create($db as xs:string, $inputs as item()*) as empty-sequence()
db:create($db as xs:string, $inputs as item()*, $paths as xs:string*) as empty-sequence()
db:create($db as xs:string, $inputs as item()*, $paths as xs:string*, $options as map(*)?) as empty-sequence()
SummaryCreates a new database with name $db and adds initial documents specified via $inputs to the specified $paths:
  • $inputs may be strings or nodes:
    • nodes may be of any type except for attributes
    • strings can be a URI pointing to a file/directory or an XML string (which is detected by the leading < character)
    • a path must be specified if the input is not a file or directory reference
  • The parsing and indexing behavior can be controlled via $options:
    • allowed options are ADDCACHE and the indexing, full-text indexing, parsing and XML parsing options, all in lower case
    • parsing options will only impact string input (URIs, XML strings), because nodes have already been parsed.
  • An existing database will be overwritten.
  • Database creation takes place after most other update operations (see Pending Update List). As a consequence, a newly created database cannot be addressed in the same query.
Errorslock: a database is opened by another process.
name: the specified name is not a valid database name.
conflict: the same database was addressed more than once.
args: the number of specified inputs and paths differs.
Examples
  • db:create('DB') creates the empty database DB.
  • db:create('DB', '/home/dir/doc.xml') creates the database DB and adds the document /home/dir/doc.xml as initial content.
  • db:create('DB', <a/>, 'doc.xml') creates the database DB and adds the document with content <a/> under the name doc.xml.
  • db:create('DB', '/home/dir/', 'docs/dir') creates the database DB and adds the documents in /home/dir to the database under the path docs/dir.
  • db:create('DB', file:list('.'), (), map { 'ftindex': true() }) adds all files of the current working directory to a new database, preserving relative filesystem paths and creating a full-text index.

db:drop[edit]

Signaturesdb:drop($db as xs:string) as empty-sequence()
SummaryDrops the database $db and all connected resources.
Errorsopen: the addressed database does not exist or could not be opened.
lock: a database is opened by another process.
conflict: the same database was addressed more than once.
Examples
  • db:drop('DB') drops the database DB.

db:add[edit]

Signaturesdb:add($db as xs:string, $input as item()) as empty-sequence()
db:add($db as xs:string, $input as item(), $path as xs:string?) as empty-sequence()
db:add($db as xs:string, $input as item(), $path as xs:string?, $options as map(*)?) as empty-sequence()
SummaryAdds documents specified by $input to the database $db with the specified $path:
  • A document with the same path may occur more than once in a database. If you want to enforce single instances, use db:replace instead.
  • See db:create for more details on the input and path arguments.
  • The parsing behavior can be controlled via $options:
    • allowed options are ADDCACHE and the parsing and XML parsing options, all in lower case
    • parsing options will only impact string input (URIs, XML strings), because nodes have already been parsed
Errorsopen: the addressed database does not exist or could not be opened.
Examples
  • db:add('DB', '/home/dir/doc.xml') adds the file /home/dir/doc.xml to the database DB.
  • db:add('DB', <a/>, 'doc.xml') adds a document node to the database DB under the name doc.xml.
  • db:add('DB', '/home/dir', 'docs/dir', map { 'addcache': true() }) adds all documents in /home/dir to the database DB under the path docs/dir. In order to reduce memory consumption, the files will be cached before being added to the database.

db:delete[edit]

Signaturesdb:delete($db as xs:string, $path as xs:string) as empty-sequence()
SummaryDeletes resource(s), specified by $path, from the database $db.
Errorsopen: the addressed database does not exist or could not be opened.
path: the specified path is invalid.
Examples
  • db:delete('DB', 'docs/dir/doc.xml') deletes the resource docs/dir/doc.xml from DB.
  • db:delete('DB', 'docs/dir') deletes all resources from DB in the specified path docs/dir.

db:copy[edit]

Signaturesdb:copy($db as xs:string, $name as xs:string) as empty-sequence()
SummaryCreates a copy of the database $db, which will be called $name.
Errorsopen: the addressed database does not exist or could not be opened.
lock: a database is opened by another process.
name: invalid database name.
conflict: the same database was addressed more than once.

db:alter[edit]

Signaturesdb:alter($db as xs:string, $name as xs:string) as empty-sequence()
SummaryRenames the database $db to $name.
Errorsopen: the addressed database does not exist or could not be opened.
lock: a database is opened by another process.
name: invalid database name.
conflict: the same database was addressed more than once.

db:create-backup[edit]

Signaturesdb:create-backup($db as xs:string) as empty-sequence()
SummaryCreates a backup of the database $db.
Errorsopen: the addressed database does not exist or could not be opened.
name: invalid database name.
conflict: the same database was addressed more than once.
Examples
  • db:create-backup('DB') creates a backup of the database DB.
Db textworks

db:drop-backup[edit]

Signaturesdb:drop-backup($name as xs:string) as empty-sequence()
SummaryDrops all backups of the database with the specified $name. If the given $name points to a specific backup file, only this specific backup file is deleted.
Errorsbackup: No backup file found.
name: invalid database name.
conflict: the same database was addressed more than once.
Examples
  • db:drop-backup('DB') drops all backups of the database DB.
  • db:drop-backup('DB-2014-03-13-17-36-44') drops the specific backup file DB-2014-03-13-17-36-44.zip of the database DB.

db:alter-backup[edit]

Signaturesdb:alter-backup($name as xs:string, $new-name as xs:string) as empty-sequence()
SummaryRenames all backups of the database with the specified $name to $new-name. The directory inside the archive will be renamed as well. If the given $name points to a specific backup file, only this specific backup file will be renamed.
Errorsbackup: No backup file found.
name: invalid database name.
conflict: the same database was addressed more than once.
Examples
  • db:alter-backup('DB', 'DB2) renames all backups of the database DB to DB2.

db:restore[edit]

Signaturesdb:restore($name as xs:string) as empty-sequence()
SummaryRestores the database with the specified $name. The $name may include the timestamp of the backup file.
Errorslock: a database is opened by another process.
name: invalid database name.
no-backup: No backup found.
conflict: the same database was addressed more than once.
Examples
  • db:restore('DB') restores the database DB.
  • db:restore('DB-2014-03-13-18-05-45') restores the database DB from the backup file with the given timestamp.

db:optimize[edit]

Signaturesdb:optimize($db as xs:string) as empty-sequence()
db:optimize($db as xs:string, $all as xs:boolean) as empty-sequence()
db:optimize($db as xs:string, $all as xs:boolean, $options as map(*)?) as empty-sequence()
SummaryOptimizes the meta data and indexes of the database $db.
If $all is true, the complete database will be rebuilt.
The $options argument can be used to control indexing. The syntax is identical to the db:create function: Allowed options are all indexing and full-text options. UPDINDEX is only supported if $all is true.
Errorsopen: the addressed database does not exist or could not be opened.
Examples
  • db:optimize('DB') optimizes the database structures of the database DB.
  • db:optimize('DB', true(), map { 'ftindex': true() }) optimizes all database structures of the database DB and creates a full-text index.

db:rename[edit]

Signaturesdb:rename($db as xs:string, $source as xs:string, $target as xs:string) as empty-sequence()
SummaryMoves all resources(s) of database $db, which are found in the supplied $source path, to the supplied $target path. The paths may point to single resources or directories. No updates will take place if a non-existing source path is supplied.
Errorsopen: the addressed database does not exist or could not be opened.
path: the specified source or target path, or one of its descendants, is invalid.
Examples
  • db:rename('DB', 'docs/dir/doc.xml', 'docs/dir/newdoc.xml') renames the resource docs/dir/doc.xml to docs/dir/newdoc.xml in the database DB.
  • db:rename('DB', 'docs/dir', 'docs/newdir') moves all resources in the database DB from docs/dir to {Code docs/newdir}}.

db:replace[edit]

Signaturesdb:replace($db as xs:string, $path as xs:string, $input as item()) as empty-sequence()
db:replace($db as xs:string, $path as xs:string, $input as item(), $options as map(*)?) as empty-sequence()
SummaryReplaces a resource, specified by $path, in the database $db with the contents of $input, or adds it as a new resource:
  • See db:create for more details on the input argument.
  • The parsing behavior can be controlled via $options:
    • allowed options are ADDCACHE and the parsing and XML parsing options, all in lower case
    • parsing options will only impact string input (URIs, XML strings), because nodes have already been parsed
  • For historical reasons, the order of the 2nd and 3rd argument is different to db:add and db:create
Errorsopen: the addressed database does not exist or could not be opened.
target: the path points to a directory.
Examples
  • db:replace('DB', 'docs/dir/doc.xml', '/home/dir/doc.xml') replaces the content of the document docs/dir/doc.xml in the database DB with the content of the file /home/dir/doc.xml.
  • db:replace('DB', 'docs/dir/doc.xml', '<a/>') replaces the content of the document docs/dir/doc.xml in the database DB with <a/>.
  • db:replace('DB', 'docs/dir/doc.xml', document { <a/> }) replaces the content of the document docs/dir/doc.xml in the database DB with the specified document node.

The following query can be used to import files from a directory to a database:

db:store[edit]

Signaturesdb:store($db as xs:string, $path as xs:string, $input as item()) as empty-sequence()
SummaryReplaces a binary resource specified by $input in the database $db and the location specified by $path, or adds it as new resource.
Errorsopen: the addressed database does not exist or could not be opened.
mainmem: the database is not persistent (stored on disk).
Examples
  • db:store('DB', 'video/sample.mov', file:read-binary('video.mov')) stores the addressed video file at the specified location.
  • With the following query, you can copy full directories:

db:flush[edit]

Signaturesdb:flush($db as xs:string) as empty-sequence()
SummaryExplicitly flushes the buffers of the database $db. This command is only useful if AUTOFLUSH has been set to false.
Errorsopen: the addressed database does not exist or could not be opened.

db:name[edit]

Signaturesdb:name($node as node()) as xs:string
SummaryReturns the name of the database in which the specified database node$node is stored.
Errorsnode: $nodes contains a node which is not stored in a database.

db:path[edit]

Signaturesdb:path($node as node()) as xs:string
SummaryReturns the path of the database document in which the specified database node$node is stored.
Errorsnode: $nodes contains a node which is not stored in a database.

db:exists[edit]

Signaturesdb:exists($db as xs:string) as xs:boolean
db:exists($db as xs:string, $path as xs:string) as xs:boolean
SummaryChecks if the database $db or the resource specified by $path exists. false is returned if a database directory has been addressed.
Examples
  • db:exists('DB') returns true if the database DB exists.
  • db:exists('DB', 'resource') returns true if resource is an XML document or a raw file.

db:is-raw[edit]

Signaturesdb:is-raw($db as xs:string, $path as xs:string) as xs:boolean
SummaryChecks if the specified resource in the database $db and the path $path exists, and if it is a binary resource.
Errorsopen: the addressed database does not exist or could not be opened.
Examples
  • db:is-raw('DB', 'music/01.mp3') returns true.

db:is-xml[edit]

Signaturesdb:is-xml($db as xs:string, $path as xs:string) as xs:boolean
Errorsopen: the addressed database does not exist or could not be opened.
SummaryChecks if the specified resource in the database $db and the path $path exists, and if it is an XML document.
Examples
  • db:is-xml('DB', 'dir/doc.xml') returns true.

db:content-type[edit]

Signaturesdb:content-type($db as xs:string, $path as xs:string) as xs:string
SummaryRetrieves the content type of a resource in the database $db and the path $path.
The file extension is used to recognize the content-type of a resource stored in the database. Content-type application/xml will be returned for any XML document stored in the database, regardless of its file name extension.
Errorsopen: the addressed database does not exist or could not be opened.
Examples
  • db:content-type('DB', 'docs/doc01.pdf') returns application/pdf.
  • db:content-type('DB', 'docs/doc01.xml') returns application/xml.
  • db:content-type('DB', 'docs/doc01') returns application/xml, if db:is-xml('DB', 'docs/doc01') returns true.
CodeDescription
argsThe number of specified inputs and paths differs.
conflictMultiple update operations point to the same target.
lockA database cannot be updated because it is opened by another process.
mainmemThe addressed database is not persistent (stored on disk).
nameThe name of the specified database is invalid.
no-backupNo backup exists for a database.
nodeThe referenced XML node is no database node, i.e. it is neither stored in a database nor represented as database fragment.
no-indexThe database lacks an index structure required by the called function.
openThe addressed database does not exist or could not be opened.
optionThe specified option is unknown.
pathThe specified database path is invalid.
propertyThe specified database property is unknown.
rangeThe addressed database id or pre value is out of range.
targetPath points to an invalid target.
Version 9.3
  • Added: db:alter-backup
  • Updated: db:open-id, db:open-pre: support for multiple integers
Version 9.2
  • Added: db:dir
  • Updated: db:add: $path allow empty path argument
Version 9.0
  • Added: db:option
  • Updated: db:output renamed to update:output, db:output-cache renamed to update:cache
  • Updated: error codes updated; errors now use the module namespace
Version 8.6
  • Added: db:property
Version 8.4
  • Updated: db:create, db:add, db:replace: support for ADDCACHE option.
  • Added: db:token
Version 8.3
  • Updated: db:list-details: attributes with name of database and date of backup added to results.
  • Updated: db:backups now include attributes with name of database and date of backup.
  • Updated: Value Indexes: raise error if no index exists.

Db Text Abbreviation

Version 8.2
  • Added: db:output-cache
  • Removed: db:event
Version 7.9
  • Updated: parsing options added to db:create, db:add and db:replace.
  • Updated: allow UPDINDEX if $all is true.
Version 7.8.2
  • Added: db:alter, db:copy, db:create-backup, db:drop-backup, db:restore
Version 7.8
  • Removed: db:fulltext (use ft:search instead)
Version 7.7
  • Added: db:export, db:name, db:path
  • Updated: $options argument added to db:create and db:optimize.
  • Updated: the functions no longer accept Database Nodes as reference. Instead, the name of a database must now be specified.

Db Textiles Llc

Version 7.6
  • Updated: db:create: allow more than one input and path.

Db/textworks

Version 7.5
  • Updated: db:add: input nodes will be automatically converted to document nodes
  • Added: db:backups
  • Added: db:create
  • Added: db:drop
Version 7.3
  • Added: db:flush
Version 7.2.1
  • Added: db:text-range, db:attribute-range, db:output
Version 7.1
  • Added: db:list-details, db:content-type
  • Updated: db:info, db:system, db:retrieve
Version 7.0

Mongodb Text Search

  • Added: db:retrieve, db:store, db:exists, db:is-raw, db:is-xml
  • Updated: db:list, db:open, db:add

Db Textile Collections Ltd

Retrieved from 'http://docs.basex.org/index.php?title=Database_Module&oldid=15325'