-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add EXISTS and NOT EXISTS to SELECT queries
- Loading branch information
Showing
4 changed files
with
88 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace RebelCode\Atlas\Expression; | ||
|
||
/** Renders using a callback. */ | ||
class CallbackExpr extends BaseExpr | ||
{ | ||
/** @var callable():string */ | ||
private $callback; | ||
|
||
/** | ||
* Creates a new callback expression. | ||
* @param callable():string $callback A function that renders the expr SQL. | ||
*/ | ||
public function __construct(callable $callback) | ||
{ | ||
$this->callback = $callback; | ||
} | ||
|
||
/** @inheritdoc */ | ||
protected function toBaseString(): string | ||
{ | ||
return call_user_func($this->callback); | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace RebelCode\Atlas\Test\Expression; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use RebelCode\Atlas\Expression\CallbackExpr; | ||
|
||
class CallbackExprTest extends TestCase | ||
{ | ||
public function testRenderClosure() | ||
{ | ||
$closure = new CallbackExpr(function () { | ||
return 'foobar'; | ||
}); | ||
|
||
$this->assertEquals('foobar', $closure->toSql()); | ||
} | ||
|
||
public function testRenderArrowFn() | ||
{ | ||
$var = 'foobar'; | ||
$closure = new CallbackExpr(fn () => $var); | ||
|
||
$this->assertEquals('foobar', $closure->toSql()); | ||
} | ||
} |
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