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

How to custom the table name in peewee?

I want to define a table which the table name is gobang_server,i write code as follow: class BaseModel(Model): class Meta: database = database class GobangServer(BaseModel): time = DateField(default=datetime.datetime.now()) name…
Sigma65535
  • 361
  • 4
  • 15
12
votes
2 answers

How can I dynamically set the SQLite database file in Peewee?

I'm using Peewee for a project I'm working on, and I'm trying to figure out how to dynamically set the database so that I can use one for production and one for testing. All the examples I've seen have the following line outside of any…
Christopher Shroba
  • 7,006
  • 8
  • 40
  • 68
12
votes
1 answer

Peewee insert if not exist

I am using Python/Mysql and Peewee as ORM. I am stuck in a situation. Suppose i want to insert a row using peewee but check if that row exist skip else insert. Is there any procedure to do so in python using peewee.
Afroz Alam
  • 874
  • 6
  • 19
12
votes
2 answers

Python peewee joins multiple tables

I want to be able to join multiple tables in peewee. However the scenario is a little difficult for me to figure out how to get it to work with peewee. I have the following tables: Ticket TicketCategory TicketBooking Event Here are my models: class…
Atul Bhatia
  • 1,633
  • 5
  • 25
  • 50
12
votes
7 answers

How to create all tables defined in models using peewee

I define a lot of model classes using peewee. ClassName.create_table() can generate the table,but only one table. How could I create all tables using a single statement?
Alexander.Li
  • 133
  • 1
  • 1
  • 5
11
votes
3 answers

Can peewee create a new MySQL database

I've looked through all the docs I could find, and read the source code...and it doesn't seem you can actually create a MySQL database (or any other kind, that I could find) using peewee. If so, that means for any the database I may need to connect…
zaisha
  • 133
  • 1
  • 7
11
votes
6 answers

Custom sqlite database for unit tests for code using peewee ORM

I am trying to implement a many-to-many scenario using peewee python ORM and I'd like some unit tests. Peewee tutorial is great but it assumes that database is defined at module level then all models are using it. My situation is different: I don't…
user1542167
10
votes
3 answers

How to manage a peewee database in a separate module?

I want to have my database implementation in a separate module or class. But I am struggling with a few details. A simple example: from peewee import * db = SqliteDatabase(':memory:') class BaseModel(Model): class Meta: database =…
Feodoran
  • 1,752
  • 1
  • 14
  • 31
9
votes
3 answers

Python peewee.ImproperlyConfigured: MySQL driver not installed

I tried to make a MySQL connection with peewee and followed the tutorial from their website: peewee quickstart So my code is the following: from peewee import * db = MySQLDatabase( host='127.0.0.1', user='root', password='', …
Tamino W.
  • 139
  • 1
  • 1
  • 7
9
votes
2 answers

Do peewee models automatically close the connection?

I am using peewee to access a SQLite DB. I have made a model.py like: from peewee import * db = SqliteDatabase('people.db') class Person(Model): name = CharField() birthday = DateField() is_relative = BooleanField() class Meta: …
Superbest
  • 25,318
  • 14
  • 62
  • 134
9
votes
2 answers

Fetching most recent related object for set of objects in Peewee

Suppose I have an object model A with a one-to-many relationship with B in Peewee using an sqlite backend. I want to fetch some set of A and join each with their most recent B. Is their a way to do this without looping? class A(Model): …
David Berger
  • 12,385
  • 6
  • 38
  • 51
9
votes
3 answers

Reconnecting MySQL on timeout

I have a Python program which runs on background for weeks, and does database queries every once in a while. For that, I am using the ORM peewee (version 2.2.1). I am using MySQL as a backend. Lately I've encountered a recurring problem with…
Bach
  • 6,145
  • 7
  • 36
  • 61
9
votes
2 answers

String matching in Peewee (SQL)

I am trying to query in Peewee with results that should have a specific substring in them. For instance, if I want only activities with "Physics" in the name: schedule = Session.select().join(Activity).where(Activity.name %…
Ben
  • 1,561
  • 4
  • 21
  • 33
8
votes
2 answers

Python: Conditional variables based on whether nosetest is running

I'm running nosetests which have a setup function that needs to load a different database than the production database. The ORM I'm using is peewee which requires that the database for a model is set in the definition. So I need to set a conditional…
Emsu
  • 203
  • 2
  • 4
  • 13
8
votes
3 answers

Peewee ORM JSONField for MySQL

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…
Varun Verma
  • 213
  • 3
  • 12
1
2
3
79 80