I am porting the following 10 lines of Python code to Scala:
import psycopg2
def execute(user, password, database, host, port, *queries):
connection = psycopg2.connect(user=user, password=password, host=host, port=port, database=database)
cursor = connection.cursor()
for sql in queries:
print(sql)
cursor.execute(sql)
connection.commit()
cursor.close()
connection.close()
I have the following equivalent Scala code:
def execute(user: String, password: String, database: String, host: String, port: Int, queries: String*): Unit = {
???
}
I want to execute (and print) bunch of SQL statements in a single transaction against the database (assume it to be Postgres) and be done.
How do I do that using doobie?
Note:
I cannot change the interface to my
execute()
(including I cannot add type or implicit params). It must take in String user, password etc. and a vararg ofqueries: String*
and thus keep the interface same as the Python one.Please also mention all imports needed