Skip to content

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

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f5820dc
Added Expression.
dorantor Oct 10, 2017
c0b5955
Merge branch 'master' of github.com:smi2/phpClickHouse
dorantor Mar 13, 2018
b46fd48
Merge branch 'master' into fork
dorantor Mar 13, 2018
e4bc57a
Merge tag '1.3.1' into merge
dorantor Oct 17, 2018
2927397
Shortened fully qualified name.
dorantor Oct 17, 2018
7336cad
Updated docblocks, made internal field private, added typehint.
dorantor Oct 17, 2018
57d01c5
Update src/Query/Expression.php
simPod Oct 18, 2018
9d22259
Updated docblocks and added typehint.
dorantor Oct 18, 2018
41d9979
Merge branch 'merge' of github.com:dorantor/phpClickHouse into merge
dorantor Oct 18, 2018
a46a60c
Replaced field multiline docblock with oneliner.
dorantor Oct 18, 2018
2d26997
Removed expr() method from Client.
dorantor Oct 18, 2018
45da49f
Update src/Query/Expression.php
simPod Oct 18, 2018
7e25e5f
Update src/Client.php
simPod Oct 18, 2018
9662a7c
Update src/Query/Expression.php
simPod Oct 18, 2018
da54872
Merge branch 'merge' of github.com:dorantor/phpClickHouse into merge
dorantor Oct 18, 2018
c08cf6a
Added ExpressionTest.
dorantor Oct 18, 2018
751a501
Fixed typo, removed empty lines.
dorantor Oct 18, 2018
6f2259f
Update tests/Query/ExpressionTest.php
simPod Oct 18, 2018
a68e3e0
Update tests/Query/ExpressionTest.php
simPod Oct 18, 2018
c7944e4
Update tests/Query/ExpressionTest.php
simPod Oct 18, 2018
c4aa709
Merge branch 'merge' of github.com:dorantor/phpClickHouse into merge
dorantor Oct 18, 2018
b3c340f
Update tests/Query/ExpressionTest.php
simPod Oct 18, 2018
72b7574
Update tests/Query/ExpressionTest.php
simPod Oct 18, 2018
80d4196
Update tests/Query/ExpressionTest.php
simPod Oct 18, 2018
11eb84a
Merge branch 'merge' of github.com:dorantor/phpClickHouse into merge
dorantor Oct 18, 2018
4d8b339
Fixed broken ExpressionTest.
dorantor Oct 18, 2018
7c14c60
Code formatting - aligned = signs as expected by phpcs.
dorantor Oct 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
include_once __DIR__ . '/src/Query/WriteToFile.php';
include_once __DIR__ . '/src/Query/WhereInFile.php';
include_once __DIR__ . '/src/Query/Query.php';
include_once __DIR__ . '/src/Query/Expression.php';
// Transport
include_once __DIR__ . '/src/Transport/Http.php';
include_once __DIR__ . '/src/Transport/CurlerRolling.php';
Expand Down
13 changes: 13 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use ClickHouseDB\Exception\QueryException;
use ClickHouseDB\Query\Degeneration;
use ClickHouseDB\Query\Expression;
use ClickHouseDB\Query\Degeneration\Bindings;
use ClickHouseDB\Query\Degeneration\Conditions;
use ClickHouseDB\Query\WhereInFile;
Expand Down Expand Up @@ -888,4 +889,16 @@ public function dropOldPartitions(string $table_name, int $days_ago, int $count_

return $result;
}

/**
* Build sql expression to be used "as is" in a query
*
* @param string $expression
*
* @return \ClickHouseDB\Query\Expression
*/
public function expr($expression)
{
return new Expression($expression);
}
}
34 changes: 34 additions & 0 deletions src/Query/Expression.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace ClickHouseDB\Query;

/**
* Query expression
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would deserve more explanation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated docblock with example and param type.

*
* @package ClickHouseDB
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

*/
class Expression
{
/**
* @var string
*/
protected $expression = '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO there should not be a default value and not be protected. Let there only be a constructor as the way to create a valid object.

Suggested change
protected $expression = '';
private $expression;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Sorry, just now understood that this change could be applied right in github.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Np, new feature introduced yesterday ;)


/**
* Expression constructor.
*
* @param $expression
*/
public function __construct($expression)
{
$this->expression = $expression;
}

/**
* @return string
*/
public function __toString()
{
return $this->expression;
}
}