peewee

Can I chain where clauses conditionally?

Can I chain where clauses conditionally? Question: I’m using Peewee as ORM extensively and within my DAO API layer I need to conditionally make a query narrower e.g. query = UserModel.select().where(UserModel.last_name == last_name) if first_name is not None: query = query.where(UserModel.first_name == first_name) # … more conditions then df = pd.DataFrame(query.dicts()) is this the most …

Total answers: 2

Peewee value returns to its default after few seconds (BUG?)

Peewee value returns to its default after few seconds (BUG?) Question: This used to be my model: db = SqliteDatabase(Settings.stats_conf_database_location) class ActivityTracker(Model): date = DateField(unique=True) activity_time_curr = IntegerField(default=0) # active seconds today activity_time_max = IntegerField() # max active seconds today class Meta: database = db I added: blocked = BooleanField(default=False) as a 4th parameter and …

Total answers: 1

Using parameters to return table column values?

Using parameters to return table column values? Question: I want to be able to use a parameter to determine which columns value to return. But, since ‘owner’ is a model, the ‘assetType’ in ‘owner.assetType’ is treated as an attribute and not as the parameter. This is just an example of the code I’m working on. …

Total answers: 1

Python Peewee – How to select and alias a literal column value?

Python Peewee – How to select and alias a literal column value? Question: Given the following model: class User(BaseModel): name = TextField() How do I execute the following sql: SELECT name, ‘hello’ as foo FROM user I’ve found that I can use peewee.Alias, but I’m not sure if this is the ideal approach: >>> print(User.select(User.name, …

Total answers: 1

Multiple write single read SQLite application with Peewee

Multiple write single read SQLite application with Peewee Question: I’m using an SQLite database with peewee on multiple machines, and I’m encountering various OperationalError, DataBaseError. It’s obviously a problem of multithreading, but I’m not at all an expert with this nor with SQL. Here’s my setup and what I’ve tried. Settings I’m using peewee to …

Total answers: 3

Peewee (Python Sqlite ORM) – NameError: name 'SqliteDatabase' is not defined

Peewee (Python Sqlite ORM) – NameError: name 'SqliteDatabase' is not defined Question: OS Linux Mint 18.3 (but same problem also with version 19) Python3 and Sqlite3 installed After a lot of trouble with “pip / pip3”, I managed to install Peewee. I tried running the following sample script with python3 peewee.py but I get this …

Total answers: 2

peewee field default type and DateTimeField

peewee field default type and DateTimeField Question: I have created model class inherititng form peewee.Model import peewee class Example(peewee.Model): id = peewee.IntField(primary_key=True) text = peewee.charField(default=”waiting”) dt = peewee.DateTimeField(default=datetime.datetime.now().strftime(‘%Y-%m-%d’)) but when I insert new value for just only id field to the example table I do not get the default text value as “waiting” and date_added …

Total answers: 1

How to store binary data in pewee BlobField

How to store binary data in pewee BlobField Question: How can I store binary data io.BytesIO() in SQLlite DB using peewee? When I try to store it in BlobField I’m getting following error: ValueError: Value must be either a bytes, memoryview or BigBitFieldData instance. Asked By: Leopoldo || Source Answers: It appears that you’re not …

Total answers: 2

Peewee ORM JSONField for MySQL

Peewee ORM JSONField for MySQL Question: I have a peewee model like so: class User(peewee.Model): name = peewee.CharField(unique=True) some_json_data = peewee.CharField() requested_at = peewee.DateTimeField(default=datetime.now()) I know that peewee doesn’t support a JSONField for a MySQL DB, but anyway, I though if I could just convert it to a string format and save to db, I …

Total answers: 2