Skip to content
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

support parameterized raw expressions in inserts/updates/criteria values #195

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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