1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Staudenmeir\LaravelAdjacencyList\Query\Grammars; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Query\Builder; |
6
|
|
|
use Illuminate\Database\Query\Grammars\PostgresGrammar as Base; |
7
|
|
|
|
8
|
|
|
class PostgresGrammar extends Base implements ExpressionGrammar |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Compile an initial path. |
12
|
|
|
* |
13
|
|
|
* @param string $column |
14
|
|
|
* @param string $alias |
15
|
|
|
* @return string |
16
|
|
|
*/ |
17
|
49 |
|
public function compileInitialPath($column, $alias) |
18
|
|
|
{ |
19
|
49 |
|
return 'array[('.$this->wrap($column)." || '')::varchar] as ".$this->wrap($alias); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Compile a recursive path. |
24
|
|
|
* |
25
|
|
|
* @param string $column |
26
|
|
|
* @param string $alias |
27
|
|
|
* @return string |
28
|
|
|
*/ |
29
|
49 |
|
public function compileRecursivePath($column, $alias) |
30
|
|
|
{ |
31
|
49 |
|
return $this->wrap($alias).' || '.$this->wrap($column).'::varchar'; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Get the recursive path bindings. |
36
|
|
|
* |
37
|
|
|
* @param string $separator |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
49 |
|
public function getRecursivePathBindings($separator) |
41
|
|
|
{ |
42
|
49 |
|
return []; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Select a concatenated list of paths. |
47
|
|
|
* |
48
|
|
|
* @param \Illuminate\Database\Query\Builder $query |
49
|
|
|
* @param string $expression |
50
|
|
|
* @param string $column |
51
|
|
|
* @param string $pathSeparator |
52
|
|
|
* @param string $listSeparator |
53
|
|
|
* @return \Illuminate\Database\Query\Builder |
54
|
|
|
*/ |
55
|
4 |
|
public function selectPathList(Builder $query, $expression, $column, $pathSeparator, $listSeparator) |
56
|
|
|
{ |
57
|
4 |
|
return $query->selectRaw( |
58
|
4 |
|
'string_agg(array_to_string('.$this->wrap($column).', ?), ?)', |
59
|
4 |
|
[$pathSeparator, $listSeparator] |
60
|
4 |
|
)->from($expression); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|