pixie icon indicating copy to clipboard operation
pixie copied to clipboard

support parameterized raw expressions in inserts/updates/criteria values

Open drdaxxy opened this issue 7 years ago • 1 comments

This PR enables using raw() expressions with parameters in insert queries, update queries and inside (right-hand side) value expressions of (where) criteria. Tests updated accordingly.

Insert

QB::table('people')->getQuery('insert', [
    'firstname' => 'Jane',
    'lastname'  => QB::raw('UPPER(?)', 'Doe'),
    'age'       => 27
])->getRawSql();

// before: INSERT INTO `people` (`firstname`,`lastname`,`age`) VALUES ('Jane',UPPER(27),?)
// after:  INSERT INTO `people` (`firstname`,`lastname`,`age`) VALUES ('Jane',UPPER('Doe'),27)

Where

QB::table('people')
    ->where('firstname', '=', 'Jane')
    ->where('lastname', '=', QB::raw('UPPER(?)', 'Doe'))
    ->getQuery()->getRawSql();

// before: SELECT * FROM `people` WHERE `firstname` = 'Jane' AND `lastname` = UPPER(?)
// after:  SELECT * FROM `people` WHERE `firstname` = 'Jane' AND `lastname` = UPPER('Doe')

drdaxxy avatar Aug 22 '18 05:08 drdaxxy

Hi @drdaxxy many thanks for the PR and effort, this is definitely a great feature. Can you review @usmanhalalit ?

TCB13 avatar Aug 22 '18 11:08 TCB13