flask-sqlalchemy

How do I search for dates registered as an array in Json?

半世苍凉 提交于 2019-12-20 04:24:16
问题 How do I search for dates registered as an array in Json? (PostgreSQL is DB.) Below is the relevant code. ##### 1. Model ##### class Business(db.Model): __tablename__ = 'business' id = db.Column(db.Integer, primary_key=True) sales = db.Column(JSON) ##### 2. Data ##### id=1 sales={'time': ['10:00', '19:00']}, ##### 3. View Query ##### # filter var filter_val = request.json['filter']['value'] # basic query bQuery = Business.query # Filter query if filter_val['sales']['time'][0]: bQuery = bQuery

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) relation “story” does not exist

落爺英雄遲暮 提交于 2019-12-20 04:19:42
问题 So this is my code below. I'm trying to create a database, with one story table. The input comes from the html input part from flask import Flask, render_template from flask_sqlalchemy import SQLAlchemy from flask import request, redirect, url_for app = Flask(__name__) password = input("Your database password: ") app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://adambodnar:{}@localhost/user_stories'.format(password) db = SQLAlchemy(app) class Story(db.Model): id = db.Column(db.Integer,

Flask inherited classes of tables in multiple identical databases using __bind_key__

蹲街弑〆低调 提交于 2019-12-20 03:05:33
问题 I'm trying to build an admin control panel that brings together 4 different ecommerce sites. The sites all have identical database structures (all MySQL). What's Going Wrong? I get 404 Not Found on any order ID and site I put in. No matter how I mix it I can not get any record to come up. Always a 404 and I have no idea why. SO here I am. Code I tried to do this by creating base model classes of every table. Then creating inherited clases of those base classes with a different bind key

Can't load JSON data to jQuery sqlalchemy-datatable

可紊 提交于 2019-12-20 02:36:27
问题 I'm having troubles on loading JSON data to a datatable. Here it is my Python code to perform that (do the query to the database and return that data with jsonify): @users_blueprint.route('/data') def data(): """Return server side data.""" # defining columns columns = [ ColumnDT(User.firstname), ColumnDT(User.lastname), ColumnDT(User.email), ColumnDT(User.urole) ] # defining the initial query users = db.session.query(User).all() # GET parameters params = request.args.to_dict() # instantiating

Minimizing the performance issues of loading a many to many relationship

梦想与她 提交于 2019-12-19 19:41:25
问题 I've been tokenizing an extremely large corpus. Each Unigram can occur in multiple Comments multiple times. I'm storing the Comment.ids in a list that is attached to the Unigram in the database every 250K newly counted unigrams or so. What I'm wondering is if there is a way to extend the comment id list--or a similar data structure--without querying and loading the existing list of comments tied to the Unigram (it can number in the the thousands). Or is there no way around the slow IO? Here

Minimizing the performance issues of loading a many to many relationship

只谈情不闲聊 提交于 2019-12-19 19:41:14
问题 I've been tokenizing an extremely large corpus. Each Unigram can occur in multiple Comments multiple times. I'm storing the Comment.ids in a list that is attached to the Unigram in the database every 250K newly counted unigrams or so. What I'm wondering is if there is a way to extend the comment id list--or a similar data structure--without querying and loading the existing list of comments tied to the Unigram (it can number in the the thousands). Or is there no way around the slow IO? Here

Sqlalchemy - executing raw sql queries

こ雲淡風輕ζ 提交于 2019-12-19 11:28:17
问题 I'm using sqlalchemy in a flask application that connects to multiple databases, using binds as shown here. I want to execute a raw sql query on one of the non-primary databases. I'm trying to use session.execute, as shown here but it executes for the primary db. The API docs state that you can use a parameter: "bind – Optional Engine to be used as the bind". How do I access and specify the bind for the non-primary db and call session.execute to execute a query for that db? Alternately, is

SQLALchemy “after_insert” doesn't update target object fields

戏子无情 提交于 2019-12-19 08:09:29
问题 I have a model (see code below) on which I want to execute a function after an object is inserted that will update one of the object's fields. I'm using the after_insert Mapper Event to do this. I've confirmed that the after_insert properly calls the event_extract_audio_text() handler, and the target is getting updated with the correct audio_text value. However, once the event handler finishes executing, the text value is not set for the object in the database. Code # Event handler def event

In Flask-migrate ValueError: invalid interpolation syntax in connection string at position 15

荒凉一梦 提交于 2019-12-19 05:48:32
问题 I am using flask migrate to for database creation & migration in flask with flask-sqlalchemy. Everything was working fine until I changed my database user password contains '@' then it stopped working so, I updated my code based on Writing a connection string when password contains special characters It working for application but not for flask-migration, Its showing error while migrating i.e on python manage.py db migrate ValueError: invalid interpolation syntax in u'mysql://user:p%40ssword

How to query JSON Array in Postgres with SqlAlchemy?

我怕爱的太早我们不能终老 提交于 2019-12-19 03:24:08
问题 I have a SqlAlchemy model defined from sqlalchemy.dialects.postgresql import JSONB class User(db.Model): __tablename__ = "user" id = db.Column(db.Integer, primary_key=True) nickname = db.Column(db.String(255), nullable=False) city = db.Column(db.String(255)) contact_list = db.Column(JSONB) created_at = db.Column(db.DateTime, default=datetime.utcnow) def add_user(): user = User(nickname="Mike") user.contact_list = [{"name": "Sam", "phone": ["123456", "654321"]}, {"name": "John", "phone": [