Changes

Jump to navigation Jump to search
1,479 bytes removed ,  17:43, 4 June 2024
no edit summary
This page is part of the [[Getting Started]] Section.BaseX offers a It introduces you to the standalone console command-line mode from which all [[Commands|database commands]] can be executed.The article on the [[Database Server]] provides numerous examples for running commands in the console mode(note that the GUI does ''not'' interact with the client/server architecture)of BaseX.
=Startup=
First of all, please launch a '''standalone''' version of BaseX: double click on the '''BaseX''' icon, or run the <code>basex</code> script. [[Startup#Standalone|Follow this link]] for more information (or check out the additional [[Command-Line Options#Standalone|The command-line options]]).client can be started as follows:
=Create a database=* Run one of the {{Code|basex}} or {{Code|basex.bat}} scripts.* If you have installed BaseX on ''Windows'', click on the '''BaseX Standalone''' icon.
* All operations will be performed with admin permissions (no password needs to be supplied). Various [[Command-Line_Options#Standalone|command-line options]] are available to simplify batch processing. The [[Start_Scripts|start script]] can be adjusted for individual purposes (e.g. if the default memory limit is too restrictive). The standalone client must not be used if you perform parallel (concurrent) read and write operations on your databases. See [[Startup#Concurrent Operations|Concurrent Operations]] for more details. =Operations= ==Create a Database== To create a database , you need an XML document, e.g. , [httphttps://files.basex.org/xml/factbook.xml factbook.xml].* Save this document to your working directory.* Type and type in the following commandto create and open the database:
<code>
> [[Commands#CREATE DB{{Command|CREATE DB]] }} factbook factbook.xml
</code>
: '''factbook.xml''' is the initial input of the database<br/>
If everything works you see the following lines:<pre>Database 'factbook' created in 950.83 ms.</pre> ; Where is the database stored?By default, databases are stored in the <code>BaseXDatabasex/data</code> directory, which is located in of your project’s home folderdirectory.Depending on your [[Configuration]], the location of your home folder variesmay vary. For example, on  ==Execute a Query== The {{Command|XQUERY}} command lets you run a Mac it's <code>/Users/John</code>, if your name is Johnquery. If you have used The following query returns all country elements of the Windows Installer, the directory will be named <code>data</code>, and reside in the application directory.currently opened database:
=Execute a query=
The [[Commands#XQUERY|XQUERY]] command lets you run a query.
* For example, this query returns all country nodes in the currently opened database.
<code>
> [[Commands#XQUERY{{Command|XQUERY]] }} //country
</code>
* You can also run queries in files: 
<code>
> [[Commands#RUN{{Command|RUN]] }} /Userspath/Johnto/query.xq
</code>
=Create a new database=Now we will create another database from the [http://files.basex.org/xml/xmark.xml xmark.xml] document.Database Commands==
* Create The following command lists all databases that can be opened by the new database, named 'xmark'.<code>> [[Commands#CREATE DB|CREATE DB]] xmark xmark.xml</code>currently logged-in user:
* Set the new database xmark as the context:
<code>
> [[Commands#OPEN{{Command|OPEN]] xmarkLIST}}
</code>
* Now you can easily To open an existing database, execute queries on your new databasethe following:<code>> [[Commands#XQUERY|XQUERY]] //people/person/name</code>
=Switch the database=
* You can explicitly query the factbook database with the <code>doc(...)</code> funtion, no matter what the current context is.
<code>
> [[Commands#XQUERY{{Command|XQUERY]] doc("OPEN}} factbook")//country
</code>
* Otherwise, to set factbook as To get information on the current contextcurrently opened database, execute the followingtype:<code>> [[Commands#OPEN|OPEN]] factbook</code>
* The following command lists all databases than can be opened by the currently logged in users:
<code>
> [[Commands#LIST{{Command|LIST]]INFO}}
</code>
=Close or delete You can also address a database=* To [[Commandswithin your query with the {{Function|close]] the current context database, please typeDatabase|db:get}} function: <code>> [[Commands#CLOSE|CLOSE]]</code>
* Use the [[Commands#DROP DB|DROP DB]] command to delete the xmark database:
<code>
> [[Commands#DROP DB{{Command|DROP DB]] xmarkXQUERY}} db:get("factbook")//country
</code>
=Create a collection='''What is a collection?'''With BaseX you can group documents into one logical collection. A collection is a To close the current database that contains two or more documents. Collections accept any , please type of XML documents, regardless of their structure.:
Let's add the xmark.xml document to the factbook database to create a collection. The name of the original factbook database remains.
 
* First make sure factbook is opened:
<code>
> [[Commands#OPEN{{Command|OPEN]] factbookCLOSE}}
</code>
* Now add the xmark.xml documentA database can eventually be dropped again:  
<code>
> [[Commands#ADD{{Command|ADD]] xmark.xmlDROP DB}} factbook
</code>
=Delete a document=* Deleting a document from a collection is easy:<code>> [[Commands#DELETE|DELETE]] xmark.xml</code>Multiple Resources==
Make sure that the collectionOne database can contain not only a single, which contains the '''xmarkbut millions of documents.xml''' document, is openedAll documents can have a different structure.
=Delete a collection=Deleting a collection is With the same as deleting a following commands, you can create an empty databaseand add two documents.It is also possible to address resources via URLs:
* To delete the collection factbook, type:
<code>
> [[Commands#DROP {{Command|CREATE DB}} store</code><br/><code>> {{Command|DROP DB]] ADD}} factbook.xml</code><br/><code>> {{Command|ADD}} http://files.basex.org/xml/xmark.xml
</code>
=Get server information=Several commands help to explore the state of Deleting a server. For document from a complete listdatabase is easy, but make sure that the database, please visit which contains the [[Commands]] Section.addressed document, is currently opened:
* To see all databases on the server, type:
<code>
> [[Commands#LIST{{Command|LIST]]DELETE}} factbook.xml
</code>
* To see the general information of the opened database, type:<code>> [[Commands#INFO|INFO]]</code>==Backup and Restore==
* To list all sessions that are managed by the server instanceback up and restore your database, type:<code>> [[Commands#SHOW USERS|SHOW USERS]]</code>
=Backup and restore=
* To backup your database, type:
<code>
> [[Commands#CREATE BACKUP{{Command|CREATE BACKUP]] }} factbook</code> * To restore your database, type:<br/>
<code>
> [[Commands#RESTORE{{Command|RESTORE]] }} factbook
</code>
'''Where is the backup-file stored?''' The backup-file is stored in the database directory.The file is named It contains the name of the database and a timestamp: <code>factbook[db-timestamp.zip</code> (<code>db_namename]-[timestamp].zip</code>).To restore the If a database is to be restored, and if several backups exist, the file backup with the newest timestamp is taken. [[Category:Beginner]]
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu