mcfunley / pugsql

A HugSQL-inspired database library for Python
https://pugsql.org
Apache License 2.0
673 stars 22 forks source link

Add :insert Result which returns the inserted primary key #6

Closed pingiun closed 5 years ago

pingiun commented 5 years ago

This allows insert statements to quickly use the inserted primary key, this is useful when auto increment primary keys are used.

This feature is based on this api.

The api docs for sqlalchemy say this:

This is a DBAPI specific method and is only functional for those backends which support it, for statements where it is appropriate. It’s behavior is not consistent across backends.

I only tested this with sqlite (see tests/test_pugsql.py)

mcfunley commented 5 years ago

Hey thank you this is great!

I'm wondering if there's a way to unify this with INSERT .. RETURNING syntax with postgres, etc. I'll merge this and open a ticket for thinking about that..