mysqlclient icon indicating copy to clipboard operation
mysqlclient copied to clipboard

Documentation clarification

Open tonkolviktor opened this issue 1 year ago • 1 comments

Hi, thanks for putting all the work into the module!

I had to do some quick inserts to mysql and I could not find a very good sample on the documentation page. It's described multiple times how to connect, but I could not find a single complete db update example.

A quick count shows 20 hits for 'connect(', only 6 for 'query(' and only 3 for 'close('

(I might be expert db connecter :) I would be ok with 1 of that, since I might be less expert db updater more of that I would find helpful)

Sooo is is something like this the expected way of working:

import MySQLdb as mysql

mysql_conn = mysql.connect(...)
cursor = mysql_conn.cursor()
try:
    cursor.execute("INSERT ... ")
    mysql_conn.commit()
except OperationalError??? as e:
    mysql_conn.rollback()
finally:
    cursor.close()
    mysql_conn.close()

Small correction: https://mysqlclient.readthedocs.io/MySQLdb.html?highlight=execute#MySQLdb.connections.Connection.begin "Explicitly begin a connection." -> "Explicitly begin a transaction."

tonkolviktor avatar Aug 04 '22 20:08 tonkolviktor

It is because most API is DB-API 2.0 compatible and user can find "how to" elsewehere. And this library is low level library. Application programmers are recommended to use higher layer libraries like Django or SQLAlchemy.

I don't have motivation and energy to improve doc for application programmers. They can learn from many books and web tutorials.

connect() is special because many options in the connect() are important and not part of DB-API 2.0. So they are documented well. Even application programmers using SQLAlchemy or Django should know many options of connect().

Small correction: https://mysqlclient.readthedocs.io/MySQLdb.html?highlight=execute#MySQLdb.connections.Connection.begin "Explicitly begin a connection." -> "Explicitly begin a transaction."

Thank you. I will fix it.

methane avatar Aug 05 '22 02:08 methane