Fun fact: there are biological viruses that exclusively eat bacteria called "bacteriophages."
Viruses as a rule are extremely host-specific, because they can only latch on to one or a few specific proteins on the surface of the host cells they're parisitizing. The fact that bacterial cells are so different from human or any animal cells means its almost if not impossible for them to harm humans. Using a bacterial sample / culture from an infection to breed bacteriophages that can then be introduced to the patient fight the infection is called "phage therapy" and is actually fairly common in some parts of the world. Phage therapy often outpreforms antibiotic therapy both in terms of resistance and in terms of safety for the patient. Because they're so host specific it's both harder for the bacteria to develop resistance and less likely to harm the patient.
A better analogy to the OP might be something more like a specially retrovirus that inserts dna into a cell that that cell will then replicate as part of its own, but it tangentially reminded me of this so I thought I'd share.