Questions tagged [peewee]

peewee is a small ORM written in Python, providing a lightweight querying interface over SQL.

peewee is a small ORM written in Python. It provides a lightweight querying interface over SQL, and uses SQL concepts when querying, like joins and where clauses. It supports sqlite, mysql and postgresql.

1197 questions
6
votes
2 answers

How can I create a model of a table with an enum in peewee 2?

I'm trying to create a model to describe a table with an enum field in peewee. I'm seeing that EnumField was removed from the peewee.py file before the 2.0 version, and I can't find anything in the current docs that outlines how to implement it.…
Chris Matta
  • 3,263
  • 3
  • 35
  • 48
6
votes
1 answer

Python: Dumping Database Data with Peewee

Background I am looking for a way to dump the results of MySQL queries made with Python & Peewee to an excel file, including database column headers. I'd like the exported content to be laid out in a near-identical order to the columns in the…
Rejected
  • 4,445
  • 2
  • 25
  • 42
6
votes
1 answer

Can an operator be overloaded as a class method in python?

In order to make an extension really clean looking I'm trying to implement the ">>" operator in python as a class method. I'm not sure how to go about it though. I don't want to have to create an instance since I am really operating on the class…
sdobz
  • 63
  • 4
5
votes
2 answers

Foreign key to the same table in Python Peewee

I am using ORM peewee for sqlite in Python. I would like to create table Item with field parent_id that will be foreign key to the Item: from peewee import * db = SqliteDatabase("data.db") class Item(Model): id = AutoField() parent_id =…
Michal
  • 1,755
  • 3
  • 21
  • 53
5
votes
1 answer

Peewee row level blocking

I'm currently using Peewee as an ORM in my project. In my current situation, I have some processes each having a database connection. All of these processes need to access a certain table simultaneously. I'm looking for some way to make them…
Offofue
  • 159
  • 1
  • 10
5
votes
2 answers

Bulk update using Peewee library

I'm trying to update many records inside a table using Peewee library. Inside a for loop, i fetch a single record and then I update it but this sounds awful in terms of performance so I need to do the update in bulk. Current code look like…
Offofue
  • 159
  • 1
  • 10
5
votes
2 answers

how to initialise a peewee.Model object? __init__() doesn't work

I am not able to initialise the fields of a "peewee.Model" descendant object with the usual init() method. How can I initialise alternatively? import peewee peewee_database = peewee.SqliteDatabase('example.db') class Config(): def…
elemolotiv
  • 181
  • 1
  • 7
5
votes
1 answer

How to get ids from bulk inserting in Peewee?

How to get ids from bulk inserting in Peewee? I need to return inserted ids for create a new array of dict like this: a = [{"product_id": "inserted_id_1", "name": "name1"}, {"product_id": "inserted_id_2", "name": "name1"}] Then I need to insert…
user9377278
5
votes
1 answer

on_delete='CASCADE' seems to have no effect

I have a many-to-many relationship between two models, User and Role, implemented via an intermediary table, UserRoleThrough, which has two ForeignKeyFields: one referencing User, and another referencing Role. As I understand from the docs, ON…
bzrr
  • 1,490
  • 3
  • 20
  • 39
5
votes
1 answer

How to search for substring in textfield in a peewee query

I'm trying to return results that have a particular phrase or word in a textfield of a particular item in a Sqlite database using peewee. My current attempt has been: for key in listOfKeys: foundPun = models.Pun.select().where(key in…
TomHill
  • 614
  • 1
  • 10
  • 26
5
votes
1 answer

Peewee to print generated queries

Is there a way or setting in Peewee where I can get it to print out all the queries being executed in order to debug and understand potential performance issues.
valanto
  • 893
  • 3
  • 8
  • 23
5
votes
1 answer

Peewee ORM - Copying data from multiple database in a main one

I want to copy the data from multiple database, processing them, and after that moving them to a main database. All the databases have the same schema. Even if I open and close the databases, peewee always connect to the same database(the 3rd in the…
user3541631
  • 3,686
  • 8
  • 48
  • 115
5
votes
1 answer

Peewee: how to do ORDER BY ... NULLS (FIRST|LAST)?

The title pretty much sums it up: I would like to specify whether nulls appear first or last in my results. In my specific case, I want to get nulls last with a descending sort order, corresponding to SQL like this: SELECT id, something,…
ASL
  • 263
  • 2
  • 10
5
votes
1 answer

peewee savepoint does not exist

I'm using peewee to interface a MySQL database. I have a list of entries which must be inserted into database and updated in case they're already present there. I'm using create_or_get function for this. I also use threading to speed up the process;…
user37741
  • 370
  • 1
  • 10
5
votes
3 answers

Peewee MySQL server has gone away

I use flask and peewee. Sometimes peewee throws this error MySQL server has gone away (error(32, 'Broken pipe')) Peewee database connection db = PooledMySQLDatabase(database,**{ "passwd": password, "user": user, …
Alexander
  • 1,720
  • 4
  • 22
  • 40