Skip to content

Allow PHP object to act as query #84

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
g105b opened this issue Mar 16, 2018 · 1 comment · Fixed by #372
Closed

Allow PHP object to act as query #84

g105b opened this issue Mar 16, 2018 · 1 comment · Fixed by #372

Comments

@g105b
Copy link
Member

g105b commented Mar 16, 2018

A typical user table will have the following queries:

  • src/query/user/create.sql
  • src/query/user/delete.sql
  • src/query/user/getById.sql
  • src/query/user/update.sql

Allowing the ResultSet to be build programatically would replace the above files with one file:

  • src/query/User.php

Which would contain the following methods:

  • User::create
  • User::delete
  • User::getById
  • User::update

If there is a class and method present, use that. If not, fall back to SQL. This allows PHP to produce some ResultSets that are not easy to produce in SQL, and allows the developer to skip using SQL at all.

This will make it really easy to get a prototype going, without the need of a database. A mechanism needs to be created that defines where the data is stored. By default, this can simply be in the data directory, as files/directories in the filesystem. Really simple way to make a prototype, and uses a set template for upgrading when speed and scalability is required.

@g105b g105b added this to the v3 milestone Mar 16, 2018
@g105b g105b modified the milestones: v3, v2 Apr 20, 2023
@g105b
Copy link
Member Author

g105b commented Mar 26, 2025

  • QueryFactory::findQueryFilePath can be augmented to return the path with method name, when PHP is encountered. e.g. /path/to/query/Example.php::selectTheThing() - this is fine to not be an actual file path on disk, because the file path is checked in the Query constructor.
  • Inside the Query ctor, handle :: paths differently. Still store the file path with the double colon, but there needs to be more complex checks involved to check if the query actually exists - does the PHP file exist? The method check can come next.
  • SqlQuery::getSql should load the PHP file and call the method, which must return a string or stringable.

g105b added a commit that referenced this issue May 11, 2025
g105b added a commit that referenced this issue May 19, 2025
* ci: upgrade workflow

* feature: split query collection into directory/class subclasses
for #84

* wip: break Query into SqlQuery and PhpQuery

* feature: php object query
for #84

* build: php 8.1 compatibility

* tweak: remove non-existant test

* tweak: import DateTimeInterface

* tweak: remove superfluous typehint

* tweak: ignore complexity of abstract query class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant