#Code improvements
Code improvements
#Design improvements
Design improvements
#Code improvements
#Design improvements
Code improvements
Design improvements
Since you are using Python 3, consider using type hints. This will make your code easier to read, as well as allow static analysis of your code to make sure the correct types are used. For example, here would be your connect
function with type hints. Note the added import from typing
, which has common types like List
, Dict
, and Tuple
.
- For performance, queries that at ranare executed "ad hoc" (or, basically, improvised) on the database usually have a poorer performance than queries that are stored. The SQL database usually has to recalculate execution plans for ad hoc queries each time, as opposed to re-using the execution plan from the last time(s) a similar query was executed. On busy production databases, this can make a significant impact on the database processing load.
Since you are using Python 3, consider using type hints. This will make your code easier to read, as well as allow static analysis of your code. For example, here would be your connect
function with type hints. Note the added import from typing
, which has common types like List
, Dict
, and Tuple
.
- For performance, queries that at ran "ad hoc" (or, basically, improvised) on the database usually have a poorer performance than queries that are stored. The SQL database usually has to recalculate execution plans for ad hoc queries each time, as opposed to re-using the execution plan from the last time(s) a similar query was executed. On busy production databases, this can make a significant impact on the database processing load.
Since you are using Python 3, consider using type hints. This will make your code easier to read, as well as allow static analysis of your code to make sure the correct types are used. For example, here would be your connect
function with type hints. Note the added import from typing
, which has common types like List
, Dict
, and Tuple
.
- For performance, queries that are executed "ad hoc" (or, basically, improvised) on the database usually have a poorer performance than queries that are stored. The SQL database usually has to recalculate execution plans for ad hoc queries each time, as opposed to re-using the execution plan from the last time(s) a similar query was executed. On busy production databases, this can make a significant impact on the database processing load.
I would recommend using the string .format()
string .format()
method instead of +
'ing strings together. For example:
def check_user_exists(nameuser_name: str) -> bool:
query = "SELECT id FROM users WHERE name = ?"
cursor.execute(query, nameuser_name)
# etc.
I would recommend using the string .format()
method instead of +
'ing strings together. For example:
def check_user_exists(name: str) -> bool:
query = "SELECT id FROM users WHERE name = ?"
cursor.execute(query, name)
# etc.
I would recommend using the string .format()
method instead of +
'ing strings together. For example:
def check_user_exists(user_name: str) -> bool:
query = "SELECT id FROM users WHERE name = ?"
cursor.execute(query, user_name)
# etc.