php-sql-query-builder icon indicating copy to clipboard operation
php-sql-query-builder copied to clipboard

Ability of dynamic setColumns and setValues parameters injection by object types

Open ovflowd opened this issue 7 years ago • 0 comments

Hello! I was wondering the following feature in this library, see this scenario: Recently with the intensification of JSON communication messages, and more frameworks appearing in the internet like Angular, and others that uses jSON as communication messages for MVC models fillings, i was wondering if the feature of dynamic columns and values (respectively of SELECT and INSERT/UPDATE) can be coded for this library.

The deal is simple, since it's based in the relation of Data Models and certain properties being used as criteria for the SQL Builder.

See the following scenario:

  1. I have a model (object) called "Users", which have public properties: ID, NAME, MAIL, that are correspondent directly of the table "users" that contains columns "ID, NAME, MAIL", the idea it's as an example, in case of SELECT using those properties as the desired columns to be selected, and in case of INSERT/UPDATE being the Values to be updated or inserted, where the properties that aren't filled, strictly being null, will not be added as values to be updated.
  2. Also if you know the RESTful api methodologies, we can do a relation between the HTTP methods GET, PUT, POST and DELETE as the correspondent MySQL query types (SELECT, UPDATE, INSERT, DELETE).
  3. Following that the Criteria (in case of this library where() statements) can be also (supposing) objects, think the following scenario, we have an Property Object (property equals a column of a table), these property objects does the relation of which columns need to be added as a criteria for the SQL Instruction, as an example, an Array of Property Objects are the same as a set of criterias. The Property Object is, as an example, with the properties of INTERNAL_NAME, corresponding at the name of the column in database, and FRIENDLY_NAME, corresponding as the public name of the column (visible for the client/user). Obviously the Property Object need to be generic and followed by an Interface document, meaning, the Property Object is a class of your library, in the example.

The scenario is a good tip, since php works really well with objects and arrays, and also with the casting of those. Since your library allows the insertion of values(), columns() as array, and sadly each criteria (where()), need be manually configured.. The option of alllowing objects or array of objects as values and columns is great, in my opinion haha...

This feature in my opinion is good, and really helpful. Really in my usage of your framework i use objects as data models, and i need every time do foreach loops or arrays manipulation to create arrays through the iteration of my objects to insert as argument of yours values(), columns() and where() methods..

Your library is good, but adding this feature in my opinion is good also..

Sorry about my bad english, been a good time that i don't write big texts in english.. If you didn't understood anything, or have questions about some parts of what i wrote, ask me haha.

I really think this feature will be awesome! Cheers and big hugs.

ovflowd avatar Jul 22 '16 17:07 ovflowd