Re: [sqlalchemy] Bulk Lazy Loader for relationships

2017-05-03 Thread Simon King
On Wed, May 3, 2017 at 10:47 AM, David Chanin wrote: > Hi Everyone, > > We just open-sourced a custom lazy loader for SQLAlchemy that does bulk lazy > loading of relations - essentially a lazy subqueryload. The idea is that > whenever a relation is lazy-loaded on a model, the

Re: [sqlalchemy] eager loading relationships after an initial query?

2017-04-25 Thread Simon King
On Mon, Apr 24, 2017 at 10:26 PM, Jonathan Vanasco wrote: > > On Monday, April 24, 2017 at 4:28:22 PM UTC-4, Mike Bayer wrote: >> >> yeah just load the object again w/ the eagerloads option you want. > > > > Thanks. I was hoping there was a way to just say

Re: [sqlalchemy] How to pass list of columns into query method.

2017-04-05 Thread Simon King
s why i want pass columns in query method dynamically. can > you suggest me how can achieve this. > > > On Wednesday, April 5, 2017 at 5:08:50 PM UTC+5:30, Simon King wrote: >> >> On Wed, Apr 5, 2017 at 11:10 AM, Mayank Soni <mayank...@gmail.com> wrote: >> > I am

Re: [sqlalchemy] How to pass list of columns into query method.

2017-04-05 Thread Simon King
On Wed, Apr 5, 2017 at 11:10 AM, Mayank Soni wrote: > I am trying to pass list of columns of table into query method using > add_columns method. Below i am mentioning code snipped. > > def LLL(): > Base = automap_base() > class AAA(Base): > __tablename__ =

Re: [sqlalchemy] Attribute history for columns with no explicit default

2017-03-13 Thread Simon King
On Mon, Mar 13, 2017 at 1:50 PM, mike bayer <mike...@zzzcomputing.com> wrote: > > > On 03/13/2017 08:34 AM, Simon King wrote: >> >> Hi, >> >> I'm not sure if the problem I've got is a bug or intended behaviour. >> Here's a test script: >> >&g

Re: [sqlalchemy] Looks like there is no event to catch "before" a rollback happens

2017-03-10 Thread Simon King
On Fri, Mar 10, 2017 at 4:12 PM, Alessandro Molina wrote: > > > On Fri, Mar 10, 2017 at 3:40 PM, mike bayer > wrote: >> >> If this is truly, "unexpected error but we need to do things", perhaps you >> can use before_flush() to memoize the

Re: [sqlalchemy] Perfoming join on multiple tables dynamically

2017-03-06 Thread Simon King
On Mon, Mar 6, 2017 at 1:28 AM, Vijaya Sekar wrote: > Hello everyone, > > I have parent table which holds the primary keys of several child tables.The > child table are got as a list . Using SQLalchemy ORM, how can I join > multiple child tables to this parent? > Can

Re: [sqlalchemy] ORM: Implementing abstract base class that generates auxiliary tables for each child class

2017-02-17 Thread Simon King
On Fri, Feb 17, 2017 at 10:03 AM, wrote: > I want to achieve something like this: > > Base = declarative_base() > > # the abstract base, no table generated for it > class TreeNode(Base): > __abstract__ = True > parent = Column(ForeignKey('child_class_table.id'),

Re: [sqlalchemy] SQLAlchemy dedicated read-server pooling

2016-12-15 Thread Simon King
On Thu, Dec 15, 2016 at 10:00 AM, Simon King <si...@simonking.org.uk> wrote: > On Thu, Dec 15, 2016 at 2:07 AM, Matt <m...@ramwise.com> wrote: >> >> >> On Wednesday, December 14, 2016 at 3:58:19 PM UTC+1, Mike Bayer wrote: >>> >>> >&

Re: [sqlalchemy] SQLAlchemy dedicated read-server pooling

2016-12-15 Thread Simon King
On Thu, Dec 15, 2016 at 2:07 AM, Matt wrote: > > > On Wednesday, December 14, 2016 at 3:58:19 PM UTC+1, Mike Bayer wrote: >> >> >> When you want to switch between "writer" and "reader", the "reader" must >> be fine with using a totally clean transaction and that means totally >>

Re: [sqlalchemy] Set/clear mapping for some tables only

2016-11-29 Thread Simon King
The "transaction" package is a system for coordinating transactions between multiple systems: https://pypi.python.org/pypi/transaction For example, it could coordinate transactions between multiple SQL databases, using 2-phase commit to ensure that either all are committed or none are

Re: [sqlalchemy] Set/clear mapping for some tables only

2016-11-28 Thread Simon King
I don't know if this is part of your problem, but: 1. metadata.create_all(Session.connection()) will not mark the session as dirty 2. Session.flush() is a no-op if the session is clean - it won't even fire the "after_flush" event 3. ZopeTransactionExtension uses the after_flush event (or

Re: [sqlalchemy] Column value determined as a function return on INSERT

2016-11-18 Thread Simon King
You can provide a function for the default value, and the function can receive the current statement context as a parameter. This context gives you access to the rest of the insert statement, including values of other parameters:

Re: [sqlalchemy] How to run multiple statements/operations in a single transaction ?

2016-11-18 Thread Simon King
On Fri, Nov 18, 2016 at 11:43 AM, Santosh Sharma wrote: > I am using SQLAlchemy and postgres database. > > I want to do "Delete and Insert operation" on the table in a single > transaction without using orm. > > Say > table User > Column | Type|

Re: [sqlalchemy] Setting key of hybrid_property to attribute name rather than function name

2016-11-11 Thread Simon King
On Fri, Nov 11, 2016 at 1:53 PM, Michael Williamson wrote: > >> I think your code is basically fine, you've just got a mistake on the >> last line. Presumably you meant to query Person, not Person.born? > > > I want Person.born so that I don't have to get the entire object. It

Re: [sqlalchemy] Setting key of hybrid_property to attribute name rather than function name

2016-11-11 Thread Simon King
On Fri, Nov 11, 2016 at 12:20 PM, Michael Williamson wrote: > I'm using hybrid_property, and would like the key of the property to be set > to the attribute name, rather than the name of the getter. This is because > I'm generating a getter function based on some args, rather

Re: [sqlalchemy] Re: One to One relationship

2016-11-11 Thread Simon King
On Fri, Nov 11, 2016 at 6:59 AM, Alfred Soeng wrote: > It's the issue in the inheritance: > What I want to do is like this: > class Employee(Base): > __tablename__ = 'employee' > id = Column( > Integer, > primary_key=True, > ) > type_name =

Re: [sqlalchemy] Flask SQLalchemy sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) column todos.user_id does not exist

2016-11-11 Thread Simon King
On Fri, Nov 11, 2016 at 7:59 AM, Muhammad Aldo Firmansyah wrote: > I want to make API using flask, flask-restless and flask sqlalchemy. > Database using postgres > > Here's my model. The relation below is one-to-many (User have one or many > tasks. And a task is

Re: [sqlalchemy] Re: Orm, join 1 row from many2many table when querying

2016-11-10 Thread Simon King
Whoops, yes, you're right. You should be able to simplify the relationship definition to a simple "primaryjoin" clause, no need for any of the "secondary" stuff. Simon On Thu, Nov 10, 2016 at 1:41 PM, Dorian Hoxha wrote: > Note that you're joining with User, which I

Re: [sqlalchemy] Orm, join 1 row from many2many table when querying

2016-11-10 Thread Simon King
s for a product, but only 1 filtered by user_id) ? > > > On Thu, Nov 10, 2016 at 11:53 AM, Simon King <si...@simonking.org.uk> wrote: >> >> On Thu, Nov 10, 2016 at 9:32 AM, Dorian Hoxha <dorian.ho...@gmail.com> >> wrote: >> > So I have: >> > &

Re: [sqlalchemy] Orm, join 1 row from many2many table when querying

2016-11-10 Thread Simon King
On Thu, Nov 10, 2016 at 9:32 AM, Dorian Hoxha wrote: > So I have: > > class Thing(): > current_user_like = relationship(Like) > > class User(): > pass > > class Like(): > user_id = Column(primary_key=True) > thing_id = Column(primary_key=True) > > > Now I

Re: [sqlalchemy] postgresql array column, fetch only_load() element by index

2016-11-08 Thread Simon King
at 10:12 AM, Dorian Hoxha <dorian.ho...@gmail.com> wrote: > Hi Simon, > > It all works. All I need is how to do: > > Model.query.options(load_only(Model.array[1])).all() ? > > > Thanks > > > On Tue, Nov 8, 2016 at 10:56 AM, Simon King <si...@simonking.org

Re: [sqlalchemy] .count() hangs indefinitely

2016-11-04 Thread Simon King
On Fri, Nov 4, 2016 at 8:13 AM, James Burke wrote: > Hi All, > > I've run into a odd problem, where calling the count function hangs my code > indefinitely. The odd thing is it was working until recently, so I'm a > little confused. > > customer = >

Re: [sqlalchemy] Handy package to debug flask+sqlalchemy+orm (flask_sqla_debug)

2016-10-31 Thread Simon King
gt; For Pyramid, another interesting package is SQLTap, which provides useful > informations about execution of SQLAlchemy queries... > > Best regards, > Thierry > > 2016-10-31 11:05 GMT+01:00 Simon King <si...@simonking.org.uk>: >> >> On Sun, Oct 30, 2016 at 9:36

Re: [sqlalchemy] Handy package to debug flask+sqlalchemy+orm (flask_sqla_debug)

2016-10-31 Thread Simon King
On Sun, Oct 30, 2016 at 9:36 PM, Alfred Perlstein <alfred.perlst...@gmail.com> wrote: > Hello, > > I wanted to start this out with a big thanks to the community, especially > Mike Bayer, Simon King, and Jonathan Vanasco. > > A few weeks ago I asked for help on debugging

Re: [sqlalchemy] Inject/Extend an attribute onto all objects in a Session?

2016-10-28 Thread Simon King
> On 28 Oct 2016, at 21:47, Jonathan Vanasco wrote: > > oh great! `session.info["request"]` solved all my problems quite nicely. i > integrated that my pipy sessions manager. > > Simon, thanks. Looking at your code, I recall that `dbsession.remove()` may > be better than

Re: [sqlalchemy] Inject/Extend an attribute onto all objects in a Session?

2016-10-28 Thread Simon King
On Fri, Oct 28, 2016 at 3:19 AM, mike bayer wrote: > > > On 10/27/2016 09:41 PM, Jonathan Vanasco wrote: >> >> I have an edge-case in a few situations where, within an @property of a >> SqlAlchemy object, I need to know the current active web-request/context. >> >> I'm

Re: [sqlalchemy] Simple SQLAlchemy hiearchical inheritance model

