mindplay-dk / sql

Database framework and query builder
Other
17 stars 6 forks source link

Allow Column for $name in Query::bind() #35

Open mindplay-dk opened 7 years ago

mindplay-dk commented 7 years ago

Allow Column in place of $name in the Query::bind() method.

Currently it accepts only string.

For example this:

$delete = $this->db
    ->delete($c)
    ->where("{$c->parent_uuid} = :parent_uuid AND {$c->column_index} = :column_index")
    ->bind($c->parent_uuid->getName(), $parent_uuid)
    ->bind($c->column_index->getName(), $column_index);

Could then be simplified as this:

$delete = $this->db
    ->delete($c)
    ->where("{$c->parent_uuid} = :parent_uuid AND {$c->column_index} = :column_index")
    ->bind($c->parent_uuid, $parent_uuid)
    ->bind($c->column_index, $column_index);

The bind() method would internally call getName() for you.

This won't work for all cases, but will work in a lot of cases for SELECT queries at least.