Tagged Questions
0
votes
0answers
2 views
SQLAlchemy hybrid_property expression with foreign keys
I'm kind of new to SQLAlchemy, and a bit confused about how to create a hybrid_property expression when there are foreign keys involved. Here are the declarative classes I'm using:
class ...
0
votes
1answer
10 views
How do I access the data in a join SQLAlchemy
Given the following sess query:
sess = DBSession()
reg = sess.query(Registration,Schedule).join(Schedule,Registration.classcode==Schedule.classcode).filter(Registration.registration_no==reg_id)
...
1
vote
0answers
20 views
Can I use an ORM class as association table for a many-to-many realtionship in SQLAlchemy?
I want to collect statistical information for songs (rating, play-count, last time played) from a couple of players over different devices and from different users. I use Python and SQL Alchemy.
I ...
1
vote
1answer
24 views
SQLAlchemy: find child objects in a relationship with NULL parent
I have a class which has a parent-child relationship:
Base = declarative_base()
class Parent(Base):
__tablename__ = "parent_table"
id = Column(Integer, primary_key=True)
children = ...
0
votes
1answer
14 views
SQLAlchemy Linear One-to-One Relationship
I have two classes mapped to two tables respectively.
Ex:
Obj 1: ID (PK), KEY (String(20))
Obj 2: ID (PK), obj_1_id (FK), value (String(20))
I would like to be able to perform obj_1.value = *val*, ...
0
votes
0answers
23 views
Python Sqlalchemy “select where ” issue [on hold]
There is a table:
mysql> select * from verify ;
+----+----------------------------------+----------+------+
| id | user_id | mask | bind |
...
3
votes
3answers
18 views
sqlalchemy, select using reverse-inclusive (not in) list of child column values
I have a typical Post / Tags (many tags associated with one post) relationship in flask-sqlalchemy, and I want to select posts which aren't tagged with any tag in a list I provide. First, the models I ...
2
votes
1answer
18 views
Are there serious performance differences between using pickleType and relationships?
Let's say there is a table of People. and let's say that are 1000+ in the system. Each People item has the following fields: name, email, occupation, etc.
And we want to allow a People item to have ...
1
vote
1answer
24 views
How to subclass the default `db.Model` to use as a custom `Base` with SQLAlchemy
I have a flask application spread across modules with blueprints.
Each module/blueprint has its own models.py file where models are defined.
With my desktop applications, using SQLAlchemy API ...
2
votes
1answer
29 views
Flask: Preferred way to manipulate view arguments?
I'm creating REST API with Flask & have a question related to manipulating the arguments of the view questions. I have currently two resources, "Survey" and "SurveyStep", accessible through:
...
1
vote
1answer
11 views
How to create (in Flask using flask-SA etc.) an SQLite DB file with metadata.create_all(..)
I have a flask application spread across modules with blueprints.
Each module/blueprint has its own models.py file where models are defined.
When the application runs, I would like SQLAlchemy to ...
1
vote
1answer
15 views
Why does SQLAlchemy insert expression values() method function differently when executing in one statement or two?
I'm working through the SQLAlchemy core tutorial (http://docs.sqlalchemy.org/en/rel_0_8/core/tutorial.html) and found a strange behavior. In the Insert Expressions section they first create a basic ...
0
votes
1answer
36 views
How to union two subqueries in SQLAlchemy and postgresql
Raw SQL desired:
SELECT
id
FROM
(SELECT some_table.id FROM some_table WHERE some_table.some_field IS NULL) AS subq1
UNION
(SELECT some_table.id WHERE some_table.some_field IS NOT NULL)
...
0
votes
1answer
8 views
In SQLAlchemey, Can I add new object to the relationship object?
Can I add new object to the relationship object?
Class Parent():
id = Column(Integer, primary_key=True)
name = Column(String(10))
child = relationship('Child', backref='parent', ...
1
vote
1answer
37 views
How to create table defined in sqlalchemy schema in the Heroku server?
I have a very simple app that I'm building with Python, SQLAlchemy, PostgreSQL and Turbogears 2.3.
The app works in my local machine, where I use SQLite. However, when I upload it to Heroku, I don't ...
0
votes
1answer
15 views
nosetests not running all the tests in a file
i run
nosetests -v --nocapture --nologcapture tests/reward/test_stuff.py
i get
----------------------------------------------------------------------
Ran 7 tests in 0.005s
OK
the tests ...
1
vote
2answers
20 views
SQLAlchemy foreign key lazy loading
I have a basic one to many relationship:
class Term(Base):
__tablename__ = 'term'
id = Column(Integer, primary_key=True)
class Node(Base):
__tablename__ = 'node'
id = Column(Integer, ...
0
votes
1answer
64 views
+50
Can I use dynamic relationships (or VIEWS) in SQLAlchemy ORM?
I'm looking for a way, so that a relationship only uses some rows of a table, instead of the whole table.
I was thinking about using a view instead of the original table as base for the ...
0
votes
1answer
23 views
Pyramid Framework including models.py from addon to main application
I am trying to create a pyramid framework authentication addon/Plugin. The Plugin needs to have a database that stores user logins and other data, so if a user uses my addon his database must contain ...
0
votes
1answer
42 views
Script is taking too long
so here is my script:
import glob,os, csv
from sqlalchemy import *
count = 0
served_imsi = []
served_imei = []
served_msisdn = []
location_area_code = []
routing_area = []
cell_identity = []
...
1
vote
1answer
24 views
Struggling with 'synchronisation' between Session's in SQLAlchemy
I've a created delete_entity function which delete's entities and I've a function which tests this functions.
#__init__.py
engine = create_engine('sqlite://:memory')
Session = ...
0
votes
1answer
21 views
hybrid property with join in sqlalchemy
I have probably not grasped the use of @hybrid_property fully. But what I try to do is to make it easy to access a calculated value based on a column in another table and thus a join is required.
So ...
0
votes
0answers
51 views
Better way to filter join against a list of values in SQLAlchemy?
In my schema, a Hardware item may have zero or more Mods recorded against it. I'm trying to filter a query based on an exact match against a list of mods. For example, I might want to filter for ...
0
votes
1answer
38 views
SQLAlchemy: Unable to get the first item of query
I'm currently learning SQLAlchemy, and i found this strange thing. I was experimenting with a table which stores a person's name and address, and to get them i use this:
session.query(User)
And to ...
1
vote
0answers
29 views
SQLAlchemy hybrid_property and expressions
I am working on storing some data produced by an external process in a postgres database using sqlalchemy. The external data has several dates stored as strings that I would like to use as datetime ...
0
votes
0answers
28 views
SQLAlchemy Insert into Table
So, I have multiple arrays with multiple values, I want to insert those values into a Table previously created.
The code I'm writing is this:
#!/usr/bin/env python
import glob,os, csv
from ...
1
vote
0answers
42 views
SQLAlchemy + SQLite Locking in IPython Notebook
I'm getting an OperationalError: (OperationalError) database is locked error when connection via SQLAlchemy in an IPython notebook instance and I'm not sure why.
I've written a Python interface to a ...
2
votes
1answer
35 views
sqlalchemy query after flushed delete
Given this piece of code:
record = session.query(Foo).filter(Foo.id == 1).first()
session.delete(record)
session.flush()
has_record = session.query(Foo).filter(Foo.id == 1).first()
I think the ...
1
vote
1answer
37 views
SQLAlchemy force Left Join
I have a little problem. I have two SQL tables (ip and client) bound by a third one (ip_client). I did not use the many to many relationships shipped with SQLAlchemy because of complex filtering ...
0
votes
1answer
10 views
Filtering SQLAlchemy query on attribute_mapped_collection field of relationship
I have two classes, Tag and Hardware, defined with a simple parent-child relationship (see the full definition at the end).
Now I want to filter a query on Tag using the version field in Hardware ...
1
vote
1answer
45 views
flask-sqlalchemy: Query for records in one table with NO related records in another table (or records of a certain value)
I am writing a simple app that helps people call voters. I don't want my volunteers to bug any voter more than once. How can I get a list of voters who have not been called yet? I'm using flask with ...
1
vote
1answer
51 views
Pyramid, sqlalchemy dbsession
When building a Pyramid app (SQLAlchemy as ORM) I'm hit with a problem I can't seem to figure out.
Project built with SQLAlchemy scaffold, so all the setup is proper.
When I use DBSession variable in ...
1
vote
1answer
47 views
Transactions and sqlalchemy
I am trying to figure out how to insert many (in the order of 100k) records into a db using sqlalchemy in python3. Everything points to using transactions, however I am slightly confused as to how ...
1
vote
0answers
31 views
sqlalchemy query on deleted object
I recently write a client testing program to test my server. In the test, I start using orm to delete existing objects (row) in the database. Then I send in a sequence of commands to the server to ...
0
votes
0answers
25 views
Flask-SQLAlchemy integration tests can't find a way to rollback changes
I'm trying to learn flask technology stack and for my application I'm using Flask-SQLAlchemy. Everything works perfect, but I'm struggling with writing integration tests. I don't want to use SQLite ...
0
votes
1answer
19 views
How to use the filter operater of like in sqlalchemy?
I want to query data from database use sqlalchemy, and the code is below:
session.query(Person).filter(Person.name.like("%tom%")).all()
but this is case sensitive, in other words, the params of ...
2
votes
0answers
25 views
Understanding SQLite Thread Pooling Behavior in SQLAlchemy
list_of_some_class_dictionaries = [{'foo': foo, 'bar': bar}, ...]
engine.execute(SomeClass.__table__.insert(), list_of_some_class_dictionaries)
This breaks using NullPool with a SQLite file database ...
0
votes
1answer
47 views
How to login in flask?
I would like to know how to login a user in flask by comparing usernames and passwords from data base.
If error is the username doesnt exist flash "User doesnt exist"
if that password doesnt match ...
0
votes
0answers
45 views
SQL-Alchemy Association Table does not work as planned
I'm currently writing Database-Code for my Flask-Application, and while most of my code works without problems, there is one Association Table I can't get to work and I'm running out of ideas how to ...
0
votes
1answer
31 views
SQLAlchemy: is it possible to store session wide properties
I am working on a software that manipulates SQL tables using SQLALchemy.
Each operation a user will perform (insertion, modification, deletion) must be logged on a specific LOG table.
The log table ...
0
votes
0answers
22 views
SQLAlchemy: One-To-Many Relationship through secondary table without primary ID
I am trying to create SQLAlchemy model objects through reflection.
The database is used by a Spring application that uses Hibernate for ORM.
One of the model classes has an attribute that is annotated ...
1
vote
2answers
38 views
Getting a parents children through a backref attribute via sqlalchemy relationship causes unnecessary flush
I have a sqlalchemy relationship like this (trimmed for simplicity):
class Parent(Base):
__tablename__ = 'Parent'
name = Column(String, nullable=False)
def __init__(self, name)
self.name = ...
1
vote
0answers
50 views
'No such table' SQL-Alchemy Error with Flask-Admin
I'm trying to configure flask admin to provide an interface for the models in different blueprints.
app/__init__.py
def configure_extensions(app):
# flask-sqlalchemy
from .extensions import ...
1
vote
1answer
27 views
How to handle multiple requests without SQLAlchemy crashing/raising exceptions?
Context: I'm working on a Flask app, running on CherryPy, DB handled using SQLAlchemy ORM.
Problem:
The app runs fine and does everything I want, however, if I have a page which fetches some data ...
0
votes
1answer
20 views
How to wrap a column in a CAST operation
I have an MSSQL database with tables which I cannot change and only ever interact with it as read only (SELECT statements). I am using sqlalchemy. What I need to do is to automatically wrap specific ...
1
vote
0answers
28 views
How does a sqlalchemy object get detached?
I have code structured something like this:
project
--app
----utils
------util.py
----__init__.py
----models.py
--tests
----__init__.py
Within tests/__init__.py I have code that initializes the ...
1
vote
1answer
23 views
SQLAlchemy Error: This operation requires only one Table or entity be specified as the target
I'm trying to delete a row and its parent row from a table:
This is my code:
result = session.query(TableA, TableB). \
join(TableB). \
filter(TableA.ColumnA == 'something').delete()
Unfortunately ...
0
votes
0answers
22 views
MySQLdb performance and sqlalchemy
The example of the MySQLdb:
import MySQLdb
from datetime import datetime
def instantiate():
global engine
db = MySQLdb.connect(host="127.0.0.1",user="root",passwd="dfdf",db="TEST")
...
0
votes
0answers
36 views
Querying by a list of attributes, SQLAlchemy
Is it possible to make queries that are filtered by membership in a list in SQLAlchemy? If so, would it generally be more efficient than my alternative?
This is how the code is currently structured. ...
0
votes
0answers
26 views
fixtures + sqlalchemy orm working example
i am trying to load data when running unit tests using the two python packages fixture and sqlalchemy.
i can't seem to find an example on how exactly to do this, however.
i ended up here but this ...