flow php

DSL stands for Domain Specific Language. In the case of Flow, the DSL is used to define simple functions that can be used to transform data. Most of those functions are initializing a new instance of a class under the hood since Flow is fully object-oriented. Please look at the examples below to get a better understanding of how to use the DSL functions.

HELPER


/**
 * Create a CountModifier that transforms a SELECT query into a COUNT query.
 *
 * The original query is wrapped in: SELECT COUNT(*) FROM (...) AS _count_subq
 * ORDER BY and LIMIT/OFFSET are removed from the inner query.
 */
pg_count_modifier() : CountModifier
/**
 * Convert a ParsedQuery AST back to SQL string.
 *
 * When called without options, returns the SQL as a simple string.
 * When called with DeparseOptions, applies formatting (pretty-printing, indentation, etc.).
 *
 * @throws \RuntimeException if deparsing fails
 */
pg_deparse(ParsedQuery $query, ?DeparseOptions $options) : string
/**
 * Returns a fingerprint of the given SQL query.
 * Literal values are normalized so they won't affect the fingerprint.
 */
pg_fingerprint(string $sql) : ?string
/**
 * Parse and format SQL query with pretty printing.
 *
 * This is a convenience function that parses SQL and returns it formatted.
 *
 * @param string $sql The SQL query to format
 * @param null|DeparseOptions $options Formatting options (defaults to pretty-print enabled)
 *
 * @throws \RuntimeException if parsing or deparsing fails
 */
pg_format(string $sql, ?DeparseOptions $options) : string
/**
 * Create a KeysetColumn for keyset pagination.
 *
 * @param string $column Column name (can include table alias like "u.id")
 * @param SortOrder $order Sort order (ASC or DESC)
 */
pg_keyset_column(string $column, SortOrder $order) : KeysetColumn
/**
 * Create a KeysetPaginationModifier for cursor-based pagination.
 *
 * Keyset pagination is more efficient than OFFSET for large datasets because it uses
 * indexed WHERE conditions instead of scanning and skipping rows.
 *
 * @param int $limit Maximum number of rows to return
 * @param list<KeysetColumn> $columns Columns to use for keyset pagination (must match ORDER BY)
 * @param null|list<null|bool|float|int|string> $cursor Cursor values from the last row of previous page (null for first page)
 */
pg_keyset_pagination(int $limit, array $columns, ?array $cursor) : KeysetPaginationModifier
/**
 * Create a KeysetPaginationConfig for cursor-based pagination.
 *
 * @param int $limit Maximum number of rows to return
 * @param list<KeysetColumn> $columns Columns to use for keyset pagination (must match ORDER BY)
 * @param null|list<null|bool|float|int|string> $cursor Cursor values from the last row of previous page (null for first page)
 */
pg_keyset_pagination_config(int $limit, array $columns, ?array $cursor) : KeysetPaginationConfig
/**
 * Normalize SQL query by replacing literal values and named parameters with positional parameters.
 * WHERE id = :id will be changed into WHERE id = $1
 * WHERE id = 1 will be changed into WHERE id = $1.
 */
pg_normalize(string $sql) : ?string
/**
 * Normalize utility SQL statements (DDL like CREATE, ALTER, DROP).
 * This handles DDL statements differently from pg_normalize() which is optimized for DML.
 */
pg_normalize_utility(string $sql) : ?string
/**
 * Create a PaginationModifier for offset-based pagination.
 *
 * Applies LIMIT and OFFSET to the query. OFFSET without ORDER BY will throw an exception.
 *
 * @param int $limit Maximum number of rows to return
 * @param int $offset Number of rows to skip (requires ORDER BY in query)
 */
pg_pagination(int $limit, int $offset) : PaginationModifier
/**
 * Create a PaginationConfig for offset-based pagination.
 *
 * @param int $limit Maximum number of rows to return
 * @param int $offset Number of rows to skip (requires ORDER BY in query)
 */
pg_pagination_config(int $limit, int $offset) : PaginationConfig
/**
 * Extract columns from a parsed SQL query.
 */
pg_query_columns(ParsedQuery $query) : Columns
/**
 * Extract tables from a parsed SQL query.
 */
pg_query_tables(ParsedQuery $query) : Tables
/**
 * Split string with multiple SQL statements into array of individual statements.
 *
 * @return array<string>
 */
pg_split(string $sql) : array
/**
 * Generate a summary of parsed queries in protobuf format.
 * Useful for query monitoring and logging without full AST overhead.
 */
pg_summary(string $sql, int $options, int $truncateLimit) : string
/**
 * Transform a SQL query into a COUNT query for pagination.
 *
 * Wraps the query in: SELECT COUNT(*) FROM (...) AS _count_subq
 * Removes ORDER BY and LIMIT/OFFSET from the inner query.
 *
 * @param string $sql The SQL query to transform
 *
 * @return string The COUNT query
 */
pg_to_count_query(string $sql) : string
/**
 * Transform a SQL query into a keyset (cursor-based) paginated query.
 *
 * More efficient than OFFSET for large datasets - uses indexed WHERE conditions.
 *
 * @param string $sql The SQL query to paginate (must have ORDER BY)
 * @param int $limit Maximum number of rows to return
 * @param list<KeysetColumn> $columns Columns for keyset pagination (must match ORDER BY)
 * @param null|list<null|bool|float|int|string> $cursor Values from last row of previous page (null for first page)
 *
 * @return string The paginated SQL query
 */
pg_to_keyset_query(string $sql, int $limit, array $columns, ?array $cursor) : string
/**
 * Transform a SQL query into a paginated query with LIMIT and OFFSET.
 *
 * @param string $sql The SQL query to paginate
 * @param int $limit Maximum number of rows to return
 * @param int $offset Number of rows to skip (requires ORDER BY in query)
 *
 * @return string The paginated SQL query
 */
pg_to_paginated_query(string $sql, int $limit, int $offset) : string

Contributors

Join us on GitHub external resource
scroll back to top