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
8
votes
1 answer

Union over fields having different names using peewee

I'm using peewee as ORM and have two classes like this: class A(Model): name = CharField() body = TextField() class B(Model): title = CharField() body = TextField() I would like to get all entries from A and B whose title/name…
Achim
  • 15,415
  • 15
  • 80
  • 144
8
votes
2 answers

Deleting multiple records in a table using join in Peewee?

Since joining is not allowed on "delete" queries in Peewee, what is the best way to delete all records in table_2 that match a specific condition in related table_1? Using a simple example, I want to achieve the equivalent of this: DELETE…
David
  • 110
  • 1
  • 7
8
votes
3 answers

In Peewee I have a datetime field defaulted to datetime.datetime.now(). But when inserted, it takes the time the server was started. Why

When I insert a row, the field is filled with the time when the server was started not the time when the row was inserted. Why is this happening and what is the solution? BTW I am using SQLite. class LOG(peewee.Model): id =…
Sampad Mohanty
  • 111
  • 1
  • 1
  • 6
8
votes
3 answers

How to get sql query from peewee?

Simple peewee example: MySQL DB "Pet" with autoincrement "id" and char-field "name". Doing my_pet = Pet.select().where(name == 'Garfield') With .sql() we get the sql interpretation. How to get the raw sql query from: my_pet =…
Stefan Weiss
  • 461
  • 1
  • 6
  • 20
8
votes
3 answers

Python-peewee get last saved row

is there a way how to obtain last saved row in database while using peewee with all its attributes? Let's say I do this: user = User.create( email = request.json['email'], nickname = request.json['nickname'], password =…
skornos
  • 3,121
  • 1
  • 26
  • 30
8
votes
0 answers

"Sometimes" getting an InterfaceError on PostgreSQL with Peewee ORM

I'm building a website using the Python Flask framework and the Peewee ORM with PostgreSQL 9.3. So far things are going pretty well, but I now run into some trouble. I sometimes get an InterfaceError: connection already closed. The code on which I…
kramer65
  • 50,427
  • 120
  • 308
  • 488
8
votes
1 answer

Python peewee - select from multiple tables

I am trying to select two fields from separate tables using peewee. I believe my issue is with iterating over the resulting object. I have the following code in Python: sHeader_Value = (System_Headers .select(System_Headers.SystemHeader_Name,…
James Mnatzaganian
  • 1,255
  • 1
  • 17
  • 32
7
votes
3 answers

Searching for items in a many-to-many relationship

I'm currently writing an application that allows one to store images, and then tag these images. I'm using Python and the Peewee ORM (http://charlesleifer.com/docs/peewee/), which is very similar to Django's ORM. My data model looks like this…
Andrew D
  • 73
  • 5
7
votes
3 answers

Finding source of PyMySQL error - err.InterfaceError("(0, '')")

I am a Discord bot developer, and recently completed an order. The client upon setting the application up on their server initially had no issues, but according to them after running for "about three hours" the program begins spitting a specific…
Sparrow
  • 91
  • 2
7
votes
2 answers

python multiprocessing + peewee + postgresql fails with SSL error

I am trying to write a Python model which is capable of doing some processing in a PostgreSQL database using the multi-threading module and peewee. In single core mode the code works, however, when I try to run the code with multiple cores I am…
Eelco van Vliet
  • 1,198
  • 12
  • 18
7
votes
1 answer

Get list of query results in Peewee

Considering to switch from SQLAlchemy to peewee but have a fundamental question as I'm not able to find an example of this. I want to execute a query that returns a list of the matched objects. What works is get which returns a single…
valanto
  • 893
  • 3
  • 8
  • 23
7
votes
4 answers

Is there a way to query.all() in peewee?

I need to transfer all data from an SQL table to an html page. In SQLAlchemy I would do something like this: class Author(db.Model): id = db.Column(db.Integer, primary_key=True) first = db.Column(db.String(80)) last =…
T1ber1us
  • 161
  • 1
  • 2
  • 6
7
votes
2 answers

peewee and peewee-async: why is async slower

I am trying to wrap my head around Tornado and async connections to Postgresql. I found a library that can do this at http://peewee-async.readthedocs.io/en/latest/. I devised a little test to compare traditional Peewee and Peewee-async, but somehow…
kurtgn
  • 8,140
  • 13
  • 55
  • 91
7
votes
1 answer

How to query dates range using peewee?

I have SQLite database with tables that contains dates. I want ot select records that falls in particular range, but I fail to write correct query. # This query returns nothing rows = model.select().where( …
SS_Rebelious
  • 1,274
  • 2
  • 19
  • 35
7
votes
1 answer

peewee instance matching query does not exist

I have the following code where I'm querying my peewee database. I'm getting an error in the for loop on the line that has term.sets_term_id. This is the error TermsDoesNotExist: Instance matching query does not exist: If I do vars(term) then…
Rafa
  • 3,219
  • 4
  • 38
  • 70
1 2
3
79 80