python - How to get sql query from peewee? -
simple peewee example: mysql db "pet" autoincrement "id" , char-field "name".
doing
my_pet = pet.select().where(name == 'garfield')
with .sql() sql interpretation.
how raw sql query from:
my_pet = pet.get(name='garfield')
?
when write:
my_pet = pet(name='garfield')
nothing @ happens in database.
you have created object. there no magic, peewee activerecord orm, , saves when call method model.save()
or model.create()
.
if want sql query model.create()
, should using model.insert()
instead:
insert_stmt = pet.insert(name='garfield') sql = insert_stmt.sql() new_obj_id = insert_stmt.execute()
the downside there aren't returned model instance, primary key.
Comments
Post a Comment