Download the PHP package matatirosoln/sql-to-odata without Composer
On this page you can find all versions of the php package matatirosoln/sql-to-odata. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download matatirosoln/sql-to-odata
More information about matatirosoln/sql-to-odata
Files in matatirosoln/sql-to-odata
Package sql-to-odata
Short Description Convert SQL queries to OData query syntax.
License MIT
Informations about the package sql-to-odata
MSDev SQL to OData
A PHP library for converting SQL queries to OData (Open Data Protocol) query syntax. Targets OData 4.01 at the intermediate conformance level, primarily designed for use with the Claris FileMaker OData API (FileMaker Server 2025 / v22+).
We would be very interested in hearing from potential users who have access to alternative OData implementations and may be interested in working to extend this library to ensure that it is broadly useful as possible.
Requirements
- PHP ^8.4
- Composer
Installation
Usage
Call parse() on any supported SQL statement. It returns a typed query object you can inspect to build your OData request.
SELECT
Returns a SelectQuery with entitySet and queryString properties.
INSERT
Returns an InsertQuery with entitySet and body properties. body is an associative array of column-value pairs with PHP-native types, suitable for JSON-encoding into a POST request body.
UPDATE
Returns an UpdateQuery with entitySet, body, and filter properties. filter is an OData filter expression derived from the WHERE clause. UPDATE without a WHERE clause throws a ConversionException.
DELETE
Returns a DeleteQuery with entitySet and filter properties. DELETE without a WHERE clause throws a ConversionException.
Dispatching on query type
Use match or instanceof checks to handle each statement type:
Supported SQL features
Targets OData 4.01 intermediate conformance level (spec).
SELECT clauses
| SQL | OData |
|---|---|
SELECT col1, col2 |
$select=col1,col2 |
SELECT * |
(omitted — returns all fields) |
JOIN / LEFT JOIN |
$expand |
WHERE |
$filter |
ORDER BY |
$orderby |
LIMIT n |
$top=n |
LIMIT n OFFSET m |
$top=n&$skip=m |
JOIN → $expand
SQL JOINs are translated to OData $expand, which follows navigation properties defined in the OData service metadata. Columns selected from a joined table are promoted into a nested $select within the expand:
Multiple JOINs produce a comma-separated $expand:
Note: Unlike SQL, OData
$expandis constrained to navigation properties defined in the service metadata — arbitrary cross-entity joins are not supported by the OData protocol itself.
WHERE operators
| SQL | OData |
|---|---|
= |
eq |
!= / <> |
ne |
> |
gt |
>= |
ge |
< |
lt |
<= |
le |
AND / OR |
and / or |
IS NULL |
eq null |
IS NOT NULL |
ne null |
LIKE '%val%' |
contains(col, 'val') |
LIKE 'val%' |
startswith(col, 'val') |
LIKE '%val' |
endswith(col, 'val') |
IN (a, b, c) |
(col eq a or col eq b or col eq c) |
Exceptions
All errors throw Matatirosoln\SqlToOdata\Exception\ConversionException. Common cases:
- Invalid or unparseable SQL
- UPDATE or DELETE without a WHERE clause
- Subqueries (not supported)
- Unsupported statement types (e.g.
CREATE,DROP)
Running tests
License
MIT — see LICENSE.
Contact
Steve Winter — Matatiro Solutions Ltd — [email protected]