Improved definition style
This commit is contained in:
parent
63ebbb8a16
commit
c3aa2730de
2 changed files with 12 additions and 9 deletions
|
@ -109,7 +109,11 @@ class DBView
|
||||||
|
|
||||||
$sql_rows = [];
|
$sql_rows = [];
|
||||||
foreach ($structure["fields"] AS $fieldname => $origin) {
|
foreach ($structure["fields"] AS $fieldname => $origin) {
|
||||||
$sql_rows[] = $origin . " AS `" . DBA::escape($fieldname) . "`";
|
if (is_string($origin)) {
|
||||||
|
$sql_rows[] = $origin . " AS `" . DBA::escape($fieldname) . "`";
|
||||||
|
} elseif (is_array($origin) && (sizeof($origin) == 2)) {
|
||||||
|
$sql_rows[] = "`" . DBA::escape($origin[0]) . "`.`" . DBA::escape($origin[1]) . "` AS `" . DBA::escape($fieldname) . "`";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = sprintf("DROP VIEW IF EXISTS `%s`", DBA::escape($name));
|
$sql = sprintf("DROP VIEW IF EXISTS `%s`", DBA::escape($name));
|
||||||
|
|
|
@ -24,8 +24,7 @@
|
||||||
* Syntax (braces indicate optionale values):
|
* Syntax (braces indicate optionale values):
|
||||||
* "<view name>" => [
|
* "<view name>" => [
|
||||||
* "fields" => [
|
* "fields" => [
|
||||||
* "<field name>" => "`table`.`field`",
|
* "<field name>" => ["table", "field"],
|
||||||
* "<field name>" => "`other-table`.`field`",
|
|
||||||
* "<field name>" => "SQL expression",
|
* "<field name>" => "SQL expression",
|
||||||
* ...
|
* ...
|
||||||
* ],
|
* ],
|
||||||
|
@ -39,12 +38,12 @@
|
||||||
|
|
||||||
return [
|
return [
|
||||||
"tag-view" => [
|
"tag-view" => [
|
||||||
"fields" => ["uri-id" => "`post-tag`.`uri-id`",
|
"fields" => ["uri-id" => ["post-tag", "uri-id"],
|
||||||
"uri" => "`item-uri`.`uri`",
|
"uri" => ["item-uri", "uri"],
|
||||||
"guid" => "`item-uri`.`guid`",
|
"guid" => ["item-uri", "guid"],
|
||||||
"type" => "`post-tag`.`type`",
|
"type" => ["post-tag", "type"],
|
||||||
"tid" => "`post-tag`.`tid`",
|
"tid" => ["post-tag", "tid"],
|
||||||
"cid" => "`post-tag`.`cid`",
|
"cid" => ["post-tag", "cid"],
|
||||||
"name" => "CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END",
|
"name" => "CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END",
|
||||||
"url" => "CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END"],
|
"url" => "CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END"],
|
||||||
"query" => "FROM `post-tag`
|
"query" => "FROM `post-tag`
|
||||||
|
|
Loading…
Reference in a new issue