Total Complexity | 8 |
Total Lines | 56 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
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 | 40 | */ |
|
17 | public function compileCreateView($name, $query, $columns, $orReplace, bool $materialized = false) |
||
18 | 40 | { |
|
19 | $orReplaceSql = $orReplace ? 'or replace ' : ''; |
||
20 | 40 | ||
21 | $materializedSql = $materialized ? 'materialized ' : ''; |
||
22 | 40 | ||
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 | 33 | * @param bool $ifExists |
|
33 | * @return string |
||
34 | 33 | */ |
|
35 | public function compileDropView($name, $ifExists) |
||
36 | 33 | { |
|
37 | $ifExists = $ifExists ? 'if exists ' : ''; |
||
38 | |||
39 | return 'drop view '.$ifExists.$this->wrapTable($name); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Compile the query to determine if a view exists. |
||
44 | 6 | * |
|
45 | * @return string |
||
46 | 6 | */ |
|
47 | public function compileViewExists() |
||
48 | { |
||
49 | return 'select * from information_schema.views where table_schema = ? and table_name = ?'; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Compile the query to refresh a materialized view. |
||
54 | * |
||
55 | * @param string $name |
||
56 | * @return string |
||
57 | */ |
||
58 | public function compileRefreshMaterializedView(string $name): string |
||
61 | } |
||
62 | } |
||
63 |