peewee

Peewee MySQL server has gone away

一笑奈何 提交于 2019-12-05 11:53:32
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, "max_connections":None,"stale_timeout":None, "threadlocals" : True }) @app.before_request def before_request(): db.connect() @app.teardown_request def teardown_request(exception): db.close() After mysql error that "MySQL server has gone away (error(32, 'Broken pipe'))", select queries works without problem, but insert,update,delete queries don't work. On insert,update,delete queries

How to do query with `WHERE value IN list` in the Python Peewee ORM?

拥有回忆 提交于 2019-12-05 00:34:07
I'm using the (awesome) Python Peewee ORM for my Flask project, but I now got stuck trying to do a query with a where value in ['a', 'b', 'c'] . I tried doing it as follows: MyModel.select().where(MyModel.sell_currency in ['BTC', 'LTC']) But unfortunately it returns all records in the DB. Any ideas how I could do this? ambi The docs has the answer: x << y will perform x IN y, where y is a list or query . So the final query will look like: MyModel.select().where(MyModel.sell_currency << ['BTC', 'LTC']) Oscar Javier Jimenez You can also do "IN" expressions with a subquery. For example, to get

Can peewee nest SELECT queries such that the outer query selects on an aggregate of the inner query?

佐手、 提交于 2019-12-04 16:31:39
I'm using peewee2.1 with python3.3 and an sqlite3.7 database. I want to perform certain SELECT queries in which: I first select some aggregate (count, sum), grouping by some id column; then I then select from the results of (1), aggregating over its aggregate. Specifically, I want to count the number of rows in (1) that have each aggregated value. My database has an 'Event' table with 1 record per event, and a 'Ticket' table with 1..N tickets per event. Each ticket record contains the event's id as a foreign key. Each ticket also contains a 'seats' column that specifies the number of seats

Python Peewee execute_sql() example

此生再无相见时 提交于 2019-12-04 10:29:51
问题 I am using the Peewee module as the ORM for my project. I read the entire documentation, there is no clear example on how to process the result from db.execute_sql(). I traced the code, only can find db.execute_sql() return back the cursor. Does anyone knows how to process the cursor, such as iterate over it and get back the result from complex select statement. Update: I just found the following source code from peewee folder, it should help me to resolve this problem. class

Why is peewee including the 'id' column into the mysql select query?

一笑奈何 提交于 2019-12-03 12:10:35
问题 I am trying to learn how to use peewee with mysql. I have an existing database on a mysql server with an existing table. The table is currently empty (I am just testing right now). >>> db = MySQLDatabase('nhl', user='root', passwd='blahblah') >>> db.connect() >>> class schedule(Model): ... date = DateField() ... team = CharField() ... class Meta: ... database = db >>> test = schedule.select() >>> test <class '__main__.schedule'> SELECT t1.`id`, t1.`date`, t1.`team` FROM `nhl` AS t1 [] >>>

Accessing remote MySQL database with peewee

半世苍凉 提交于 2019-12-03 08:39:52
问题 I'm trying to connect to a MySQL database on Amazon's RDS using peewee and I can't get it to work. I'm new to databases so I'm probably doing something stupid, but this is what I'm trying: import peewee as pw myDB = pw.MySQLDatabase(host="mydb.crhauek3cxfw.us-west-2.rds.amazonaws.com",port=3306,user="user",passwd="password",db="mydb") class MySQLModel(Model): """A base model that will use our MySQL database""" class Meta: database = myDB class User(MySQLModel): username = CharField() myDB

Reconnecting MySQL on timeout

萝らか妹 提交于 2019-12-03 06:34:29
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 accessing the DB, usually after days of running the program. The error which is raised by peewee is peewee.OperationalError: (2006, 'MySQL server has gone away') The traceback is deep in peewee . I post it here, but as my virtualenv makes filenames too long, I am shortening them: File ".../local/lib/python2.7/site-packages/peewee.py", line 2910, in save

Getting peewee to work on elastic beanstalk

梦想的初衷 提交于 2019-12-02 10:48:09
问题 I'm trying to install the peewee package on an elastic beanstalk instance to control a bottle application. I think the problem is with the MySQL-python dependency, but peewee doesn't load either. My requirements file looks like this: bottle==0.11.6 peewee==2.1.1 MySQL-python I also tried MySQL-python as MySQL-python==1.2.4b4 . For a number of reasons which I believe are summed up here, this doesn't work; peewee isn't installed and I get this error message in the log: 2013-05-18 06:57:08,407

How to select dummy column in peewee?

佐手、 提交于 2019-12-02 04:31:11
问题 how to do select 'blah' as dummycolumn in peewee?? I have tried MyTable.select('blah') but it is not working 回答1: MyModel.select( MyModel.some_field.alias('another_name'), Value('a string literal').alias('a_string'), Value(12345).alias('a_number')) 来源: https://stackoverflow.com/questions/36395229/how-to-select-dummy-column-in-peewee

Getting peewee to work on elastic beanstalk

点点圈 提交于 2019-12-02 04:24:32
I'm trying to install the peewee package on an elastic beanstalk instance to control a bottle application. I think the problem is with the MySQL-python dependency, but peewee doesn't load either. My requirements file looks like this: bottle==0.11.6 peewee==2.1.1 MySQL-python I also tried MySQL-python as MySQL-python==1.2.4b4 . For a number of reasons which I believe are summed up here , this doesn't work; peewee isn't installed and I get this error message in the log: 2013-05-18 06:57:08,407 [INFO] (15947 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Script