records icon indicating copy to clipboard operation
records copied to clipboard

get row count from query method

Open yitzchakl opened this issue 8 years ago • 4 comments

Hi.

is it possible to get number of rows affected (in case of delete, update, insert, etc.) from query method?

yitzchakl avatar Jun 14 '17 09:06 yitzchakl

not to my knowledge

kennethreitz avatar Jun 14 '17 17:06 kennethreitz

I've also wanted this info; perhaps alongside .query there could be .execute which instead of returning a RecordCollection, returns the underlying ResultProxy from sqlalchemy?

pjz avatar Jul 06 '17 18:07 pjz

The correct answer might be to go 'around' records a bit:

mydb = records.Database(...)
result = mydb.db.execute("delete from mytable where mycondition = 1")

Personally, I did a bit of monkeypatching to expose a .execute that matched query semantics a bit closer:

import records
from sqlalchemy import text

def rdb_execute(self, query, **params):                                                                                                                          
    return self.db.execute(text(query), **params)                                                                                                                
                                                                                                                                                                 
records.Database.execute = rdb_execute

pjz avatar Jul 07 '17 14:07 pjz

Exposing the generic execute is also what #103 does, but he calls it in_bulk, which is a bit inaccurate. I agree with the implementation, but think it should be named execute.

pjz avatar Jul 13 '17 14:07 pjz