Finish missing docs for the rest of the database module.

This commit is contained in:
Relintai 2024-04-27 23:03:18 +02:00
parent bef76e4adf
commit 3dfa9bd7e8
8 changed files with 145 additions and 0 deletions

View File

@ -1,20 +1,31 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<class name="Database" inherits="Reference" version="4.4"> <class name="Database" inherits="Reference" version="4.4">
<brief_description> <brief_description>
Represents a database.
</brief_description> </brief_description>
<description> <description>
Represents a database.
Classes inherited from it implement communication with database systems.
See [SQLite3Database] for an example.
Currently only an sqlite backend is available, however communication with other systems (like MySQL, or PostgreSQL) can be implemented without too much hassle using engine modules.
</description> </description>
<tutorials> <tutorials>
<link title="Simple Database Demo Project">https://github.com/Relintai/pandemonium_demo_projects/tree/master/database/database_simple</link>
<link title="Prepared Statement Database Demo Project">https://github.com/Relintai/pandemonium_demo_projects/tree/master/database/prepared_statements</link>
<link title="Web Demo Projects">https://github.com/Relintai/pandemonium_demo_projects/tree/master/web</link>
</tutorials> </tutorials>
<methods> <methods>
<method name="get_connection"> <method name="get_connection">
<return type="DatabaseConnection" /> <return type="DatabaseConnection" />
<description> <description>
Returns a [DatabaseConnection] object which can be used to run queries on the database.
Always get a new one, don't store it, as the database backend might give different ones depending on certain factors (like calling threads) for faster operation.
</description> </description>
</method> </method>
</methods> </methods>
<members> <members>
<member name="connection_string" type="String" setter="set_connection_string" getter="get_connection_string" default="&quot;&quot;"> <member name="connection_string" type="String" setter="set_connection_string" getter="get_connection_string" default="&quot;&quot;">
Connection string used by the backend.
</member> </member>
</members> </members>
<constants> <constants>

View File

@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<class name="DatabaseConnection" inherits="Reference" version="4.4"> <class name="DatabaseConnection" inherits="Reference" version="4.4">
<brief_description> <brief_description>
Represents a connection to a database server.
</brief_description> </brief_description>
<description> <description>
Represents a connection to a database server.
Don't create these directly, use the [code]get_connection()[/code] method in [Database] to get one.
</description> </description>
<tutorials> <tutorials>
</tutorials> </tutorials>
@ -10,56 +13,69 @@
<method name="create_prepared_statement"> <method name="create_prepared_statement">
<return type="PreparedStatement" /> <return type="PreparedStatement" />
<description> <description>
Creates a [PreparedStatement] for use with this database connection.
</description> </description>
</method> </method>
<method name="database_connect"> <method name="database_connect">
<return type="int" enum="Error" /> <return type="int" enum="Error" />
<argument index="0" name="connection_str" type="String" /> <argument index="0" name="connection_str" type="String" />
<description> <description>
Connect to the database. The backend will automatically call this.
</description> </description>
</method> </method>
<method name="ensure_version_table_exists"> <method name="ensure_version_table_exists">
<return type="void" /> <return type="void" />
<description> <description>
Ensures that a table that contains the database's verison exists for compatibility checks.
</description> </description>
</method> </method>
<method name="escape"> <method name="escape">
<return type="String" /> <return type="String" />
<argument index="0" name="str" type="String" /> <argument index="0" name="str" type="String" />
<description> <description>
Escapes the given [String] using the database backend's excape method.
Use it on user input for sanitization.
Note that [QueryBuilder] does this where necessary automatically.
Also note that when using [PreparedStatement]s this is not needed.
</description> </description>
</method> </method>
<method name="get_owner"> <method name="get_owner">
<return type="Database" /> <return type="Database" />
<description> <description>
Returns the owner [Database].
</description> </description>
</method> </method>
<method name="get_query_builder"> <method name="get_query_builder">
<return type="QueryBuilder" /> <return type="QueryBuilder" />
<description> <description>
Returns a new [QueryBuilder] that is properly set up for this connection.
</description> </description>
</method> </method>
<method name="get_table_builder"> <method name="get_table_builder">
<return type="TableBuilder" /> <return type="TableBuilder" />
<description> <description>
Returns a new [TableBuilder] that is properly set up for this connection.
</description> </description>
</method> </method>
<method name="get_table_version"> <method name="get_table_version">
<return type="int" /> <return type="int" />
<argument index="0" name="table" type="String" /> <argument index="0" name="table" type="String" />
<description> <description>
Returns the current table version. This can be used to determine database compatibility, or for example whether to run migrations or not during startup.
</description> </description>
</method> </method>
<method name="query"> <method name="query">
<return type="QueryResult" /> <return type="QueryResult" />
<argument index="0" name="query" type="String" /> <argument index="0" name="query" type="String" />
<description> <description>
Run a query. Use the resulting[QueryResult] object to read data from the database.
</description> </description>
</method> </method>
<method name="query_run"> <method name="query_run">
<return type="void" /> <return type="void" />
<argument index="0" name="query" type="String" /> <argument index="0" name="query" type="String" />
<description> <description>
Run a query.
</description> </description>
</method> </method>
<method name="set_table_version"> <method name="set_table_version">
@ -67,6 +83,7 @@
<argument index="0" name="table" type="String" /> <argument index="0" name="table" type="String" />
<argument index="1" name="version" type="int" /> <argument index="1" name="version" type="int" />
<description> <description>
Sets the current table version.
</description> </description>
</method> </method>
</methods> </methods>

