-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve depthFirst() with integer keys
Co-authored-by: Amir Rami <[email protected]>
- Loading branch information
1 parent
747c034
commit 1e27800
Showing
13 changed files
with
212 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Staudenmeir\LaravelAdjacencyList\Query\Grammars; | ||
|
||
class MariaDbGrammar extends MySqlGrammar | ||
{ | ||
/** | ||
* Compile an "order by path" clause. | ||
* | ||
* @return string | ||
*/ | ||
public function compileOrderByPath() | ||
{ | ||
$column = $this->model->getLocalKeyName(); | ||
|
||
$path = $this->wrap( | ||
$this->model->getPathName() | ||
); | ||
|
||
$pathSeparator = $this->model->getPathSeparator(); | ||
|
||
if (!$this->model->isIntegerAttribute($column)) { | ||
return "$path asc"; | ||
} | ||
|
||
return <<<SQL | ||
regexp_replace( | ||
regexp_replace( | ||
$path, | ||
'(^|[$pathSeparator])(\\\\d+)', | ||
'\\\\100000000000000000000\\\\2' | ||
), | ||
'0+(\\\\d\{20\})([$pathSeparator]|$)', | ||
'\\\\1\\\\2' | ||
) asc | ||
SQL; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Staudenmeir\LaravelAdjacencyList\Query\Grammars; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
trait OrdersByPath | ||
{ | ||
protected $model; | ||
|
||
public function __construct(Model $model) | ||
{ | ||
$this->model = $model; | ||
} | ||
|
||
/** | ||
* Compile an "order by path" clause. | ||
* | ||
* @return string | ||
*/ | ||
public function compileOrderByPath() | ||
{ | ||
$path = $this->model->getPathName(); | ||
|
||
return $this->wrap($path) . ' asc'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Tests\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Staudenmeir\LaravelAdjacencyList\Eloquent\HasRecursiveRelationships; | ||
|
||
class Category extends Model | ||
{ | ||
use HasRecursiveRelationships; | ||
|
||
public $incrementing = false; | ||
|
||
protected $keyType = 'string'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters