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

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -