def test_not_passing_where_clause(self): stmt = insert(self.some_table).values(id=1) stmt = get_on_conflict_stmt(stmt, ["id"], ["id"]) assert ( format_statement(stmt) == "INSERT INTO conflict_model (id) VALUES (1) ON CONFLICT (id) DO UPDATE SET id = excluded.id" )
def test_does_nothing_if_no_arguments(self): stmt = insert(self.some_table).values(id=1) stmt = get_on_conflict_stmt( stmt, ["id"], [], where=stmt.excluded.id == self.some_table.c.id) assert ( format_statement(stmt) == "INSERT INTO conflict_model (id) VALUES (1) ON CONFLICT (id) DO NOTHING" )
def test_upsert(): table = SomeModel.__table__ stmt = insert(table).values(id=1) stmt = get_on_conflict_stmt(stmt, ["id"], ["id"], where=stmt.excluded.id == table.c.id) assert ( format_statement(stmt) == "INSERT INTO some_model (created_at, updated_at, id) VALUES (now(), now(), 1) ON CONFLICT (id) DO UPDATE SET id = excluded.id WHERE excluded.id = some_model.id" )
def test_upsert_with_timestamp_mixin(self): stmt = insert(self.timestamp_table).values(id=1) stmt = get_on_conflict_stmt( stmt, ["id"], ["id"], where=stmt.excluded.id == self.timestamp_table.c.id) assert ( format_statement(stmt) == "INSERT INTO timestamp_model (last_seen_at, first_seen_at, id) VALUES (now(), now(), 1) ON CONFLICT (id) DO UPDATE SET last_seen_at = %(param_1)s, id = excluded.id WHERE excluded.id = timestamp_model.id" )
def test_upsert(self): stmt = insert(self.some_table).values(id=1) stmt = get_on_conflict_stmt( stmt, ["id"], ["id"], where=stmt.excluded.id == self.some_table.c.id) assert ( format_statement(stmt) == "INSERT INTO conflict_model (id) VALUES (1) ON CONFLICT (id) DO UPDATE SET id = excluded.id WHERE excluded.id = conflict_model.id" )
def test_does_nothing_if_do_nothing_action_was_passed(self): stmt = insert(self.some_table).values(id=1) stmt = get_on_conflict_stmt( stmt, ["id"], ["id"], where=stmt.excluded.id == self.some_table.c.id, action=ConflictAction.DO_NOTHING, ) assert ( format_statement(stmt) == "INSERT INTO conflict_model (id) VALUES (1) ON CONFLICT (id) DO NOTHING" )