View File

@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<class name="DatabaseManager" inherits="Object" version="4.4"> <class name="DatabaseManager" inherits="Object" version="4.4">
<brief_description> <brief_description>
Database Manager Singleton.
</brief_description> </brief_description>
<description> <description>
Database Manager Singleton.
Stores database connections that need to be accessible throughout the application.
</description> </description>
<tutorials> <tutorials>
</tutorials> </tutorials>
@ -12,32 +15,38 @@
<argument index="0" name="db" type="Database" /> <argument index="0" name="db" type="Database" />
<argument index="1" name="set_as_default" type="bool" default="true" /> <argument index="1" name="set_as_default" type="bool" default="true" />
<description> <description>
Add a Database. If [code]set_as_default[/code] is true it will be set as default, which means it will be set to the [member ddb] property.
</description> </description>
</method> </method>
<method name="get_database"> <method name="get_database">
<return type="Database" /> <return type="Database" />
<argument index="0" name="index" type="int" /> <argument index="0" name="index" type="int" />
<description> <description>
Returns a Database.
</description> </description>
</method> </method>
<method name="get_database_count"> <method name="get_database_count">
<return type="int" /> <return type="int" />
<description> <description>
Returns how many databases are stored in the singleton.
</description> </description>
</method> </method>
<method name="get_databases"> <method name="get_databases">
<return type="Array" /> <return type="Array" />
<description> <description>
Returns all Databases.
</description> </description>
</method> </method>
<method name="initialized"> <method name="initialized">
<return type="void" /> <return type="void" />
<description> <description>
Calls the [code]initialized[/code] signal.
</description> </description>
</method> </method>
<method name="load"> <method name="load">
<return type="void" /> <return type="void" />
<description> <description>
Not implemented currently. Will likely load databases from ProjectSettings.
</description> </description>
</method> </method>
<method name="migrate"> <method name="migrate">
@ -46,6 +55,7 @@
<argument index="1" name="should_seed" type="bool" /> <argument index="1" name="should_seed" type="bool" />
<argument index="2" name="pseed" type="int" /> <argument index="2" name="pseed" type="int" />
<description> <description>
Calls the [member migration] signal.
</description> </description>
</method> </method>
<method name="remove_database"> <method name="remove_database">
@ -53,31 +63,37 @@
<argument index="0" name="index" type="int" /> <argument index="0" name="index" type="int" />
<argument index="1" name="unset_if_default" type="bool" default="true" /> <argument index="1" name="unset_if_default" type="bool" default="true" />
<description> <description>
Removes a Database.
</description> </description>
</method> </method>
</methods> </methods>
<members> <members>
<member name="ddb" type="Database" setter="set_ddb" getter="get_ddb"> <member name="ddb" type="Database" setter="set_ddb" getter="get_ddb">
The default database.
</member> </member>
</members> </members>
<signals> <signals>
<signal name="database_added"> <signal name="database_added">
<argument index="0" name="db" type="Database" /> <argument index="0" name="db" type="Database" />
<description> <description>
Emitted when a [Database] is added.
</description> </description>
</signal> </signal>
<signal name="database_removed"> <signal name="database_removed">
<argument index="0" name="db" type="Database" /> <argument index="0" name="db" type="Database" />
<description> <description>
Emitted when a [Database] is removed.
</description> </description>
</signal> </signal>
<signal name="default_database_changed"> <signal name="default_database_changed">
<argument index="0" name="db" type="Database" /> <argument index="0" name="db" type="Database" />
<description> <description>
Emitted when default database is changed.
</description> </description>
</signal> </signal>
<signal name="initialized"> <signal name="initialized">
<description> <description>
Can be emitted using the [member initialized] method after the database connections are set up.
</description> </description>
</signal> </signal>
<signal name="migration"> <signal name="migration">
@ -85,6 +101,7 @@
<argument index="1" name="should_seed" type="bool" /> <argument index="1" name="should_seed" type="bool" />
<argument index="2" name="pseed" type="int" /> <argument index="2" name="pseed" type="int" />
<description> <description>
Can be emitted using the [member migrate] method when the databse structure needs to be updated (or created).
</description> </description>
</signal> </signal>
</signals> </signals>

