]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Writer/ViewDefinitionSqlWriter.php
Changes:
[friendica.git] / src / Util / Writer / ViewDefinitionSqlWriter.php
index 5e6715b6f4f8755e8f6d36e4fcfab41c18f0ff23..429a7dc5cbc4ca3c00ef93535fdc4fee947db4f6 100644 (file)
@@ -23,8 +23,18 @@ namespace Friendica\Util\Writer;
 
 use Friendica\Database\Definition\ViewDefinition;
 
+/**
+ * SQL writer utility for the db view definition
+ */
 class ViewDefinitionSqlWriter
 {
+       /**
+        * Creates a complete SQL definition bases on a give View Definition class
+        *
+        * @param ViewDefinition $definition The View definition class
+        *
+        * @return string The SQL definition as a string
+        */
        public static function create(ViewDefinition $definition): string
        {
                $sqlString = '';
@@ -40,11 +50,26 @@ class ViewDefinitionSqlWriter
                return $sqlString;
        }
 
+       /**
+        * Creates the SQL definition to drop a view
+        *
+        * @param string $viewName the view name
+        *
+        * @return string The SQL definition
+        */
        public static function dropView(string $viewName): string
        {
                return sprintf("DROP VIEW IF EXISTS `%s`", static::escape($viewName)) . ";\n";
        }
 
+       /**
+        * Creates the SQL definition to create a new view
+        *
+        * @param string $viewName      The view name
+        * @param array  $viewStructure The structure information of the view
+        *
+        * @return string The SQL definition
+        */
        public static function createView(string $viewName, array $viewStructure): string
        {
                $sql_rows = [];
@@ -59,6 +84,13 @@ class ViewDefinitionSqlWriter
                           implode(",\n\t", $sql_rows) . "\n\t" . $viewStructure['query'] . ";\n\n";
        }
 
+       /**
+        * Standard escaping for SQL definitions
+        *
+        * @param string $sqlString the SQL string to escape
+        *
+        * @return string escaped SQL string
+        */
        public static function escape(string $sqlString): string
        {
                return str_replace("'", "\\'", $sqlString);