I'm currently using sqlalchemy
as my package for working on MySQL
databases. The databases are all large and were built before this software that is working with them, so I have not made ORM classes to interact with them in a session in sqlalchemy
. I'm currently working on them by creating an engine
and then using a transaction
in the following way
from sqlalchemy import create_engine
mysql_engine = create_engine(**connection_parameters)
connection = mysql_engine.connect()
trans = connection.begin()
try:
connection.execute("INSERT INTO FROM table (id, name) VALUES (1, 'foo')")
trans.commit()
res = conn.execute("SELECT * FROM table").fetchall()
print(res)
except:
trans.rollback()
Which comes partly from sqlalchemy tutorial. Is my understanding correct that the engine
is mostly a template for making connections? Also, is there an advantage to using sqlalchemy
for databases if I'm not utilizing ORMs and using the connections from it with raw SQL
statements? Is it faster or have benefits over using something like pymysql
or MySQLdb
?