Download the PHP package esazykin/clickhouse-builder without Composer
On this page you can find all versions of the php package esazykin/clickhouse-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download esazykin/clickhouse-builder
More information about esazykin/clickhouse-builder
Files in esazykin/clickhouse-builder
Package clickhouse-builder
Short Description Clickhouse sql query builder
License MIT
Informations about the package clickhouse-builder
Clickhouse Query Builder
Requirements
php 7.1
Install
Via composer
Usage
For working query builder we must previously instantiate and pass in constructor the-tinderbox/clickhouse-php-client
.
After that we can build and perform sql queries.
Select columns
All this calls will be transformed into next sql:
Also, as a column we can pass closure. In this case in closure will be passed instance of Column class, inside which we can setup column how we want. This can be useful for difficult expressions with many functions, subqueries and etc.
Will be compiled in:
Will be compiled in:
Same behavior can be also achieved by any of the following approaches:
Notice! Functions on columns is not stable and under development.
From
Produce the following query:
Also can be passed closure or builder as argument for performing sub query.
or
or
or
It is all variants of the same sql query which was listed above.
Sample coefficient
I think there no need for additional words)
Joins
For performing subquery as first argument you can pass closure or builder.
Also there are many helper functions with hardcoded arguments, like strict or type and they combinations.
Temporary tables usage
There are some cases when you need to filter f.e. users by their ids, but amount of ids is huge. You can store users ids in local file, upload it to server and use it as temporary table.
Will produce:
If you want tables to be detected automatically, call addFile
method before calling whereIn
.
You can use local files in whereIn
, prewhereIn
, havingIn
and join
statements of query builder.
Prewhere, where, having
All example will be about where, but same behavior also is for prewhere and having.
All string values will be wrapped with single quotes.
If operator is not provided =
will be used.
If operator is not provided and value is an array, then IN
will be used.
If in the first argument was passed closure, then all wheres statements from inside will be wrapped with parenthesis.
But if on that builder (inside closure) will be specified from
then it will be transformed into subquery.
Almost same is for value parameter, except wrapping into parenthesis. Any closure or builder instance passed as value will be converted into subquery.
Also you can pass internal representation of this statement and it will be used. I will no talk about this with deeper explanation because its not preferable way to use this.
Like joins there are many helpers with hardcoded parameters.
Also there is method to make where by dictionary:
If you want to use complex key, you may pass an array as $key
, then array will be converted to tuple. By default all strings will be escaped by single quotes, but you may pass an Identifier
instance to pass for example column name:
Will produce:
Group By
Works like select.
Final query will be like:
Order By
In the example above, third argument is optional
Aliases:
For column there are same behaviour like in select method.
Limit
There are two types of limit. Limit and limit n by.
Limit n by:
Will produce:
Simple limit:
Will produce:
SELECT * FROM `table` LIMIT 100, 10
Union ALL
In unionAll
method can be passed closure or builder instance. In case of closure inside will be passed
builder instance.
Performing request and getting result.
After building request you must call get()
method for sending request to the server.
Also there has opportunity to make asynchronous requests. Its works almost like unionAll
.
This callings will produce the same behavior. Two queries which will be executed asynchronous.
Now, if you call get()
method, as result will be returned array, where numeric index correspond to the result of
request with this number.
All versions of clickhouse-builder with dependencies
myclabs/php-enum Version ^1.5
the-tinderbox/clickhouse-php-client Version ^1.0