View File

@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<class name="DatabaseMultiThreaded" inherits="Database" version="4.4"> <class name="DatabaseMultiThreaded" inherits="Database" version="4.4">
<brief_description> <brief_description>
Contains helper methods for multi threaded database systems on the c++ side. Don't use it directly.
</brief_description> </brief_description>
<description> <description>
Contains helper methods for multi threaded database systems on the c++ side. Don't use it directly.
</description> </description>
<tutorials> <tutorials>
</tutorials> </tutorials>

View File

@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<class name="DatabaseSingleThreaded" inherits="Database" version="4.4"> <class name="DatabaseSingleThreaded" inherits="Database" version="4.4">
<brief_description> <brief_description>
Contains helper methods for single threaded database systems on the c++ side.
</brief_description> </brief_description>
<description> <description>
Contains helper methods for single threaded database systems on the c++ side.
</description> </description>
<tutorials> <tutorials>
</tutorials> </tutorials>

View File

@ -390,18 +390,36 @@
<method name="psph"> <method name="psph">
<return type="QueryBuilder" /> <return type="QueryBuilder" />
<description> <description>
Adds a placeholder for prepared statements statement. (psph = Prepared Statement PlaceHolder)
Equivalent to:
[codeblock]
result += "?";
[/codeblock]
</description> </description>
</method> </method>
<method name="psphi"> <method name="psphi">
<return type="QueryBuilder" /> <return type="QueryBuilder" />
<argument index="0" name="id" type="String" /> <argument index="0" name="id" type="String" />
<description> <description>
Adds a placeholder with id for prepared statements statement.
Equivalent to:
[codeblock]
if (id.is_valid_unsigned_integer()):
result += "?" + id;
else:
result += ":" + id;
[/codeblock]
</description> </description>
</method> </method>
<method name="psphr"> <method name="psphr">
<return type="QueryBuilder" /> <return type="QueryBuilder" />
<argument index="0" name="raw_id" type="String" /> <argument index="0" name="raw_id" type="String" />
<description> <description>
Adds a raw placeholder for prepared statements statement.
Equivalent to:
[codeblock]
result += raw_id;
[/codeblock]
</description> </description>
</method> </method>
<method name="reset"> <method name="reset">
@ -484,6 +502,14 @@
<return type="QueryBuilder" /> <return type="QueryBuilder" />
<argument index="0" name="col" type="String" /> <argument index="0" name="col" type="String" />
<description> <description>
Add a prepared statement placeholder parameter to [code]UPDATE[/code] statements.
Equivalent to:
[codeblock]
result += col;
result += "=";
psph();
result += ", ";
[/codeblock]
</description> </description>
</method> </method>
<method name="setphi"> <method name="setphi">
@ -491,6 +517,14 @@
<argument index="0" name="col" type="String" /> <argument index="0" name="col" type="String" />
<argument index="1" name="id" type="String" /> <argument index="1" name="id" type="String" />
<description> <description>
Add a prepared statement with id placeholder parameter to [code]UPDATE[/code] statements.
Equivalent to:
[codeblock]
result += col;
result += "=";
psphi(id);
result += ", ";
[/codeblock]
</description> </description>
</method> </method>
<method name="setphr"> <method name="setphr">
@ -498,6 +532,14 @@
<argument index="0" name="col" type="String" /> <argument index="0" name="col" type="String" />
<argument index="1" name="raw_id" type="String" /> <argument index="1" name="raw_id" type="String" />
<description> <description>
Add a raw prepared statement placeholder parameter to [code]UPDATE[/code] statements.
Equivalent to:
[codeblock]
result += col;
result += "=";
psphr(raw_id);
result += ", ";
[/codeblock]
</description> </description>
</method> </method>
<method name="setpi"> <method name="setpi">
@ -611,18 +653,36 @@
<method name="valph"> <method name="valph">
<return type="QueryBuilder" /> <return type="QueryBuilder" />
<description> <description>
Add a prepared statement placeholder parameter to a [code]VALUES[/code] statement.
Equivalent to:
[codeblock]
psph();
result += ", ";
[/codeblock]
</description> </description>
</method> </method>
<method name="valphi"> <method name="valphi">
<return type="QueryBuilder" /> <return type="QueryBuilder" />
<argument index="0" name="id" type="String" /> <argument index="0" name="id" type="String" />
<description> <description>
Add a prepared statement with id placeholder parameter to a [code]VALUES[/code] statement.
Equivalent to:
[codeblock]
psphi(id);
result += ", ";
[/codeblock]
</description> </description>
</method> </method>
<method name="valphr"> <method name="valphr">
<return type="QueryBuilder" /> <return type="QueryBuilder" />
<argument index="0" name="raw_id" type="String" /> <argument index="0" name="raw_id" type="String" />
<description> <description>
Add a raw prepared statement placeholder parameter to a [code]VALUES[/code] statement.
Equivalent to:
[codeblock]
psphi(raw_id);
result += ", ";
[/codeblock]
</description> </description>
</method> </method>
<method name="vals"> <method name="vals">
@ -700,6 +760,14 @@
<return type="QueryBuilder" /> <return type="QueryBuilder" />
<argument index="0" name="col" type="String" /> <argument index="0" name="col" type="String" />
<description> <description>
Add a prepared statement placeholder parameter to a [code]WHERE[/code] statement. (wpb = where param bool)
Equivalent to:
[codeblock]
result += col;
result += "=";
psph();
result += " ";
[/codeblock]
</description> </description>
</method> </method>
<method name="wphi"> <method name="wphi">
@ -707,6 +775,14 @@
<argument index="0" name="col" type="String" /> <argument index="0" name="col" type="String" />
<argument index="1" name="id" type="String" /> <argument index="1" name="id" type="String" />
<description> <description>
Add a prepared statement with id placeholder parameter to a [code]WHERE[/code] statement. (wpb = where param bool)
Equivalent to:
[codeblock]
result += col;
result += "=";
psphi(id);
result += " ";
[/codeblock]
</description> </description>
</method> </method>
<method name="wphr"> <method name="wphr">
@ -714,6 +790,14 @@
<argument index="0" name="col" type="String" /> <argument index="0" name="col" type="String" />
<argument index="1" name="raw_id" type="String" /> <argument index="1" name="raw_id" type="String" />
<description> <description>
Add a raw prepared statement placeholder parameter to a [code]WHERE[/code] statement. (wpb = where param bool)
Equivalent to:
[codeblock]
result += col;
result += "=";
psphr(raw_id);
result += " ";
[/codeblock]
</description> </description>
</method> </method>
<method name="wpi"> <method name="wpi">

