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

peewee vs sqlalchemy performance

I have 2 simple scripts: from sqlalchemy import create_engine, ForeignKey, Table from sqlalchemy import Column, Date, Integer, String, DateTime, BigInteger, event from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.engine import…
Bdfy
  • 23,141
  • 55
  • 131
  • 179
7
votes
1 answer

Defining virtual fields in peewee

Suppose I have a peewee model which looks more or less as follows: class MyModel(peewee.Model): a = peewee.IntegerField() b = peewee.IntegerField() And I wish to add a property to that model as follows: @property def diff(self): …
Bach
  • 6,145
  • 7
  • 36
  • 61
7
votes
1 answer

Is it possible to make sql join on several fields using peewee python ORM?

Assuming we have these three models. class Item(BaseModel): title = CharField() class User(BaseModel): name = CharField() class UserAnswer(BaseModel): user = ForeignKeyField(User, 'user_answers') item = ForeignKeyField(Item,…
Yaroslav Melnichuk
  • 820
  • 1
  • 11
  • 15
7
votes
1 answer

Peewee getting column after join

I am unable to read the column of another table which is joined. It throws AttributeError class Component(Model): id = IntegerField(primary_key=True) title = CharField() class GroupComponentMap(Model): group = ForeignKeyField(Component,…
Rishabh
  • 1,185
  • 1
  • 12
  • 28
7
votes
3 answers

How to use Update query in Flask Peewee?

Hi I am using Flask Peewee and trying to update merchant_details model but it is not working. Following is the error I am getting: AttributeError: 'SelectQuery' object has no attribute 'update' mdetails =…
Rohit Dhiman
  • 208
  • 2
  • 3
  • 8
7
votes
1 answer

Allowing null value in Peewee

I'm trying to allow null values in some columns of a MySQL database using peewee with bottle. Looking at the docs here I thought that would be quite easy. I set up a class like this: class TestClass(MySQLModel): Title = pw.CharField(null =…
Alex S
  • 4,726
  • 7
  • 39
  • 67
6
votes
1 answer

Return max value in a column with peewee

I have a table called jobs with a column called job_num. How do i return the maximum value of the integers in that column? I have tried result = Job.select(max(Job.job_num)) I have also tried a few different combinations such as result =…
Finchy70
  • 441
  • 9
  • 25
6
votes
2 answers

How do I disallow a classmethod from being called on an instance?

I have been looking a the source code for peewee, specifically Model and the update function: https://github.com/coleifer/peewee/blob/a33e8ccbd5b1e49f0a781d38d40eb5e8f344eee5/peewee.py#L4718 I don't like the fact that this method can be called from…
Harald Nordgren
  • 11,693
  • 6
  • 41
  • 65
6
votes
1 answer

peewee - Define models separately from Database() initialization

I need to use some ORM engine, like peewee, for handling SQLite database within my python application. However, most of such libraries offer syntax like this to define models.py: import peewee db = peewee.Database('hello.sqlite') class…
Croll
  • 3,631
  • 6
  • 30
  • 63
6
votes
2 answers

Can I somehow query all the existing tables in peewee / postgres?

I am writing a basic gui for a program which uses Peewee. In the gui, I would like to show all the tables which exist in my database. Is there any way to get the names of all existing tables, lets say in a list?
handris
  • 1,999
  • 8
  • 27
  • 41
6
votes
1 answer

Multiple SQLite connections to a database in :memory:

Is it possible to access an in-memory SQLite database from different threads? In the following sample code I create a SQLite database in memory and create a table. When I now go to a different execution context, which I think have to do when I go to…
Randrian
  • 1,055
  • 12
  • 25
6
votes
1 answer

Selecting distinct values from a column in Peewee

I am looking to select all values from one column which are distinct using Peewee. For example if i had the table Organization Year company_1 2000 company_1 2001 company_2 2000 .... To just return unique values…
kyrenia
  • 5,431
  • 9
  • 63
  • 93
6
votes
3 answers

Using multiple databases with peewee

I'm writing a "multi tenant" application. It's going to be hosted on different subdomains, and based on which subdomain it's hosted, it should use a different database. Is it possible to define, in execution time, which database peewee should be…
g3rv4
  • 19,750
  • 4
  • 36
  • 58
6
votes
1 answer

Can I add methods and attributes to a class derived from peewee.Model

I am working on an app with Cherrypy and Peewee, and I would like to know if my approach is good or wrong and dangerous. All the examples of Peewee classes that I found have only the Meta subclass and the Field attributes. I have never found an…
stenci
  • 8,290
  • 14
  • 64
  • 104
6
votes
1 answer

How to use peewee limit()?

With Peewee I'm trying to use limit as follows: one_ticket = Ticket.select().limit(1) print one_ticket.count() This prints out 5 however. Does anybody know what's wrong here?
kramer65
  • 50,427
  • 120
  • 308
  • 488