Consider the following piece of code
import peewee
SQL_CONN = peewee.MySQLDatabase(database=SQL_DATA,
host=SQL_HOST,
port=SQL_PORT,
user=SQL_USER,
passwd=SQL_PASS)
class User(peewee.Model):
name = peewee.CharField(max_length=100, primary_key=True)
born = peewee.DateTimeField()
print(SQL_CONN.is_closed()) # True
print(User.select().where(User.name == "Jack").execute()) # Silently opens a connection w/o letting me know
print(SQL_CONN.is_closed()) # False
This will automatically perform SQL_CONN.connect()
under the hood.
How do I disable this functionality - force peewee
to just throw exceptions if the database is not connected - as opposed to automatically connecting to it without letting me know.