Skip to content

Conversation

@drdaxxy
Copy link

@drdaxxy drdaxxy commented Aug 22, 2018

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')

@TCB13
Copy link

TCB13 commented Aug 22, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants