Re: [sqlalchemy] simple relationship join ends up in 1 s

2014-09-11 Thread Simon King
The query that you are doing: customerorders = sqlsession.query(Customerorder)\ .join(Itemsbought.order)\ .all() probably doesn't do what you intend. In particular, it doesn't populate the Customerorder.itemsbought collection. So when you iterate over customerorders and access the "

Re: [sqlalchemy] Re: Specify Protected keywords in new SQL Dialect

2014-09-19 Thread Simon King
I don't know about documentation, but a quick look at the source suggests that you can set the "reserved_words" property on your identifier preparer: https://bitbucket.org/zzzeek/sqlalchemy/src/master/lib/sqlalchemy/dialects/postgresql/base.py#cl-476 https://bitbucket.org/zzzeek/sqlalchemy/src/ma

Re: [sqlalchemy] Self-Referential Association Relationship SQLalchemy

2014-09-24 Thread Simon King
Could you show the whole model and table definition? I've lost track of exactly what you've written. Thanks, Simon On Wed, Sep 24, 2014 at 11:15 AM, Mohammad Reza Kamalifard wrote: > thanks Mike > with new to_contacts relationship i have new error > ArgumentError: Could not locate any relevant

Re: [sqlalchemy] Self-Referential Association Relationship SQLalchemy

2014-09-24 Thread Simon King
7;, >backref = 'from_contacts') > > class ContactRelation(db.Model): > __tablename__ = 'contactrelation' > id = db.Column(db.Integer, primary_key=True) > from_contact_id = db.Column(db.Integer, db.ForeignKey('contact.id')) > to_c

Re: [sqlalchemy] Self-Referential Association Relationship SQLalchemy

2014-09-25 Thread Simon King
; Thanks, > I want to create a relationship between two contact object and add more data > like relation type to the relation table. > For example Contact with contact id 1 and contact id 2 has friend > relationship type and some more data. > Exactly i want a self associa

Re: [sqlalchemy] Handling detached instances

2014-09-30 Thread Simon King
On Tue, Sep 30, 2014 at 8:52 AM, tonthon wrote: > Hi, > > I'm using dogpile cache to store objects in a redis database, here's the > sample function I use for my tests : > @region.cache_on_arguments() def get_my_model(id): return DBSession().query(Model).get(id) > > I retrieve mo

Re: [sqlalchemy] Any examples of using session events?

2014-10-14 Thread Simon King
On Tue, Oct 14, 2014 at 12:53 PM, Eugene Prikazchikov wrote: > I am struggling to understand how to use session events. I want to track > inserts&updates in some model and depending on certain criteria modify > objects from other model. Judging from docs, I cannot use before_update and > similar M

Re: [sqlalchemy] Child count as an object property

2014-10-16 Thread Simon King
"GROUP BY 1" means "group by the first column in the select", doesn't it? Which in this case would be parent_id. Simon On Thu, Oct 16, 2014 at 4:34 PM, Michael Bayer wrote: > > What's the group_by 1 do? Didn't you mean group_by parent_id? > > > Sent from my iPhone > >> On Oct 16, 2014, at 10:29

Re: [sqlalchemy] creating engine in python, "No module named 'MySQLdb'

2014-10-28 Thread Simon King
On Tue, Oct 28, 2014 at 5:23 PM, Larry Green wrote: > Simple question. > > Configuration= > Anaconda3 > Python 3.4 and many various 3rd party modules. > sqlalchemy 0.9.4 verified installed > Windows 7 x64 machine. > > The first part of the sqlalchemy tutorial states do the following in python: > >

Re: [sqlalchemy] [Q] Semantic difference in not equal operator

2014-10-31 Thread Simon King
At a guess, I would say that the Python code "Foo.bar != bar" means that you are looking for Foo objects that aren't related to bar. This includes Foos that are related to a *different* Bar instance, as well as Foos that aren't related to *any* bar instance. In sql terms, foo.bar_id != bar.id OR

Re: [sqlalchemy] [Q] Semantic difference in not equal operator

2014-11-03 Thread Simon King
> On 3 Nov 2014, at 13:08, Ladislav Lenart wrote: > > Hello. > > >> On 31.10.2014 18:33, Simon King wrote: >> At a guess, I would say that the Python code "Foo.bar != bar" means >> that you are looking for Foo objects that aren't related to

Re: [sqlalchemy] Re: Problem installing

2014-11-13 Thread Simon King
This is the important bit from your install log: Processing SQLAlchemy-0.9.8-py3.4.egg removing 'c:\python34\lib\site-packages\SQLAlchemy-0.9.8-py3.4.egg' (and everything under it) Extracting SQLAlchemy-0.9.8-py3.4.egg to c:\python34\lib\site-packages SQLAlchemy 0.9.8 is already the active version

Re: [sqlalchemy] Why sqlalchemy (version 0.9.7) can't be imported in python(version 2.7.2) command line