2016-10-26 Thread Simon King
On Tue, Oct 25, 2016 at 10:46 PM, Robert C wrote: > I am modeling a simple hierarchical database structure. My model is designed > as follows: > > class ChatMessage(Base): > __tablename__ = 'chat_message' > sender_id = Column(Integer,

Re: [sqlalchemy] Handling "generic" relations

2016-10-20 Thread Simon King
On Thu, Oct 20, 2016 at 12:11 PM, Lele Gaifax wrote: > Hi all, > > I'd like to have an Entity able to be "attached" to N different others, > avoiding the need of N intermediate/secondary tables. > > I imagine something like the following:: > > class Address(Base): >

Re: [sqlalchemy] sqlalchemy import issue in powa web

2016-10-14 Thread Simon King
On Fri, Oct 14, 2016 at 4:56 AM, Ulhas Kanaskar wrote: > [root@test01 powa-web-3.0.1]# ./powa-web > > Traceback (most recent call last): > > File "./powa-web", line 2, in > > from powa import make_app > > File

Re: [sqlalchemy] Selective logging using the ORM for a single thread. Can't do it, therefore can't debug our app.

2016-10-12 Thread Simon King
You could use the before_cursor_execute event to log the SQL based on some debugging flag. http://docs.sqlalchemy.org/en/latest/core/events.html#sqlalchemy.events.ConnectionEvents.before_cursor_execute For example: from sqlalchemy import event DEBUGGING = False @event.listens_for(SomeEngine,

Re: [sqlalchemy] Question regarding detached object

2016-10-07 Thread Simon King
> On 7 Oct 2016, at 14:33, Ludovic Beliveau wrote: > > Hi, > > I know this subject has been covered many times in this group and I've read a > lot on it in the past few days. But there is still something that I can't > explain/understand with detached object. > > The

Re: [sqlalchemy] How to implement SQL level expression for this hybrid property?

2016-10-03 Thread Simon King
On Mon, Oct 3, 2016 at 11:43 AM, Jinghui Niu wrote: > This really helps. Thank you Simon! I still have a couple of smaller > questions. > >> When you access .fullname, the "self" parameter is now the >> *class*, so self.firstname and self.lastname are SQLAlchemy column >>

Re: [sqlalchemy] How to implement SQL level expression for this hybrid property?

2016-10-03 Thread Simon King
y current code? Or maybe you could please point out a link >> to where I can explore further on the python to SQL transition? Thank you so >> much. >> >> Jinghui >> >> On Mon, Oct 3, 2016 at 1:27 AM, Simon King <si...@simonking.org.uk> wrote: >>>

Re: [sqlalchemy] How to implement SQL level expression for this hybrid property?

2016-10-03 Thread Simon King
On Mon, Oct 3, 2016 at 7:17 AM, Jinghui Niu wrote: > I have a ledger table and a corresponding python class. I defined the model > using SQLAlchemy, as follows, > > class Ledger(Base): > __tablename__ = 'ledger' > > currency_exchange_rate_lookup = {('CNY', 'CAD'):

Re: [sqlalchemy] How can I programmatically give a hybrid_property its name?

2016-09-29 Thread Simon King
On Thu, Sep 29, 2016 at 6:32 AM, Jinghui Niu wrote: > The documentation shows that hybrid_property should used as a decorator, > like: > @hybrid_property > def my_property(self): > pass > > > What if I wanted to give this hybrid property a name by referring a variable >

Re: [sqlalchemy] AutomapBase without binding engine/tables individually?

2016-09-20 Thread Simon King
On Tue, Sep 20, 2016 at 5:36 AM, Rahul Ahuja wrote: > Thanks for the swift reply, Mike! Unfortunately, I had some trouble running > your code. I'm getting > base = automap_base(MetaData()) > File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/automap.py", > line

Re: [sqlalchemy] SQL expression for function (and/or method) dispatching?

2016-09-16 Thread Simon King
On Fri, Sep 16, 2016 at 10:49 AM, Jinghui Niu wrote: >> If you still want to store it as a string, I guess you'll need to try >> parsing it as a datetime and then fall back to parsing it as a date. > > > Exactly! That's my intention. I'm so excited that my idea has affirmed

Re: [sqlalchemy] SQL expression for function (and/or method) dispatching?

2016-09-16 Thread Simon King
ng by making. So I would >> like to try all the new features for later tasks. >> >> I'm fascinated by hybrid_property, but is stuck now when trying to >> dispatch functions at the SQL expression level. >> >> Jinghui >> >> On Fri, Sep 16, 2016 at 1:34 AM, Simon K

Re: [sqlalchemy] SQL expression for function (and/or method) dispatching?

2016-09-16 Thread Simon King
Ignore SQLAlchemy for the moment and describe what you are trying to achieve. It looks like you want to store dates and times as strings in your database (rather than the appropriate type), and yet still be able to perform date-related operations on them qhen querying. Is that right? Is there a

Re: [sqlalchemy] Turning SAWarnings into exceptions

2016-09-15 Thread Simon King
(): "Convert SQLAlchemy warnings to exceptions" import sqlalchemy.exc warnings.simplefilter( 'error', sqlalchemy.exc.SAWarning ) Simon On Thu, Sep 15, 2016 at 3:09 PM, Simon King <si...@simonking.org.uk> wrote: > According to https://docs.python.org/2

Re: [sqlalchemy] Turning SAWarnings into exceptions

2016-09-15 Thread Simon King
According to https://docs.python.org/2/using/cmdline.html#cmdoption-W, the full form of -W (and PYTHONWARNINGS) is: action:message:category:module:line Empty fields are ignored, and unused trailing fields can be left out, so maybe "error::SAWarning" would work? Simon On Thu, Sep 15, 2016

Re: [sqlalchemy] Session autoflush when using history_meta (examples/versioned_history)

2016-09-04 Thread Simon King
> On 3 Sep 2016, at 01:36, HP3 wrote: > > Thank you Mike, > > I will strongly consider creating a PR for an alternative solution. > > I would need to dig into the library to learn the basics of sqlalchemy > architecture though. So far, I have only used 0.9.x and

Re: [sqlalchemy] examples/versioned_history test_versioning.py doubts about TestVersioning.test_relationship

2016-09-02 Thread Simon King
By default, the session is flushed before any query, so that the query results are consistent with changes you may have made in-memory: http://docs.sqlalchemy.org/en/latest/orm/session_basics.html#flushing Hope that helps, Simon On Fri, Sep 2, 2016 at 5:12 PM, HP3

Re: [sqlalchemy] setters and getters on an automapped table

2016-08-30 Thread Simon King
thon2.7/site-packages/sqlalchemy/util/_collections.py", > line 212, in __getattr__ > > raise AttributeError(key) > > AttributeError: hosts > > > On Fri, Aug 26, 2016 at 1:33 AM, Simon King <si...@simonking.org.uk> wrote: >> >> On Fri, Aug 26, 201

Re: [sqlalchemy] Wrong todo.id after the commit (a log string instead 1)

2016-08-26 Thread Simon King
> On 26 Aug 2016, at 21:42, adaptable (Metaframework) > wrote: > > Hi all, > this comment on Github is well formatted: > > https://github.com/zzzeek/sqlalchemy/pull/295#issuecomment-242834334 > > I see the wrong todo.id after the commit (a log string instead 1) > >

Re: [sqlalchemy] setters and getters on an automapped table

2016-08-26 Thread Simon King
On Fri, Aug 26, 2016 at 2:24 AM, Robert Minsk wrote: > I am using automap_base to reflect a table. > > metadata = MetaData() > metadata.reflect(bind=engine, only=['hosts']) > automap = automap_base(metadata=metadata) > automap.prepare() > > Hosts = automap.classes.hosts > > The

Re: [sqlalchemy] hybrid_property vs. hybrid_method, other than the latter can take arguments?

2016-08-24 Thread Simon King
On Wed, Aug 24, 2016 at 2:55 AM, Jinghui Niu wrote: > Hi, I wonder if there is any recommendation or best practice on choosing > between > hybrid_property > > and > hybrid_method > , > other than they hybrid_method can take arguments? If I use the hybrid_method > only

Re: [sqlalchemy] Having SA generate constructor when using autoload.

2016-08-22 Thread Simon King
On Mon, Aug 22, 2016 at 10:12 AM, Piotr Dobrogost wrote: > I'd like to map a class onto table and automatically get __init__() method > per >

Re: [sqlalchemy] Tracking instance commit status

2016-08-11 Thread Simon King
On Thu, Aug 11, 2016 at 8:30 AM, Wibowo Arindrarto wrote: > Dear all, > > I have a little problem with getting object states that have been flushed > but not committed. As far as I understand, SQLAlchemy does not have an > official object state corresponding to this.

Re: [sqlalchemy] Re: DBAPI Error with SQLAlchemy-1.0.5

2016-08-02 Thread Simon King
It looks like an exception is occurring, which SQLAlchemy has caught and is now trying to roll back the transaction before re-raising the initial exception. However, a second exception has occurred during the rollback, so you can no longer see the original exception. The second exception looks

Re: [sqlalchemy] Implementation of params for textual SQL prevents its use in column names (use Python format as workaround)

2016-07-29 Thread Simon King
On Thu, Jul 28, 2016 at 4:33 AM, Andrew M wrote: > Okay, thanks Mike for your comprehensive reply. There is still so much to > learn ... *sigh*. > > Perhaps it's worth including a sentence or two in the docs, helping > overconfident people like myself to understand the

Re: [sqlalchemy] Re: Execute with raw string not persisted to database

2016-07-25 Thread Simon King
lem when > using sqlalchemy as an ORM. > > Brgds, > > Rogier > > On Monday, 25 July 2016 13:15:11 UTC+2, Simon King wrote: >> >> ...and the reason that it works on the older tables is probably that >> they use the MyISAM engine rather than InnoDB. >> >

Re: [sqlalchemy] Re: Execute with raw string not persisted to database

2016-07-25 Thread Simon King
...and the reason that it works on the older tables is probably that they use the MyISAM engine rather than InnoDB. On Mon, Jul 25, 2016 at 12:05 PM, Mehdi gmira wrote: > Maybe you forgot to commit ? > > > Le lundi 25 juillet 2016 12:08:17 UTC+2, Rogier Eggers a écrit : >> >>

Re: [sqlalchemy] SAWarning shows not immediately, but after some time of app execution

2016-07-22 Thread Simon King
On Fri, Jul 22, 2016 at 3:25 PM, TomS. wrote: > On 07/19/2016 06:41 PM, Mike Bayer wrote: > > > > On 07/19/2016 11:51 AM, TomS. wrote: > > Hi, > > We have Flask app which uses SQLAlchemy. Weird error started to happen > recently. The difficulty is that we can't reproduce the

Re: [sqlalchemy] Re: explicitly add objects to identity map

2016-07-21 Thread Simon King
On Thu, Jul 21, 2016 at 5:58 PM, Jonathan Vanasco <jvana...@gmail.com> wrote: > > > On Thursday, July 21, 2016 at 12:15:40 PM UTC-4, Simon King wrote: >> >> There are some hints for keeping references to objects at: >> >> >> http://docs.sqlalchemy.or

Re: [sqlalchemy] Re: explicitly add objects to identity map

2016-07-21 Thread Simon King
There are some hints for keeping references to objects at: http://docs.sqlalchemy.org/en/latest/orm/session_state_management.html#session-referencing-behavior Simon On Thu, Jul 21, 2016 at 5:11 PM, Mehdi gmira wrote: > Yeah I thought of that. I find it awkward because you

Re: [sqlalchemy] explicitly add objects to identity map

2016-07-21 Thread Simon King
On Thu, Jul 21, 2016 at 3:29 PM, Mehdi gmira wrote: > Is there a way to explicitely add objects to the identity map ? I would like > to be able to do something like: > > foos = session.query(Foo).all() > add_to_identity_map(foos) I don't understand the question - objects

Re: [sqlalchemy] automap_base from MySQL doesn't setup all tables in Base.classes but they are in metadata.tables

2016-07-21 Thread Simon King
On Wed, Jul 20, 2016 at 9:44 PM, bkcsfi sfi wrote: > I have a legacy MySQL database that I am working with sqla version 1.0.11 > and MySQL-Python engine (just upgraded to 1.0.14, problem persists) > > I use automap_base and prepare with reflect=True > > some of the tables in

Re: [sqlalchemy] Re: Specify query_cls for the one query

2016-07-13 Thread Simon King
I don't create _pg_query using splitted_query_cls=False (with std Query > class), then _pg_query invokation of methods (all(), one() and other) will > always apply overrided methods (because it uses SplittedDataQuery). > But, if I create _pg_query by defined way, it creates new session and, s

Re: [sqlalchemy] Re: Specify query_cls for the one query

2016-07-12 Thread Simon King
Could you describe what you are trying to achieve? There's nothing about Mike's suggestion that means you need to create a new session - you can reuse any existing session. What does your CustomQueryCls do? Perhaps there's another way of doing what you want? Simon On Tue, Jul 12, 2016 at 11:09

Re: [sqlalchemy] How to generate a file with DDL in the engine's SQL dialect? How to copy engine?

2016-05-11 Thread Simon King
On Wed, May 11, 2016 at 10:37 AM, Piotr Dobrogost <p...@2016.groups.google.dobrogost.net> wrote: >> On Wednesday, May 11, 2016 at 11:03:57 AM UTC+2, Simon King wrote: >>> On Wed, May 11, 2016 at 9:39 AM, Piotr Dobrogost >>> >>> What's the reaso

Re: [sqlalchemy] How to generate a file with DDL in the engine's SQL dialect? How to copy engine?

2016-05-11 Thread Simon King
On Wed, May 11, 2016 at 9:39 AM, Piotr Dobrogost wrote: > On Monday, May 9, 2016 at 5:05:11 PM UTC+2, Mike Bayer wrote: >> >> >> the only thing that is sigificant with "mock" is the first part of the >> URL. You can just send the whole URL though, so just

Re: [sqlalchemy] How to generate a file with DDL in the engine's SQL dialect? How to copy engine?

2016-05-10 Thread Simon King
On Tue, May 10, 2016 at 12:37 PM, Piotr Dobrogost wrote: > On Monday, May 9, 2016 at 5:05:11 PM UTC+2, Mike Bayer wrote: >> >> >> the only thing that is sigificant with "mock" is the first part of the >> URL. You can just send the whole URL though, so just

Re: [sqlalchemy] Trying to create string array columns with Alembic gives "NameError: name 'String' is not defined"

2016-04-26 Thread Simon King
On Tue, Apr 26, 2016 at 1:28 PM, Duke Dougal wrote: > Hi folks, > > > Model is below plus error message below that. > > > I am trying to create some array columns using Alembic but getting errors. > > > Any help valued. > > > thanks! > > > > from sqlalchemy import Column,

Re: [sqlalchemy] Generic mixin classes and relationship

2016-04-24 Thread Simon King
> On 24 Apr 2016, at 13:50, Jimmy Thrasibule wrote: > > I'm working on a SQLAlchemy defining a bunch of mixin classes that > applications should be able to import and extend their model. > > When looking at the documentation, mixin classes are create knowing the >

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

2016-03-29 Thread Simon King
g > target.overview_flavor.rating_count += 1 > > > event.listen(ProductOverviewReview, 'after_insert', > reviews_after_insert_listener) > > > четверг, 25 февраля 2016 г., 15:41:03 UTC+2 пользователь Simon King > написал: >> >> Er, ok. There are simpler ways to

Re: [sqlalchemy] Too slow commit?

2016-03-22 Thread Simon King
It sounds like the transaction for task B is starting before A's transaction has been committed, but you haven't really given enough information to debug further. How are you managing your sessions and transactions? Do B and A actually overlap (ie. does B start before A finishes)? Simon On Tue,

Re: [sqlalchemy] Re: order by child object's field

2016-03-22 Thread Simon King
For what it's worth, SQLAlchemy usually does add the join condition for you, based on your relationship definitions. But the second parameter to query.join() is an optional expression that *replaces* the join condition that would normally be generated. Simon On Mon, Mar 21, 2016 at 5:42 PM,

Re: [sqlalchemy] Re: order by child object's field

2016-03-21 Thread Simon King
On Mon, Mar 21, 2016 at 5:21 PM, wrote: > Hi Michal > > > q.join(ReferenceAuthor, ReferenceAuthor.c.Index == 0) > > Ah, of course! Thank you very much! > > But... ;) > > This Python code > > return self.session.query(Reference) \ >

Re: [sqlalchemy] Modeling single FK to multiple tables

2016-03-21 Thread Simon King
Can you extract your code into a single standalone script that demonstrates the problem? This should be possible even with automap; the script can start by creating just the tables that are involved in this problem (ideally in an in-memory sqlite db), then use automap to map classes to those

Re: [sqlalchemy] Re: order by child object's field

2016-03-21 Thread Simon King
On Mon, Mar 21, 2016 at 3:05 PM, wrote: > On 2016-03-20 13:12 Jonathan Vanasco wrote: > > .contains_eager('_periodical')\ # this lets sqlalchemy > > This eager-loading thing is a nice hint. I will use this in the future. > Thanks. > > I

Re: [sqlalchemy] how can I search rows containing jsonb data on the basis of it's key>

2016-03-19 Thread Simon King
On Fri, Mar 18, 2016 at 5:12 AM, Krishnakant <krm...@openmailbox.org> wrote: > > > On Thursday 17 March 2016 03:46 PM, Simon King wrote: > > On Thu, Mar 17, 2016 at 7:19 AM, Krishnakant <krm...@openmailbox.org> > wrote: > >> Hello, >> I wish to search

Re: [sqlalchemy] how can I search rows containing jsonb data on the basis of it's key>

2016-03-19 Thread Simon King
On Thu, Mar 17, 2016 at 7:19 AM, Krishnakant wrote: > Hello, > I wish to search rows in my table on the basis of text of json keys. > My table has vouchercode, voucherdate, dramt, cramt. > Here dramt and cramt are both jsonb fields (postgresql 9.4). > dramt containes

Re: [sqlalchemy] Modeling single FK to multiple tables

2016-03-19 Thread Simon King
> On 17 Mar 2016, at 19:11, Alex Hall wrote: > > Hello all, > It seems like I can't go a day without running into some kind of wall. > This one is a conceptual one regarding foreign keys. I have to somehow > get the same FK column in table A pointing to IDs in tables B and C.

Re: [sqlalchemy] OperationalError with SQLite with simple update query

2016-03-19 Thread Simon King
On Wed, Mar 16, 2016 at 3:23 PM, Piotr Dobrogost < p...@2016.groups.google.dobrogost.net> wrote: > On Wednesday, March 16, 2016 at 3:51:16 PM UTC+1, Simon King wrote: >> >> On Wed, Mar 16, 2016 at 1:43 PM, Piotr Dobrogost < >> p...@2016.groups.google.dobrogost.net&g

Re: [sqlalchemy] alchemy expressionconfusion in insert statement having jsonb field

2016-03-16 Thread Simon King
> On 16 Mar 2016, at 06:45, Krishnakant wrote: > > Dear all, > I have a challenge which is confusing me. > I have a table called voucher with the following field. > (vid, vdate,Cr) where vid is integer, vdate is date and Cr is jsonb in > postgresql. > Can some one tell

Re: [sqlalchemy] Search in result

2016-03-16 Thread Simon King
> On 15 Mar 2016, at 22:13, Cecilio Ruiz wrote: > > Hi ! > > Assuming this result: > > n = session.query(xx).all() > > > How I can find the id 5 on the 'n' ? > something like that.: > > v = n.get(5) When you call “all()”, you’ve already loaded all the rows from the

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

2016-03-03 Thread Simon King
On Thu, Mar 3, 2016 at 12:01 PM, Krishnakant <krm...@openmailbox.org> wrote: > > > On Thursday 25 February 2016 03:50 PM, Simon King wrote: > > On Thu, Feb 25, 2016 at 9:43 AM, Krishnakant <krm...@openmailbox.org> > wrote: > >> Hello, >> I have a que

Re: [sqlalchemy] Assertion error on deleting one end of many-to-many relation

2016-03-03 Thread Simon King
On Thu, Mar 3, 2016 at 8:27 AM, Lele Gaifax wrote: > Hi all, > > I have a simple m2m relationship between two entities, with a secondary > table > in the middle. > > From the left item I need to read both the right items and the middle > ones, so > I have two relationships

Re: [sqlalchemy] replacing a filter attribute, or iterating over a booleanclauselist?

2016-03-02 Thread Simon King
Out of interest, how are you building your query, and why do you need to be able to change the values afterwards? Simon > On 2 Mar 2016, at 21:59, Brian Cherinka wrote: > > Thanks, Mike. This is excellent. That did the trick. That's much easier > than what I was

Re: [sqlalchemy] need help with query

2016-03-02 Thread Simon King
I don't understand that error - you're asking it to join along predefined relationships, so it shouldn't need to search for foreign keys at query time. "Category.products" is a relationship set up as the backref of Product.categories. Here's a working example. I had to add the definition of the

Re: [sqlalchemy] need help with query

2016-03-01 Thread Simon King
http://docs.sqlalchemy.org/en/rel_1_0/orm/tutorial.html#querying-with-joins You want something like: DBSession.query(Category).join(‘products’, ‘brand’).filter(Brand.slug==brand_slug) Hope that helps, Simon > On 1 Mar 2016, at 20:11, sector119 wrote: > > It works, but

Re: [sqlalchemy] Date range query problem

2016-03-01 Thread Simon King
On Tue, Mar 1, 2016 at 4:17 PM, Nana Okyere wrote: > Mike, thanks for your response. I turned on the echo to see the values. > Looks like it is passing a datetime.date objects. So I don't see a time > part of the date. Here's the relevant part of the echo output. > > I selected

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

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

2016-02-25 Thread Simon King
; 0)]).where( > 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

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 >> loaded i

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 >

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

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

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: > >

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

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

2016-02-19 Thread Simon King
t; 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 <si...@simonking.org.uk> wrote: > > According to > > > http://docs.sqlalchemy.org/en/rel_1_0/core/connections.htm

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

2016-02-19 Thread Simon King
> If I don't get that, 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 <si...@simonking.org.uk> wrote: > > URI prefixes

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

2016-02-19 Thread Simon King
server_info", 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 <si.

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

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

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

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

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

<    1   2   3   4   5   6   7   >