Overview
Namespace:FQL\Query
Query\Provider is the main entry point for building queries in FiQueLa. Its static methods open a data source and return a Query object. The Query object exposes a fluent API that mirrors SQL — you chain method calls to define SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, LIMIT, and more, then call execute() to get results.
Static factory methods
fromFile()
Open a file and return a Query ready to run against it. The format is detected automatically from the file extension unless you supply $format explicitly.
Filesystem path to the data file.
Force a specific format. When
null the format is inferred from the file extension.A
Query instance bound to the opened stream.FileNotFoundException, InvalidFormatException
fromFileQuery()
Parse a FileQuery string — a compact expression encoding the format, file path, optional parameters, and data path — and return a Query.
format(pathToFile[, params]).path.to.data
A FileQuery string such as
xml(feed.xml).SHOP.ITEM or csv(data.csv, "windows-1250", ";").*.A
Query instance, optionally pre-populated with a FROM clause if the query segment was present.FileNotFoundException, InvalidFormatException
fql()
Parse a full FQL (File Query Language) SQL-like string and return a Query object without executing it. Useful when queries are stored as strings or generated programmatically.
A complete FQL statement, e.g.
SELECT id, name FROM data/users.json WHERE active = 1.A configured
Query instance that can be further modified before calling execute().InvalidFormatException, FileNotFoundException
Query fluent API
All factory methods return aFQL\Query\Query object. Every method below returns $this (or Interface\Query) so calls can be chained.
SELECT
select()
Specify one or more fields to return. Accepts a comma-separated string or multiple arguments.
SelectException if a field is selected twice.
selectAll()
Select all fields (equivalent to SELECT *).
distinct()
Eliminate duplicate rows from the result set.
QueryLogicException when combined with groupBy().
as()
Alias the most recently selected field.
AliasException if the alias is empty, already used, or there is no preceding field.
exclude()
Remove one or more fields from the output even if they were included by selectAll().
Built-in SELECT functions
The following methods add a computed column to the SELECT list. Each returnsInterface\Query and can be followed by ->as('alias').
String functions
String functions
| Method | Description |
|---|---|
concat(string ...$fields) | Concatenate multiple fields |
concatWithSeparator(string $separator, string ...$fields) | Concatenate with a separator |
lower(string $field) | Convert to lowercase |
upper(string $field) | Convert to uppercase |
reverse(string $field) | Reverse a string |
replace(string $field, string $search, string $replace) | Find and replace |
substring(string $field, int $start, ?int $length) | Extract substring |
locate(string $substring, string $field, ?int $position) | Find position of substring |
leftPad(string $field, int $length, string $padString) | Pad left to given length |
rightPad(string $field, int $length, string $padString) | Pad right to given length |
explode(string $field, string $sep) | Split string into array |
implode(string $field, string $sep) | Join array into string |
fromBase64(string $field) | Decode Base64 |
toBase64(string $field) | Encode to Base64 |
randomString(int $length) | Generate random string |
Math functions
Math functions
| Method | Description |
|---|---|
round(string $field, int $precision) | Round a number |
ceil(string $field) | Round up |
floor(string $field) | Round down |
modulo(string $field, int $divisor) | Modulo operation |
add(string ...$fields) | Sum of fields |
subtract(string ...$fields) | Subtraction |
multiply(string ...$fields) | Multiplication |
divide(string ...$fields) | Division |
Aggregate functions
Aggregate functions
| Method | Description |
|---|---|
count(?string $field, bool $distinct) | Count rows or distinct values |
sum(string $field, bool $distinct) | Sum of numeric field |
avg(string $field) | Average |
min(string $field, bool $distinct) | Minimum value |
max(string $field, bool $distinct) | Maximum value |
groupConcat(string $field, string $sep, bool $distinct) | Concatenate grouped values |
Date functions
Date functions
| Method | Description |
|---|---|
strToDate(string $field, string $format) | Parse string to date |
formatDate(string $field, string $format) | Format a date field |
fromUnixTime(string $field, string $format) | Convert Unix timestamp |
currentDate(bool $numeric) | Current date |
currentTime(bool $numeric) | Current time |
currentTimestamp() | Current date and time |
now(bool $numeric) | Current date and time as formatted string (or YmdHis integer when $numeric = true) |
dateDiff(string $field1, string $field2) | Difference between dates |
dateAdd(string $field, string $interval) | Add interval to date |
dateSub(string $field, string $interval) | Subtract interval from date |
year(string $field) | Extract year |
month(string $field) | Extract month |
day(string $field) | Extract day |
Utility functions
Utility functions
| Method | Description |
|---|---|
cast(string $field, Enum\Type $as) | Cast field to a type |
coalesce(string ...$fields) | First non-null value |
coalesceNotEmpty(string ...$fields) | First non-empty value |
length(string $field) | Length of string or array |
sha1(string $field) | SHA-1 hash |
md5(string $field) | MD5 hash |
uuid() | Generate UUID |
randomBytes(int $length) | Generate random bytes |
arrayCombine(string $keys, string $values) | Combine two array fields |
arrayMerge(string $field1, string $field2) | Merge two array fields |
arrayFilter(string $field) | Filter falsy values from array |
arraySearch(string $field, string $value) | Search value in array field |
colSplit(string $field, ?string $format, ?string $keyField) | Split column into sub-structure |
fulltext(array $fields, string $query) | Fulltext relevance score |
matchAgainst(array $fields, string $query, ?Enum\Fulltext $mode) | Alias for fulltext() |
Conditional functions
Conditional functions
| Method | Description |
|---|---|
if(string $condition, string $true, string $false) | Inline IF expression |
ifNull(string $field, string $trueStatement) | Return value when field is null |
isNull(string $field) | Return bool indicating null |
case() | Begin a CASE expression |
whenCase(string $condition, string $then) | Add WHEN branch |
elseCase(string $default) | Add ELSE branch |
endCase() | Finalize CASE expression |
custom()
Inject a custom function object into the SELECT list.
FROM
from()
Set the path inside the data structure to iterate from. For nested data (XML, JSON) this selects the sub-node that contains rows.
WHERE / conditions
where()
Add the first (or primary) filter condition.
and() / or() / xor()
Chain additional conditions with the respective logical operator.
whereGroup() / andGroup() / orGroup() / havingGroup()
Open a new grouped sub-condition. havingGroup() starts a group in the HAVING context.
endGroup()
Close the current condition group.
JOIN
innerJoin() / leftJoin() / rightJoin() / fullJoin()
Add a join against another Query instance. Must be followed by ->on().
The right-side query to join.
Alias used to access joined fields. Must not be empty.
JoinException if alias is empty.
on()
Define the join condition immediately after a join method.
JoinException if called without a preceding join.
GROUP BY / HAVING
groupBy()
Group results by one or more fields.
QueryLogicException when combined with distinct().
having()
Filter groups using an aggregate condition.
ORDER BY
orderBy()
Sort results by a field. The default direction is ascending.
OrderByException if the same field is added twice.
asc() / desc()
Set the direction of the most recently added orderBy() field.
LIMIT / OFFSET / PAGE
limit()
Limit the number of rows returned, with an optional offset.
offset()
Skip the first N rows.
page()
Convenience helper for pagination. Computes offset automatically.
UNION
union()
Combine results with another query, removing duplicates.
unionAll()
Combine results with another query, keeping duplicates.
When both queries have explicit column lists (not
SELECT *), the column counts must match or execute() throws QueryLogicException.EXPLAIN
explain()
Return the query execution plan without running the query.
explainAnalyze()
Run the query and collect performance metrics per phase.
EXECUTE
execute()
Run the query and return a ResultsProvider.
Force
Results\InMemory::class or Results\Stream::class. When null, the mode is selected automatically: queries with joins or sorting use InMemory; all others use Stream.Either a
Results\Stream or Results\InMemory instance depending on query complexity.