last_insert_id¶
-
PostgresWrapper.
last_insert_id
(table_name: str, pk_name='id')[source]¶ Get the last inserted ID for a given table + primary key.
Example:
>>> db = PostgresWrapper(db='my_db') >>> db.action('INSERT INTO users (first_name, last_name) VALUES (?, ?);', ['John', 'Doe']) >>> last_id = db.last_insert_id('users') >>> db.fetchone('SELECT first_name, last_name FROM users WHERE id = ?', [last_id]) Record(id=16, first_name='John', last_name='Doe')