View File

@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<class name="QueryResult" inherits="Reference" version="4.4"> <class name="QueryResult" inherits="Reference" version="4.4">
<brief_description> <brief_description>
Read the result from a query that were run on a [Database].
</brief_description> </brief_description>
<description> <description>
Read the result from a query that were run on a [Database].
</description> </description>
<tutorials> <tutorials>
</tutorials> </tutorials>
@ -11,51 +13,60 @@
<return type="String" /> <return type="String" />
<argument index="0" name="index" type="int" /> <argument index="0" name="index" type="int" />
<description> <description>
Gets a [String] value from the index-th cell.
</description> </description>
</method> </method>
<method name="get_cell_bool"> <method name="get_cell_bool">
<return type="bool" /> <return type="bool" />
<argument index="0" name="index" type="int" /> <argument index="0" name="index" type="int" />
<description> <description>
Gets a bool value from the index-th cell.
</description> </description>
</method> </method>
<method name="get_cell_double"> <method name="get_cell_double">
<return type="float" /> <return type="float" />
<argument index="0" name="index" type="int" /> <argument index="0" name="index" type="int" />
<description> <description>
Gets a double value from the index-th cell.
</description> </description>
</method> </method>
<method name="get_cell_float"> <method name="get_cell_float">
<return type="float" /> <return type="float" />
<argument index="0" name="index" type="int" /> <argument index="0" name="index" type="int" />
<description> <description>
Gets a float value from the index-th cell.
</description> </description>
</method> </method>
<method name="get_cell_int"> <method name="get_cell_int">
<return type="int" /> <return type="int" />
<argument index="0" name="index" type="int" /> <argument index="0" name="index" type="int" />
<description> <description>
Gets a int value from the index-th cell.
</description> </description>
</method> </method>
<method name="get_error_message"> <method name="get_error_message">
<return type="String" /> <return type="String" />
<description> <description>
Returns the current error message (if any).
</description> </description>
</method> </method>
<method name="get_last_insert_rowid"> <method name="get_last_insert_rowid">
<return type="int" /> <return type="int" />
<description> <description>
Returns the last inserted row's id. On some database backends this needs to be requested in the query to be available.
</description> </description>
</method> </method>
<method name="is_cell_null"> <method name="is_cell_null">
<return type="bool" /> <return type="bool" />
<argument index="0" name="index" type="int" /> <argument index="0" name="index" type="int" />
<description> <description>
Is the given cell null.
</description> </description>
</method> </method>
<method name="next_row"> <method name="next_row">
<return type="bool" /> <return type="bool" />
<description> <description>
Read the next row. Returns true if success, false if no more rows available.
</description> </description>
</method> </method>
</methods> </methods>

View File

@ -204,6 +204,7 @@
<method name="reset"> <method name="reset">
<return type="void" /> <return type="void" />
<description> <description>
Resets the result.
</description> </description>
</method> </method>
<method name="run"> <method name="run">