flask-sqlalchemy

How to do a select query using flask and sqlalchemy?

泄露秘密 提交于 2019-12-11 07:29:24
问题 I'm new using flask and SQLAlchemy, I have a database in postgress, this database have table "data" 200 records, I want to do a Select statment but when I do it always give me the same error, this my code: This is my model.py from sqlalchemy import Column, ForeignKey, Integer, String from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Data(Base): __tablename__ =

Generating models for Flask-AppBuilder using flask-sqlqcodegen

情到浓时终转凉″ 提交于 2019-12-11 06:59:51
问题 I'm a beginner in Python and Flask ecosystems, trying to create a small proof-of-concept Web application for a research project. I'm using Debian Linux 7.9, PostgreSQL 9.5, SQLAlchemy (latest) and Flask-AppBuilder (latest). Since creating models manually is tedious and error-prone, I searched the mighty Internet and discovered the flask-sqlacodegen project (note that this a fork of sqlacodegen with improved features for Flask users). I installed flask-sqlqcodegen from GitHub (cloned repo and

Adding count of total rows through Marshmallow with @post_dump?

烂漫一生 提交于 2019-12-11 06:45:30
问题 I need to add the quantity of rows returned in this query: queryPostgres = db.text(""" SELECT *, COUNT(*) OVER () as RowCount FROM ( SELECT * , ( 3958.75 * acos(sin(:lat1 / 57.2958) * sin( cast(latitude as double precision) / 57.2958) + cos(:lat1 / 57.2958) * cos( cast(latitude as double precision) / 57.2958) * cos( cast(longitude as double precision) / 57.2958 - :lon1/57.2958))) as distanceInMiles FROM "job" ) zc WHERE zc.distanceInMiles < :dst ORDER BY zc.distanceInMiles LIMIT :per_page

Using Flask SQLAlchemy from worker threads

▼魔方 西西 提交于 2019-12-11 06:17:02
问题 I have a python app that uses Flask RESTful as well as Flask SQLAlchemy. Part of the API I'm writing has the side effect of spinning off Timer objects. When a Timer expires, it executes some database queries. I'm seeing an issue in which code that is supposed to update rows in the database (a sqlite backend) is actually not issuing any UPDATE statements. I have verified this by turning the SQLALCHEMY_ECHO flag on to log the SQL statements. Whether or not the code works seems to be random.

how can i use a string to to represent an sqlalchemy object attribute?

允我心安 提交于 2019-12-11 06:05:07
问题 I am writing a Flask application with SQLalchemy and WTForms. Trouble with database updates... I have many object table fields I am trying to update. so I started with this... # this works great but needs many lines of code event.evt_num = form.evt_num.data event.evt_name = form.evt_name.data event.evt_location = form.evt_location.data event.evt_address = form.evt_address.data event.evt_city = form.evt_city.data event.evt_state = form.evt_state.data ... While the above snippet works, in

Access a column from a Flask-SQLAlchemy paginate result

假如想象 提交于 2019-12-11 05:59:46
问题 My Document model has a text_location column, a file path that I need to read from after querying. I am using paginate when querying. That is created through this code: class Document(db.Model): id = db.Column(db.Integer, primary_key=True) text_location = db.Column(db.String) page_views = Document.query.paginate(page, 1, False) I can display {{ page_views }} correctly in the template. However, if I try to open text_location , I get "Pagination" object has no attribute "text_location" . with

Python flask-SQLAlchemy query time out error

。_饼干妹妹 提交于 2019-12-11 05:56:31
问题 I am using flask-sqlalchemy library in python to management my database(my sql). However when I test query, it give me this error: sqlalchemy.exc.TimeoutError: QueuePool limit of size 5 overflow 10 reached, connection timed out, timeout 10 Test code is simple: def test_query(self, i): random = str(i) result = Dao.query_user_by_nick("kael") print("end query at %s, id: %s" % (datetime.datetime.now(), random), "\n result: " + str(len(result))) threads = [] for i in range(0,100): test = threading

How to concatenate unrelated queries in SqlAlchemy

假如想象 提交于 2019-12-11 05:46:52
问题 How can I concatenate sqlalchemy queries with no relation and sort by date? e.g. These are the models: Human Car Tree And they all have the column created . Here are the queries: q1 = session.query(Human.created.label('created'), Human).filter(...) q2 = session.query(Car.created.label('created'), Car).filter(...) q3 = session.query(Tree.created.label('created'), Tree).filter(...) Now I want to concatenate these 3 queries and order_by date. The expected result would be something like: date |

multi-helper table for many-many-many-… relationship in flask-sqlalchemy

狂风中的少年 提交于 2019-12-11 05:39:04
问题 Many questions were about many to many problem which could be solved with a helper table. But how about many-many-many... If there existed a more elegant way to handle this problem. I tried to put an issue on https://github.com/pallets/flask-sqlalchemy/issues/710. But this guy reject to answer the question, or I think it's a feature instead of question.But anyway, he closed my issue. Here is the minimal sample code, which I would like to handle the relationship among A,B,C in this way. Helper

Convert SQL to SQL alchemy

倾然丶 夕夏残阳落幕 提交于 2019-12-11 05:27:48
问题 I am new to Flask SQl alchemy; Though i understand that alchemy abstracts the sql syntax and makes things easy while creating models; there could be times when we want to visualize data in the front end in a very specific way. I have the following query which i would like to use using alchemy using session.query and filter and possibly grouping. My query reads: mysql> SELECT status, COUNT(id) FROM bar_baz where not name = 'Foo' and not name = 'Bar' GROUP BY status select (select COUNT(id)