Changes

Jump to navigation Jump to search
240 bytes added ,  15:32, 10 April 2019
no edit summary
This page is part of the [[Getting Started]] Section.
In BaseX, a ''database'' is a pretty light-weight concept. It contains an arbitrary number of may contain one or more '''resources''', which are addressed by a unique database path. There is no explicit layer for collections. : Instead, collections are implicitly created and deleted once you add , and remove resources to a databasecollections result from the existence of documents in specific paths. Resources can either be '''XML documents''' or '''raw files''' (binaries). Some information on [[Binary Data|binary data]] can be found on an extra page. Multiple databases can be addressed (queries, updated) with a single XQuery expression. As a single database is restricted to 2 billion nodes (see [[Statistics]]), resources can be distributed across multiple database instances.
=Create Databases=
New databases Databases can be created via commands, via XQuery, in the GUI, or with any of our [[Developing|APIs]]. If an initial input is specified with create, some time can be saved, as it the specified resources will be added to the database in a bulk operation:
* [[Startup#BaseX Standalone|Console]]: <code>CREATE DB db /path/to/resources</code> will add initial documents to a database
* [[Startup#BaseX GUI|GUI]]: Go to ''Database'' → ''New'', press ''Browse'' to choose an initial file or directory, and press ''OK''
Database must follow the The name of a database is restricted to a restricted set of characters (see [[Valid Names|valid names constraints]]). Various [[parsers]] can be chosen to influence control the database creationimport process, or to convert different formats to XML.
'''Note:''' A main-memory database will be created if the {{Option|MAINMEM}} option is enabled ([[Databases#In Memory Database|see below]] for more).
</pre>
If the [[Options#DEFAULTDB{{Option|DEFAULTDB]] }} option is turned on, the path argument of the {{Code|fn:doc}} or {{Code|fn:collection}} function will first be resolved against the globally opened database.
Two more functions are available for retrieving information on database nodes:
* {{Code|doc("http://web.de")}}: retrieves the addressed URI and returns it as a main-memory document node.
* {{Code|doc("myfile.xml")}}: retrieves the given file from the file system and returns it as a main-memory document node. Note that updates to main-memory nodes are not automatically written back to disk unless the <code>[[Options#WRITEBACK{{Option|WRITEBACK]]</code> }} option is set.
* {{Code|collection("/path/to/docs")}}: returns a main-memory collection with all XML documents found at the addressed file path.
* Resources can be deleted via <code>[[Commands#DELETE|DELETE]]</code>.
The [[Options#AUTOFLUSH{{Option|AUTOFLUSH]] }} option can be turned off before ''bulk operations'' (i.e. before a large number of new resources is added to the database).
The [[Options#ADDCACHEIf {{Option|ADDCACHE]] option will first cache }} is enabled, the input will be cached before adding it is added to the database. This is helpful when the input documents to be added are expected to eat up consume too much main memory.
The following commands create an empty database, add two resources, explicitly flush data structures to disk, and finally delete all inserted data:
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu