| Total Complexity | 7 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 5 | trait CompilesViews |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Compile the query to create a view. |
||
| 9 | * |
||
| 10 | * @param string $name |
||
| 11 | * @param string $query |
||
| 12 | * @param array|null $columns |
||
| 13 | * @param bool $orReplace |
||
| 14 | * @param bool $materialized |
||
| 15 | * @return string |
||
| 16 | */ |
||
| 17 | public function compileCreateView($name, $query, $columns, $orReplace, bool $materialized = false) |
||
| 18 | { |
||
| 19 | $orReplaceSql = $orReplace ? 'or replace ' : ''; |
||
| 20 | |||
| 21 | $materializedSql = $materialized ? 'materialized ' : ''; |
||
| 22 | |||
| 23 | $columns = $columns ? '('.$this->columnize($columns).') ' : ''; |
||
|
|
|||
| 24 | |||
| 25 | return 'create '.$orReplaceSql.$materializedSql.'view '.$this->wrapTable($name).' '.$columns.'as '.$query; |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Compile the query to drop a view. |
||
| 30 | * |
||
| 31 | * @param string $name |
||
| 32 | * @param bool $ifExists |
||
| 33 | * @return string |
||
| 34 | */ |
||
| 35 | public function compileDropView($name, $ifExists) |
||
| 36 | { |
||
| 37 | $ifExists = $ifExists ? 'if exists ' : ''; |
||
| 38 | |||
| 39 | return 'drop view '.$ifExists.$this->wrapTable($name); |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Compile the query to refresh a materialized view. |
||
| 44 | * |
||
| 45 | * @param string $name |
||
| 46 | * @return string |
||
| 47 | */ |
||
| 48 | public function compileRefreshMaterializedView(string $name): string |
||
| 51 | } |
||
| 52 | } |
||
| 53 |