-
Notifications
You must be signed in to change notification settings - Fork 144
Support for expressions #101
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
Changes from all commits
f5820dc
c0b5955
b46fd48
e4bc57a
2927397
7336cad
57d01c5
9d22259
41d9979
a46a60c
2d26997
45da49f
7e25e5f
9662a7c
da54872
c08cf6a
751a501
6f2259f
a68e3e0
c7944e4
c4aa709
b3c340f
72b7574
80d4196
11eb84a
4d8b339
7c14c60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ClickHouseDB\Query; | ||
|
||
/** | ||
* Pass expression "as is" to be sent and executed at server. | ||
* P.ex.: `new Expression("UUIDStringToNum('0f372656-6a5b-4727-a4c4-f6357775d926')");` | ||
*/ | ||
class Expression | ||
{ | ||
/** @var string */ | ||
private $expression; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One more thing is on my mind. This Expression you introduced could easily replace my Type I introduced here #94. If My intention was to use it like this
but now it could be replaced with
for lower numbers eg. My main point is, why to limit the expression only for strings? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was different intention and reasoning for While There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kk, let's just leave it like it is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, maybe, $value = ValueFormatter::formatValue($value, false);
if (is_float($value) || is_int($value)) {
return (string) $value;
}
if (is_string($value) && $encode) { if you want There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right it might need some tweak in that part of code. But see this line https://github.com/smi2/phpClickHouse/blob/master/src/Quote/StrictQuoteLine.php#L74 If replaced by BTW I'd definitely be for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, missed that one. So it should be something like this IMO: if ($value instanceof NumericType) {
$encode = $value->doQuoting();
} But in this case abstract class AND interface required. Abstract is required to define default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I'd name it something like |
||
|
||
public function __construct(string $expression) | ||
{ | ||
$this->expression = $expression; | ||
} | ||
|
||
public function __toString() : string | ||
{ | ||
return $this->expression; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ClickHouseDB\Tests\Query; | ||
|
||
use ClickHouseDB\Query\Expression; | ||
use ClickHouseDB\Quote\FormatLine; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class ExpressionTest extends TestCase | ||
{ | ||
public function testToString() : void | ||
{ | ||
$expressionString = "UUIDStringToNum('0f372656-6a5b-4727-a4c4-f6357775d926')"; | ||
$expressionObject = new Expression($expressionString); | ||
|
||
self::assertEquals( | ||
$expressionString, | ||
(string) $expressionObject | ||
); | ||
} | ||
|
||
public function testExpressionValueForInsert() : void | ||
{ | ||
$expressionString = "UUIDStringToNum('0f372656-6a5b-4727-a4c4-f6357775d926')"; | ||
$preparedValue = FormatLine::Insert([new Expression($expressionString)]); | ||
|
||
self::assertEquals( | ||
$expressionString, | ||
$preparedValue | ||
); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.