gabordemooij / redbean

ORM layer that creates models, config and database on the fly
https://www.redbeanphp.com
2.31k stars 279 forks source link

Get cursor with raw SQL query #656

Closed oderayi closed 6 years ago

oderayi commented 6 years ago

In RedBeanPHP, the only way to work with cursor is through findCollection, but findCollection does not support raw SQL query.

Is there a way I can work with cursor while using raw SQL query (with joins) with RedBeanPHP?

Thank you!

Lynesth commented 6 years ago

Hey there,

You currently can use this:

R::getToolbox()->getDatabaseAdapter()->getCursor( $sql, $bindings );

Example:

$cursor = R::getToolbox()->getDatabaseAdapter()->getCursor( 'SELECT * FROM users WHERE name LIKE ?', [ 'A%' ] );
while ($row = $cursor->getNextItem()) {
    // Do your thing...
}
gabordemooij commented 6 years ago

It would be good to have a direct function for this in the facade I think.