'sqlite3 persistent connection vs single cli call and how to implement former

This question is in part due to my lack of knowledge of the proper terminology but I can explain this practically:

It is possible to simply call sqlite3 mydatabase, and then from the command promt enter

> insert into people(firstname) values ('Joe');
> insert into people(firstname) values ('Bob');
... etc - let's say 1000 entries

It is also possible to run the following command line commands:

sqlite3 /path/to/mydatabase "insert into people(firstname) values('Joe');" ".exit"
sqlite3 /path/to/mydatabase "insert into people(firstname) values('Bob');" ".exit"

And perhaps even the last ".exit" is not needed (I am not sure).

From a performance perspective (if I could type infinitely fast) it seems the former would be faster than calling the 1000 commands in the second example.

My question is, is there a way to do the first example via a persistent object, ie be as if I was typing an unending series of queries at the sqlite prompt without exiting? I'm open to doing it in php, python or go (in that order).



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source