2014-11-18 Thread Simon King
On Tue, Nov 18, 2014 at 10:07 AM, Xiaohua Zou wrote: > > I have install python 2.7.2 and sqlalchemy 0.9.7, but I found that python > can't import sqlalchemy. > And I found that sqlalchemy folder is not copy to > ...\python\Lib\site-packages\, I think that's why it can't be imported by > python, i

Re: [sqlalchemy] Why sqlalchemy (version 0.9.7) can't be imported in python(version 2.7.2) command line

2014-11-19 Thread Simon King
OT copied to > ..\python\Lib\site-packages\. > > I suspect setup.py may have some problems. Attached are the SQLAlchemy > package and setup.py file. > > Could you please help me to look into it? > Thanks in advance! > > Best Regards, > > > 在 2014年11月18日星期二UTC+8下午

Re: [sqlalchemy] Re: Generate a column value and store it.

2014-12-01 Thread Simon King
On Mon, Dec 1, 2014 at 4:09 AM, Steven DeVries wrote: > @classmethod > set_name(cls, instance): > prefix = > cls.session.query(Prefix.name).filter_by(pk=instance.prefix_fk).scalar() > item = > cls.session.query(Item.name).filter_by(pk=instance.prefix_fk).scalar() >

Re: [sqlalchemy] create a relationship to the "latest" item (i.e. many-to-one, where the 'one' is ordered)

2014-12-05 Thread Simon King
On Fri, Dec 5, 2014 at 1:30 AM, Jonathan Vanasco wrote: > This is a simplified example of my issue. I wrote a detailed example, but > it might be too confusing. > > There are three classes: > > Entity > """only has one of user_id or username""" > id > user_id >

Re: [sqlalchemy] no such table error

2014-12-11 Thread Simon King
On Thu, Dec 11, 2014 at 12:23 AM, wrote: > I had an issue while running my flask application: > https://github.com/mitsuhiko/flask/issues/1274 > > The suggested workaround is to add /home/sam to sys.path, however, if I > remove the "pantry." part from the import statements and execute from within

Re: [sqlalchemy] AmbiguousForeignKeysError or CircularDependencyError

