-
-
Notifications
You must be signed in to change notification settings - Fork 137
Support limits #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Support limits #180
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fd5c757
add limit
parkourben99 3564519
add serializable closures
parkourben99 4476f2d
just overwrite compileRowNumber method
parkourben99 adab720
update to include more grammars
parkourben99 a231cde
make styleci happy
parkourben99 c3a1f83
or version 2
parkourben99 b72920b
update test and required composer packages
parkourben99 94f62e1
typo
parkourben99 8cdfad5
Fix grammar instantiation
chrispappas 3c192d5
Use switch rather than match for BC to php 7.x
chrispappas 288c414
Replace fn with function for closures (PHP <= 7.3)
chrispappas 2b8d689
Replace fn with function for closures (PHP <= 7.3)
chrispappas 78c5861
Merge pull request #1 from chrispappas/master
parkourben99 5bd23f2
make the linter happy
parkourben99 6528f25
Merge remote-tracking branch 'origin/master'
parkourben99 06ad732
add maria db support
parkourben99 31ba638
fix tests
parkourben99 26e0a2a
phpunit
parkourben99 311e6bd
Merge pull request #2 from parkourben99/b
parkourben99 92c24eb
Update composer.json
parkourben99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,21 @@ | ||
| <?php | ||
|
|
||
| namespace Awobaz\Compoships\Database\Grammar\Concerns; | ||
|
|
||
| trait CompileRowNumber | ||
| { | ||
| protected function compileRowNumber($partition, $orders) | ||
| { | ||
| if (!is_array($partition)) { | ||
| return parent::compileRowNumber($partition, $orders); | ||
| } | ||
|
|
||
| $columns = implode(', ', array_map(function ($p) { | ||
| return $this->wrap($p); | ||
| }, $partition)); | ||
|
|
||
| $over = trim('partition by '.$columns.' '.$orders); | ||
|
|
||
| return ', row_number() over ('.$over.') as '.$this->wrap('laravel_row'); | ||
| } | ||
| } |
This file contains hidden or 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,11 @@ | ||
| <?php | ||
|
|
||
| namespace Awobaz\Compoships\Database\Grammar; | ||
|
|
||
| use Awobaz\Compoships\Database\Grammar\Concerns\CompileRowNumber; | ||
| use Illuminate\Database\Query\Grammars\MariaDbGrammar as BaseMySqlGrammar; | ||
|
|
||
| class MariaDbGrammar extends BaseMySqlGrammar | ||
| { | ||
| use CompileRowNumber; | ||
| } |
This file contains hidden or 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,11 @@ | ||
| <?php | ||
|
|
||
| namespace Awobaz\Compoships\Database\Grammar; | ||
|
|
||
| use Awobaz\Compoships\Database\Grammar\Concerns\CompileRowNumber; | ||
| use Illuminate\Database\Query\Grammars\MySqlGrammar as BaseMySqlGrammar; | ||
|
|
||
| class MySqlGrammar extends BaseMySqlGrammar | ||
| { | ||
| use CompileRowNumber; | ||
| } |
This file contains hidden or 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,11 @@ | ||
| <?php | ||
|
|
||
| namespace Awobaz\Compoships\Database\Grammar; | ||
|
|
||
| use Awobaz\Compoships\Database\Grammar\Concerns\CompileRowNumber; | ||
| use Illuminate\Database\Query\Grammars\PostgresGrammar as BasePostgresGrammar; | ||
|
|
||
| class PostgresGrammar extends BasePostgresGrammar | ||
| { | ||
| use CompileRowNumber; | ||
| } |
This file contains hidden or 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,11 @@ | ||
| <?php | ||
|
|
||
| namespace Awobaz\Compoships\Database\Grammar; | ||
|
|
||
| use Awobaz\Compoships\Database\Grammar\Concerns\CompileRowNumber; | ||
| use Illuminate\Database\Query\Grammars\SQLiteGrammar as BaseSQLiteGrammar; | ||
|
|
||
| class SQLiteGrammar extends BaseSQLiteGrammar | ||
| { | ||
| use CompileRowNumber; | ||
| } |
This file contains hidden or 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,11 @@ | ||
| <?php | ||
|
|
||
| namespace Awobaz\Compoships\Database\Grammar; | ||
|
|
||
| use Awobaz\Compoships\Database\Grammar\Concerns\CompileRowNumber; | ||
| use Illuminate\Database\Query\Grammars\SqlServerGrammar as BaseSqlServerGrammar; | ||
|
|
||
| class SqlServerGrammar extends BaseSqlServerGrammar | ||
| { | ||
| use CompileRowNumber; | ||
| } |
This file contains hidden or 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,51 @@ | ||
| <?php | ||
|
|
||
| namespace Awobaz\Compoships\Tests\Unit; | ||
|
|
||
| use Awobaz\Compoships\Tests\Models\User; | ||
| use Awobaz\Compoships\Tests\TestCase\TestCase; | ||
| use Illuminate\Database\Eloquent\Model; | ||
|
|
||
| class LimitTest extends TestCase | ||
| { | ||
| /** | ||
| * @covers \Awobaz\Compoships\Database\Grammar\MySqlGrammar | ||
| */ | ||
| public function test_relation_limit() | ||
| { | ||
| if (getLaravelVersion() < 11.0) { | ||
| $this->markTestIncomplete('This test will not work on laravel 10.x or earlier.'); | ||
| } | ||
|
|
||
| Model::unguard(); | ||
|
|
||
| $user = User::create([ | ||
| 'booking_id' => '123', | ||
| ]); | ||
|
|
||
| for ($i = 0; $i < 5; $i++) { | ||
| $user->allocations()->create([ | ||
| 'booking_id' => '123', | ||
| ]); | ||
| } | ||
|
|
||
| $allocations = $user->allocations()->get(); | ||
| $this->assertCount(5, $allocations); | ||
|
|
||
| $user = $user->fresh(); | ||
| $user->load([ | ||
| 'allocations' => function ($query) { | ||
| $query->limit(4); | ||
| }, | ||
| ]); | ||
| $this->assertCount(4, $user->allocations); | ||
|
|
||
| $user = $user->fresh(); | ||
| $user->load([ | ||
| 'allocations' => function ($query) { | ||
| $query->limit(2); | ||
| }, | ||
| ]); | ||
| $this->assertCount(2, $user->allocations); | ||
| } | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.