I'm wondering if it's possible to prevent committing duplicates to the database. For example, presume there is a class as follows
class Employee(Base):
id = Column(Integer, primary_key=True)
name = Column(String)
If I were to make a series of these objects,
employee1 = Employee(name='bob')
employee2 = Employee(name='bob')
session.add_all([employee1, employee2])
session.commit()
I would like only a single row to be added to the database, and employee1 and employee2 to point to the same object in memory (if possible).
Is there functionality within SQLAlchemy to accomplish this? Or would I need to ensure duplicates don't exist programmatically?