2014-12-11 Thread Simon King
On Thu, Dec 11, 2014 at 2:44 PM, Boris Sabatier wrote: > Hi, > > I have a problem to do the model I need. > I have 3 types of object : Category, Picture and Video. > > All of these types have some common part, like a name. > Also I want to be able to select all object with a name like "bar" > (Cat

Re: [sqlalchemy] loop over two large tables to join them

2015-01-01 Thread Simon King
> On 31 Dec 2014, at 16:25, Mehdi wrote: > > Hi > What would be the most efficient way to loop over a large table(>12 rows) > and base on some conditions find the match on another table(>7 rows)? > Actually i'm working on a given db which there are TableA with 14 fields and > more than

Re: [sqlalchemy] loop over two large tables to join them

2015-01-04 Thread Simon King
:( > Thanks again. > > > On Friday, January 2, 2015 2:41:43 AM UTC+3:30, Simon King wrote: > > On 31 Dec 2014, at 16:25, Mehdi wrote: > > > > Hi > > What would be the most efficient way to loop over a large table(>12 > > rows) and base on some condit

Re: [sqlalchemy] session query and column names

2015-01-13 Thread Simon King
On Mon, Jan 12, 2015 at 10:45 AM, Mehdi wrote: > Hi > I want to make a query with given filters received from client side. client > side sends a json array like this: > [ > "0DA": {conditionType: null, column: "serialNumber", operator: > "GREATER_THAN", value: 50}, > "1DG": {conditionType:

Re: [sqlalchemy] SQL join between two tables from two databases

2015-01-21 Thread Simon King
You don't need to convert it to a Table object, but you probably do need to add 'schema': 'whatever' to the __table_args__ dictionary. In answer to your second question, I very much doubt you can use query.join() with 2 DB connections. query.join() simply adds an SQL JOIN clause to the query that

Re: [sqlalchemy] Difficulties with parallel data insertion into the same table

2015-01-23 Thread Simon King
On Fri, Jan 23, 2015 at 7:20 AM, SF Markus Elfring wrote: >>> I would appreciate if I can fill these data structures in parallel >>> without a serial database preparation step (table creation with >>> repeated meta-data specification). >> >> You’d need to implement checks for this concurrency. > >

Re: [sqlalchemy] Handling of differences between a table and its mapped class

2015-01-23 Thread Simon King
On Fri, Jan 23, 2015 at 9:11 AM, SF Markus Elfring wrote: > Hello, > > What will (or should) happen if the column attributes > which are specified by a class that is derived > from "declarative_base()" differ (e. g. an other default > value) from the settings of an existing database table? I assu

Re: [sqlalchemy] Difficulties with parallel data insertion into the same table

2015-01-23 Thread Simon King
On Fri, Jan 23, 2015 at 11:45 AM, SF Markus Elfring wrote: >>> I would expect that database implementations will provide functionality >>> for parallel updates including concurrent creation of each table. >> >> What would you expect a database to do if it receives 2 "CREATE TABLE >> my_table(...)"

Re: [sqlalchemy] Difficulties with parallel data insertion into the same table

2015-01-23 Thread Simon King
On Fri, Jan 23, 2015 at 12:17 PM, SF Markus Elfring wrote: >>> The parameter "IF NOT EXISTS" could be passed to the SQL statement "CREATE >>> TABLE". >>> >>> * Is this setting already used by the class library "SQLAlchemy 0.9.8-78.1"? >> >> From a quick scan of the docs it appears not. > > How ca

Re: [sqlalchemy] Why is assignment of a transient parent object does not automatically add this parent object into the session?

2015-02-10 Thread Simon King
On 10 Feb 2015, at 22:14, Bao Niu wrote: > > Why is assignment of a transient parent object does not automatically add > this parent object into the session? But Parent.append(PersistedChild) will > do the job nicely? > Here is my code: > > from sqlalchemy import Column, String, Integer, Forei

Re: [sqlalchemy] Seamlessly combining data from multiple tables into a single SQLalchemy object

2015-02-11 Thread Simon King
On Wed, Feb 11, 2015 at 1:47 AM, Dun Peal wrote: > I have a declarative base called Foo, instances of which get most of their > attributes from a Foo SQL table. However, Foo also has a bar_id attribute, > which is a foreign key linking to the primary key of a Bar table. Bar is > really just an ext

Re: [sqlalchemy] Seamlessly combining data from multiple tables into a single SQLalchemy object

2015-02-11 Thread Simon King
On Wed, Feb 11, 2015 at 4:10 PM, Jonathan Vanasco wrote: > Simon, > > why not use the association_proxy? > > You just described this: > > from sqlalchemy.ext.associationproxy import association_proxy > > class Foo(Base): > _bar = relationship(Bar, uselist=False, lazy='joined') > qux = association_

Re: [sqlalchemy] Re: Deleting from relationship

2015-02-23 Thread Simon King
I haven't looked at your code in detail, so this may not be the cause of the problem, but in general it is a bad idea to modify a collection while you are iterating over it. ie. this is not generally safe: for tag in edit_post.tags: edit_post.tags.remove(tag) Removing the tag from the "tags"

Re: [sqlalchemy] How do we define a relationship in sqlalchemy for a innodb file without actually creating the FK

2015-02-23 Thread Simon King
On Mon, Feb 23, 2015 at 12:02 PM, eli rashlin wrote: > I have a table which i have changed the Engine from Myisam to InnoDB, This > is the only table that has been changed, there are other tables that are in > relation with this table of 1:N > > class Signals(Base, sql_functions): > > __tablename_

Re: [sqlalchemy] How do we define a relationship in sqlalchemy for a innodb file without actually creating the FK

2015-02-24 Thread Simon King
I'm not sure I understand - the line you've shown doesn't include any joins between Signals and Clips, so I don't know why that error would occur. In general, if you are seeing that error message, then you need to explicitly tell SQLAlchemy the join condition between the 2 tables. This is normally

Re: [sqlalchemy] How do we define a relationship in sqlalchemy for a innodb file without actually creating the FK

2015-02-24 Thread Simon King
g_value, 2) == > func.format(sig_val, 2)).\ > > order_by(signals_table.Signals.sig_value) > > > On Tuesday, February 24, 2015 at 1:09:12 PM UTC+2, Simon King wrote: >> >> I'm not sure I understand - the line you've shown doesn't include any >> joins between

Re: [sqlalchemy] CheckConstraint in sqlalchemy-1.0.0dev

2015-02-27 Thread Simon King
On Fri, Feb 27, 2015 at 3:34 PM, Christopher Singley wrote: > I'm using the latest dev version of sqlalchemy against postgresql-9.4.1 > > I can't get SA to apply table-level CHECK constraints defined via > declarative, although I can manually add them via psql to tables created by > SA Metadata.cr

Re: [sqlalchemy] Advice on multiple ORM classes in multiple files and imports

2015-03-02 Thread Simon King
On Mon, Mar 2, 2015 at 11:29 AM, Martino Io wrote: > Hello, I've been busy writing an application which now has grown > considerably, it spans across several packages/modules totalling 200K lines > of python code. > Recently I made some changes to the structure and decided to split several > class

Re: [sqlalchemy] Advice on multiple ORM classes in multiple files and imports

2015-03-02 Thread Simon King
import it in both places. Now this > might just be me skipping the basics, however > if I don't import the mybase in both modules I cannot use it, since it > should throw an undefined variable exception. > > 2015-03-02 12:47 GMT+01:00 Simon King : >> >> On Mon, Mar 2, 2015

Re: [sqlalchemy] Re: many-to-many relation: unexpected count of rows

2015-03-05 Thread Simon King
Glad you've figured it out. This is touched on briefly in the docs, in the note at the bottom of: http://docs.sqlalchemy.org/en/rel_0_9/orm/basic_relationships.html#association-object As an alternative to making User.groups a relationship, you could also consider using the Association Proxy exten

Re: [sqlalchemy] Re: many-to-many relation: unexpected count of rows

2015-03-05 Thread Simon King
: >user = user_ref() >if user is None: >raise TypeError('Stale object reference') >return User2Group(user=user, group=group, system=system) > return creator > > setattr(User, system + '_groups',

Re: [sqlalchemy] Re: many-to-many relation: unexpected count of rows

2015-03-05 Thread Simon King
associated with the user. Simon On Thu, Mar 5, 2015 at 2:30 PM, Pavel S wrote: > Yes. > However doing so: > > user.keywords = [ Keyword('one'), Keyword('two') ] > > ...will create UserKeywords with user unset. This is the problem. > > > Dne čtvrtek

Re: [sqlalchemy] Can I make an update over a table that comes from sqlalchemy.MetaData(...).reflect()?

2015-03-12 Thread Simon King
On Wed, Mar 11, 2015 at 10:12 AM, Nelson Castillo wrote: > Hi there. > > I have searched but I haven't found an answer to my issue. > > I have this code: > > metadata = sqlalchemy.MetaData(bind=self.engine) > metadata.reflect() > table_user = self.metadata.tables['USER'] > > Now, how can I i

Re: [sqlalchemy] core integrity error

2015-03-13 Thread Simon King
On Fri, Mar 13, 2015 at 3:45 PM, Adam Watson wrote: > I recently posted a question on stack overflow regarding an Integrity Error > when using sqlalchemy core. I'd really appreciate it if anyone could read it > and help me figure it out: > http://stackoverflow.com/questions/29036357/sqlalchemy-cor

Re: [sqlalchemy] core integrity error

2015-03-13 Thread Simon King
gt; Inserting each item separately seems to have worked, but I'll have to time >> it again to make sure it actually sped up. Thank you! >> >> On Friday, March 13, 2015 at 12:13:24 PM UTC-4, Simon King wrote: >>> >>> On Fri, Mar 13, 2015 at 3:45 PM, Adam Watson

Re: [sqlalchemy] Sqlalchemy, Flask-User & scoped_session

2015-03-16 Thread Simon King
On Mon, Mar 16, 2015 at 1:41 PM, Wolf Reitsamer wrote: > Hi everyone, > > I can't get the following straight although I guess it's a pretty obvious > thing, since I haven't found much about this topic online. > > I wrote a little python/flask/sqlalchemy based web-service where I want > users to re

Re: [sqlalchemy] Is there any potential problem to store datetime as strings in one column?

2015-03-23 Thread Simon King
On Sun, Mar 22, 2015 at 11:01 PM, Bao Niu wrote: > Hi, > > Is there any potential disadvantages in using string as the datatype to > store datetime plus timezone in one column? > In my application the time information is not uniform. Some rows are > datetime while others just date. I still want to

Re: [sqlalchemy] sqlalchemy (0.9.7) double quoting python list items when used in "where in" statement

2015-03-23 Thread Simon King
On Mon, Mar 23, 2015 at 2:45 PM, Edgaras Lukoševičius wrote: > Hello, > > as I'm not receiving any responses in stackoverflow I wil try here. Can > someone help me with this issue? > > http://stackoverflow.com/questions/29195825/sqlalchemy-double-quoting-list-items > For the benefit of the mailin

Re: [sqlalchemy] is True vs ==True

2015-03-30 Thread Simon King
On Mon, Mar 30, 2015 at 10:59 AM, Jose Soares wrote: > Hi all, > > While I changed some obsolete syntax as defined in > (https://www.python.org/dev/peps/pep-0008/) > like (is True instead of ==True) also False and None. > I realized that sqlalchemy do not support them > What can I do to avoid this

Re: [sqlalchemy] How to add custom attribute to the session?

2015-03-30 Thread Simon King
On Mon, Mar 30, 2015 at 1:09 PM, uralbash wrote: > Hello, > > I want to set up in each session was my custom attribute, for example: > > from sqlalchemy.orm import scoped_session, sessionmaker > > Session = my_wapper(scoped_session(sessionmaker())) > session1 = Session() > session2 = Session() > >

Re: [sqlalchemy] How to add custom attribute to the session?

2015-03-30 Thread Simon King
st_delete(self): > user = self._add_item(User, 'Volod', 'Khonin', "123") > self.session.sacrud(User).delete(user.id) > db_user = self.session.query(User).filter_by(id=user.id).all() > self.assertEqual(db_user, []) > > > > >

Re: [sqlalchemy] Documentation for SQLAlchemy 0.4.5?

2015-04-16 Thread Simon King
On Thu, Apr 16, 2015 at 8:07 AM, Saravanakumar Karunanithi wrote: > Hi, > > I am working on a legacy code that uses SqlAlchecmy0.4.5, Could anyone > help me to get the documentation of 0.4.5? I googled it, but no luck, if any > one you have the documentation link/pdf, it would be a great help f

Re: [sqlalchemy] prototyping a complex query?

2015-04-30 Thread Simon King
On Wed, Apr 29, 2015 at 10:15 PM, Jonathan Vanasco wrote: > I have a rather complex query that I've written in SQL > > • The result-set is 6 columns (1 = timestamp, 2-6 = fkeys on tables/objects) > • The query involves 15 tables > • The query is about 100 lines of raw SQL > • The query is not fun,

Re: [sqlalchemy] contains_eager limited by .first()?

2015-05-05 Thread Simon King
On Tue, May 5, 2015 at 2:45 AM, Gerald Thibault wrote: > I have 2 classes, User and Address (i tried to make my test case resemble > the contents of > http://docs.sqlalchemy.org/en/latest/orm/loading_relationships.html#contains-eager), > defined like this: > > > from sqlalchemy import * > from sql

Re: [sqlalchemy] restrict child count?

2015-05-19 Thread Simon King
On Tue, May 19, 2015 at 4:06 PM, Mike Bayer wrote: > > > On 5/19/15 10:54 AM, Richard Gerd Kuesters wrote: > > thanks Mike! > > when i stated about the limit, it was because it must not be taken as a > parameter for any query, which "select * from blah" and "select * from bla > limit N" should be

Re: [sqlalchemy] how to return an array of dicts

2015-06-01 Thread Simon King
On Mon, Jun 1, 2015 at 1:51 PM, Richard Gerd Kuesters wrote: > hello all! > > probably this was asked before, as I already grabbed some answers already > from here and stackoverflow, but I don't really feel happy about it. > > problem: i have a query that it's result must go directly as a json (we

Re: [sqlalchemy] NameError: name 'Index' is not defined

2015-06-19 Thread Simon King
On Thu, Jun 18, 2015 at 8:27 PM, Kevin Qiu wrote: > I try to define composite index on last_name, first_name on > flask-sqlalchemy, the error says NameError: name 'Index' is not defined > Code: > class Student(mydb.Model): > __tablename__ = 'STUDENT' > __table_args__ = (Index('SearchNameIndices',

Re: [sqlalchemy] How to enter value for foriegn key field via sqlalchemy

2015-06-22 Thread Simon King
On Mon, Jun 22, 2015 at 8:44 PM, sudheesh ks wrote: > I have models: > > { > class Post(db.Model): > id = db.Column(db.Integer, primary_key = True) > body = db.Column(db.String(2000)) > user_id = db.Column(db.Integer, db.ForeignKey('user.id')) > comments = db.relationship('Comment'

Re: [sqlalchemy] [alembic] how do I add a many-to-many relation with add_column()

2015-08-12 Thread Simon King
On Wed, Aug 12, 2015 at 3:13 AM, wrote: > On 2015-08-11 21:43 Mike Bayer wrote: >> a relationship() is not a Column. Alembic "add_column()" is >> intended to render an "ALTER TABLE ADD COLUMN " >> statement. You need to pass it a Column object. > > Ok, tnen how can I realize that. How can I

Re: [sqlalchemy] Session.merge() use case (possible) ambiguity

2015-08-13 Thread Simon King
On Thu, Aug 13, 2015 at 2:03 AM, Jinghui Niu wrote: > About the Session.merge(), the documentation gives several examples of use > cases, I think there might be a slight ambiguity in this one: > >> An application which reads an object structure from a file and wishes to >> save it to the database

Re: [sqlalchemy] UnicodeDecode error on sqlalchemy select query

2015-08-26 Thread Simon King
On Tue, Aug 25, 2015 at 6:43 PM, Abhishek Sharma wrote: > Hi Team, >We are executing select query using > self.session.query(Model).filter(filter_conditions).first() > > Then we are storing the about query result in result variable. > Then we are trying to update one of model attr

Re: [sqlalchemy] sqlite problem with datetime format YYYY-MM-DDTHH:mm:ss

2015-09-03 Thread Simon King
On Thu, Sep 3, 2015 at 1:05 PM, Massi wrote: > Hi everyone, > > I'm trying to use sqlalchemy (0.9.10) to read a sqlite table which contains > some datetime columns. As the title says these column are given in the > format -MM-DDTHH:mm:ss (I did not create the table). When I execute the > query

Re: [sqlalchemy] sqlite problem with datetime format YYYY-MM-DDTHH:mm:ss

2015-09-03 Thread Simon King
ely I don't create the table so I don't > define the table, I only load it from the DB. I hope I intended your > suggestion correctly. > > Thanks again. > > On Thursday, September 3, 2015 at 3:54:45 PM UTC+2, Simon King wrote: >> >> On Thu, Sep 3, 2015 at 1:05 PM, Mas

Re: [sqlalchemy] Problem with hybrid_property

2015-10-13 Thread Simon King
> On 13 Oct 2015, at 17:09, Cecilio Ruiz wrote: > > Everything works fine, add, modify, etc. But when I ask Caja.Imp. He says he > does not exist. > > > # Table definition - Caja > # > Caja_table = sa.Table("Caja", metadata, > sa.Column('id', sa.Integer, nullable=True, autoincrement=True,

Re: [sqlalchemy] Problem with hybrid_property

2015-10-13 Thread Simon King
gt; 'imp' > > Yes, is typo error en email. The imp attibute is lower case. > > El martes, 13 de octubre de 2015, 23:01:34 (UTC+2), Simon King escribió: > return " Imp:%.2f)>" % (self.id, self.id_Conceptos, self.Entidad, self.Fecha, > self.Grupo, se

Re: [sqlalchemy] Problem with hybrid_property

2015-10-14 Thread Simon King
ha, > self.Grupo, self.Entrada, self.Salida, self.imp) > > > # Declare mappings > mapper(Conceptos, Conceptos_table) > mapper(Caja, Caja_table) > > # Create a session > session = sessionmaker(bind=db_engine) > se = session() > metadata.create_all(db_engine

Re: [sqlalchemy] Domain models and "leaky abstractions"

2015-11-13 Thread Simon King
On Fri, Nov 13, 2015 at 8:16 AM, Yegor Roganov wrote: > Suppose we have a 1 <-> N relation between users and cities (meaning that > every user is related with one city). For our domain model "User" we want > to define a method "lives_in_london". Code looks like this: > > class User(Base): > i

Re: [sqlalchemy] new object using a dictionary as the parameter

2015-11-23 Thread Simon King
> On 23 Nov 2015, at 17:58, mzagr...@d.umn.edu wrote: > > Greetings, > > I'm new to SQLAlchemy - sorry if the answer to this question is obvious. > > I have a table with many fields. > > I've created the ORM mapping: > > Base = declarative_base() > class CallRecord(Base): > [stuff] > > I'd l

Re: [sqlalchemy] Re: Creating a derived class object without inserting into base class table

2015-12-01 Thread Simon King
I don't understand exactly what you are trying to do here, from a database perspective. Your table setup suggests that you are using joined-table inheritance: http://docs.sqlalchemy.org/en/rel_1_0/orm/inheritance.html#joined-table-inheritance ie. attributes that are common to all classes in the h

Re: [sqlalchemy] event.listen questions

2015-12-01 Thread Simon King
On Tue, Dec 1, 2015 at 8:17 AM, Chris Withers wrote: > Hi All, > > Where can I find documentation on the parameters taken by event.listen? > I have some listeners on instrument_class that pass propagate=True, but I > can't find docs on what that means? > I think the parameters depend on the type

Re: [sqlalchemy] Re: Creating a derived class object without inserting into base class table

2015-12-01 Thread Simon King
ssue, please explain and advise what should > be changed in order to support this structure. > > P.S. I changed the approach to solve this issue, but still want to gain > better understanding of how to design and implement relationships). I've > decided to completely separate the cla

Re: [sqlalchemy] Re: Creating a derived class object without inserting into base class table

2015-12-01 Thread Simon King
gt; is what is the reason for this limitation: > > "If someone can be both a Doctor and a Patient at the same time, I don't > think 2 classes inheriting from User can really work any more" - Why? > > Amit > > On Tuesday, December 1, 2015 at 5:26:28 PM UTC+2, Simon

Re: [sqlalchemy] Table object to mapped class (model)

2015-12-10 Thread Simon King
On Thu, Dec 10, 2015 at 5:35 AM, Nana Okyere wrote: > I'm using the sqlalchemy-datatables library to be able to display > tabular data with the jquery datatables library. One of the parameters that > I need to create a DataTables object is a mapped class (model) as > illustrated on line 50 of th

Re: [sqlalchemy] association proxy and eager loading

2015-12-18 Thread Simon King
On Fri, Dec 18, 2015 at 1:20 AM, Jonathan Vanasco wrote: > I'm trynig to use association_proxy to map a collection of items through > an intermediary table > > I'm running into a problem where I can't figure out a way to eagerload the > collection through the extension. > > if i do: > query.o

Re: [sqlalchemy] hybrid property / expression returns entire table

2016-01-15 Thread Simon King
On Fri, Jan 15, 2016 at 6:16 AM, Brian Cherinka wrote: > I'm trying to set up a hybrid property / expression in a custom class, > that I can use in queries. I think I have the syntax correct, however the > query returns the entire table, instead of the correct subset of results. > And the where c

Re: [sqlalchemy] hybrid property / expression returns entire table

2016-01-15 Thread Simon King
is embedded into a bunch of stuff. But > I'll work on it. > > Brian > > > On Friday, January 15, 2016 at 5:00:51 AM UTC-5, Simon King wrote: > >> On Fri, Jan 15, 2016 at 6:16 AM, Brian Cherinka >> wrote: >> >>> I'm trying to set up a hybri

Re: [sqlalchemy] hybrid property / expression returns entire table

2016-01-15 Thread Simon King
15, 2016 at 2:23 PM, Brian Cherinka wrote: > Ahh. Thanks. Here is the class side then. Still None. > > In [14]: print datadb.Sample.nsa_logmstar > None > > Brian > > On Friday, January 15, 2016 at 8:48:30 AM UTC-5, Simon King wrote: >> >> "Samp

Re: [sqlalchemy] hybrid property / expression returns entire table

2016-01-15 Thread Simon King
ase connection is a singleton and my base is defined inside that, > essentially > > engine = create_engine(database_connection_string) > Base = declarative_base(bind=engine) > > Brian > > On Friday, January 15, 2016 at 9:43:39 AM UTC-5, Simon King wrote: > What hap

Re: [sqlalchemy] hybrid property / expression returns entire table

2016-01-15 Thread Simon King
f nsa_logmstar(self): > try: > return math.log10(self.nsa_mstar) > except ValueError: > return -.0 > except TypeError: > return None > > @nsa_logmstar.expression > def nsa_logmstar(cls): >

Re: [sqlalchemy] Stand-alone Sequences are not created by create_all

2016-01-27 Thread Simon King
> On 27 Jan 2016, at 18:59, Chris Macklin wrote: > > If I declare a Sequence at the class level in a model class declaration using > declarative (SQLAlchemy 0.9.10 on postgres), the sequence is not created by > create_all unless the sequence is explicitly associated with a Column. My > use c

Re: [sqlalchemy] Modifying records across multiple modules?

2016-02-03 Thread Simon King
On Wed, Feb 3, 2016 at 3:54 PM, Alex Hall wrote: > Hello list, > I'm new to SQLAlchemy, but not to Python. I have an application that's > coming together, and relies on SQLAlchemy to talk to a database for > many of the app's functions. Listing tables, listing records, updating > records, pulling

Re: [sqlalchemy] Modifying records across multiple modules?

2016-02-03 Thread Simon King
> > When I print the type: > > And repr(): > (2, u'Powersports Etc', 5554443210L, u'ahall+dbte...@autodist.com', True) > > > On 2/3/16, Simon King wrote: >> On Wed, Feb 3, 2016 at 3:54 PM, Alex Hall wrote: >> >>> Hello list, &g

Re: [sqlalchemy] Modifying records across multiple modules?

2016-02-04 Thread Simon King
rks, because I get the records as expected and > can display them or inspect them. I just can't modify them for some reason. > As I said, though, I'm new to this package so am likely missing an obvious > step, or have something set up very wrong. > > Sent from my iPhone >

Re: [sqlalchemy] Modifying records across multiple modules?

2016-02-04 Thread Simon King
tablesList = [] > for table in tables.values(): >tablesList.append([table]) > #end for > > Just to be sure, I stuck a "print type(table)" statement in that for > loop, and the objects are still sqlalchemy.sql.schema.Table objects. > > On 2/4/16, Simon King wro

Re: [sqlalchemy] Modifying records across multiple modules?

2016-02-04 Thread Simon King
e).all() > myTempRecord = mySchemaClass(record) > myTempRecord.property = newValue > #update the database > > Assuming GUIManager knows about mySchemaClass, would that approach > work? How I'd pass in a record and get back an instance of > mySchemaClass I'

Re: [sqlalchemy] Itterating over database row?

2016-02-04 Thread Simon King
> On 4 Feb 2016, at 18:19, Alex Hall wrote: > > Hello all, > I'm setting my application up the way Simon suggested. I still use the > table object so I can get its name for displaying in one list, but the > other list (which holds the actual rows of the selected table) is > using the relevant su

Re: [sqlalchemy] Best practice for restricting input to columns?

2016-02-05 Thread Simon King
On Fri, Feb 5, 2016 at 2:15 PM, Michal Petrucha < michal.petru...@konk.org> wrote: > On Fri, Feb 05, 2016 at 08:24:46AM -0500, Alex Hall wrote: > > Hi all, > > What's the recommended way to restrict input? For instance, I store a > > phone number as an integer, and I need it to have 7, 10, or

Re: [sqlalchemy] Pyodbc.Connection has no attribute 'dbms_ver'?

2016-02-15 Thread Simon King
What does the traceback say? That exact line would trigger an error much like the one you are seeing, if the object in “connection.connection” is a pyodbc.Connection and doesn’t have a “dbms_ver” attribute. Note that there are at least 3 packages that could be involved here: pyodbc (https://pyp

Re: [sqlalchemy] Where to use and vs and_()

2016-02-17 Thread Simon King
On Wed, Feb 17, 2016 at 7:46 AM, Krishnakant wrote: > Hello all, > The subject might have made my problem already clear. > So I am unclear about when I should use the normal Python "and " vs the > sqlalchemy "and_" while writing where, having or similar queries including > joins. > I have tryed u

Re: [sqlalchemy] Padding columns to a query

2016-02-17 Thread Simon King
On Wed, Feb 17, 2016 at 5:29 PM, Horcle wrote: > I have the following query db.session.query(label('sid', > distinct(Clinical.patient_sid))) to which I would like to pad a few extra > columns with constant values, like in the following SQL example > > select distinct(Clinical.patient_sid) as sid

Re: [sqlalchemy] connected using pyodbc; how to hook that to SA?

2016-02-19 Thread Simon King
On Fri, Feb 19, 2016 at 2:38 PM, Alex Hall wrote: > As the subject says, I am connected to our iSeries through straight > pyodbc. That seems to run perfectly. Now, is there a way to use SA > with that connection? When I use "ibm_db_sa+pyodbc://..." I get the > exact same error I was getting when

Re: [sqlalchemy] connected using pyodbc; how to hook that to SA?

2016-02-19 Thread Simon King
;, in case anyone happens to know what that's about. I'm > getting nightmarish flashbacks to my "has no attribute" error last > week for the same object. But at least this is a different one; I'll > count it as a good thing! > > On 2/19/16, Simon King wrote: &

Re: [sqlalchemy] connected using pyodbc; how to hook that to SA?

2016-02-19 Thread Simon King
at, it's because I used a name that complains about > there being no attribute dbms_ver or server.version, depending on the > string. > > They don't make it easy, do they? > > On 2/19/16, Simon King wrote: > > URI prefixes are defined in the setup.py for the ibm

Re: [sqlalchemy] connected using pyodbc; how to hook that to SA?

2016-02-19 Thread Simon King
its own, > pyodbc is the only way I've been able to talk to the server at all. > Add it to SA, though, and that attribute error appears. > > On 2/19/16, Simon King wrote: > > According to > > > http://docs.sqlalchemy.org/en/rel_1_0/core/connections.html#registering-n

Re: [sqlalchemy] Re: column names with spaces with Declarative

2016-02-22 Thread Simon King
Your class definitions have to be valid Python syntax, and Python doesn't allow for spaces in attribute names. However, the attribute name can be different to the actual column name. Try something like this: hiring_manager = db.Column('Hiring Manager', db.String(120), primary_key=True) Hope t

Re: [sqlalchemy] update instance.relation.attr in instance.attr "set event listener"

2016-02-25 Thread Simon King
On Wed, Feb 24, 2016 at 9:51 PM, sector119 wrote: > Hello! > > I have two models, Product and ProductFlavor with one-to-many relationship > And I have a listener, which I want to update Product.quantity on > ProductFlavor.quantity change: > > @event.listens_for(ProductFlavor.quantity, 'set') > de

Re: [sqlalchemy] Re: Question about the other property of backref

2016-02-25 Thread Simon King
On Thu, Feb 25, 2016 at 7:53 AM, 尤立宇 wrote: > Thanks for your response. > > Do you consider using `backref` only on one of the class bad practice? > > I'm curious because automatically creating descriptors seems possible to > me, and I'm wondering when it happens. > > As documentation states so:

Re: [sqlalchemy] Re: Can I make bulk update through association proxy?

2016-02-25 Thread Simon King
On Thu, Feb 25, 2016 at 9:03 AM, Piotr Dobrogost < p...@2016.groups.google.dobrogost.net> wrote: > On Wednesday, February 24, 2016 at 2:41:43 PM UTC+1, Piotr Dobrogost wrote: >> >> Hi! >> >> Let's say I have a model Text with attribute "values" which is >> association proxy. >> I can update single

Re: [sqlalchemy] I wish to know how I use table ALIAS in alchemy core

2016-02-25 Thread Simon King
On Thu, Feb 25, 2016 at 9:43 AM, Krishnakant wrote: > Hello, > I have a query where there are 2 alias for a single table. > This is because the table contains a self referencing foreign key. > the table is (groupcode integer primary key, groupname text, subgroupof > integer foreign key references

Re: [sqlalchemy] Re: Can I make bulk update through association proxy?

2016-02-25 Thread Simon King
On Thu, Feb 25, 2016 at 12:01 PM, Piotr Dobrogost < p...@2016.groups.google.dobrogost.net> wrote: > On Thursday, February 25, 2016 at 11:10:36 AM UTC+1, Simon King wrote >> >> >> I can't think of a way you could do this with objects you've already >>

Re: [sqlalchemy] update instance.relation.attr in instance.attr "set event listener"

2016-02-25 Thread Simon King
> ProductFlavor.__table__.c.product_id == Product.__table__.c.id) > connection.execute( > Product.__table__.update().where(Product.__table__.c.id == > target.product_id).values(quantity=quantity)) > > > четверг, 25 февраля 2016 г., 11:52:50 UTC+2 польз

Re: [sqlalchemy] Need help with update + select query

2016-02-25 Thread Simon King
On Thu, Feb 25, 2016 at 1:19 PM, sector119 wrote: > Hello, > > Can some one help me with that query? I get AttributeError: servings > I expect that sqlalchemy use update from select for that query or it's not > possible and I must use select(...).as_scalar() for every updated column? > > s =

Re: [sqlalchemy] Re: Can I make bulk update through association proxy?

2016-02-26 Thread Simon King
On Fri, Feb 26, 2016 at 8:13 AM, Piotr Dobrogost < p...@2016.groups.google.dobrogost.net> wrote: > On Thursday, February 25, 2016 at 2:33:13 PM UTC+1, Simon King wrote: > > Maybe I'm not understanding your question properly. The return value from >> query.all() is a

  1   2   3   4   5   6   7   >