Re: [sqlalchemy] custom queries

2016-01-14 Thread Richard Gerd Kuesters
yeah, i know, it was just a shot in the dark. for me it's useful to 
prefilter some user queries, but not their relationships and others 
(like an audit system with soft delete). anyway, as you said, this 
already works now and i'll play around a little more with it :)


thanks for all your help, as always!
richard.


On 01/13/2016 06:59 PM, Mike Bayer wrote:

I can't imagine what such a "feature" would look like nor how it
wouldn't require every call everywhere in SQLA internals  well as all
dialects, 3rd party and otherwise, to always remember to mark itself in
some way, annotating the end-user statement as I illustrated is already
available now.

as


On 01/13/2016 01:46 PM, Richard Gerd Kuesters wrote:

yup! i already was going this way. it would be impossible to
"automagically" do this without the performance sacrifice ... lol. well,
if this looks reasonable in some use cases, can this sort of "feature"
be implemented in future sa releases?

best regards,
richard.

On 01/13/2016 04:41 PM, Mike Bayer wrote:

or, place a marker in your own queries:

query(User).execution_options(my_query=True).all()



On 01/13/2016 01:40 PM, Mike Bayer wrote:

similar, you'd need to use sys.exc_info() and walk through the stack
trace to programmatically determine the origin of a Python statement.
You could do this inside the before_execute() event, for example.




On 01/13/2016 01:31 PM, Richard Gerd Kuesters wrote:

Mike, thanks for your attention and i'm sorry, i was not clear enough in
my question.

i would like to know if there's a way to tell if a query was fired by
sqlalchemy internals or by my coded query (programatically).


thanks a lot!
richard.

On 01/13/2016 04:11 PM, Mike Bayer wrote:

sure, use pdb to step through and use the "where" command to show where
each call originates.

alternatively, if this is for profiling, you can use print_callers() as
in the example at
http://docs.sqlalchemy.org/en/rel_1_0/faq/performance.html#code-profiling which
will show the origins of calls, though you'd need to step through things
to see the full chain.  A tool like RunSnakeRun can provide a graphical
display instead.


On 01/13/2016 11:58 AM, Richard Gerd Kuesters wrote:

hi all!

i'm wondering if there's a way to determinate if a query was "launch" by
my code (ex. session.query(Entity)...) or by the internals of sqlalchemy
(backref, relationship, etc). i think it's better to use a example,
based on *adjacency_list.py*:

http://pastebin.com/q3yx36vn

in the code, you'll notice there's only one query *literally* written
(in the main script), but "STEP" is called more than once (by
internals). my question is: can I differ between them?

thanks a lot!
richard.

--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
<>

Re: [sqlalchemy] custom queries

2016-01-13 Thread Richard Gerd Kuesters
Mike, thanks for your attention and i'm sorry, i was not clear enough in 
my question.


i would like to know if there's a way to tell if a query was fired by 
sqlalchemy internals or by my coded query (programatically).



thanks a lot!
richard.

On 01/13/2016 04:11 PM, Mike Bayer wrote:

sure, use pdb to step through and use the "where" command to show where
each call originates.

alternatively, if this is for profiling, you can use print_callers() as
in the example at
http://docs.sqlalchemy.org/en/rel_1_0/faq/performance.html#code-profiling which
will show the origins of calls, though you'd need to step through things
to see the full chain.  A tool like RunSnakeRun can provide a graphical
display instead.


On 01/13/2016 11:58 AM, Richard Gerd Kuesters wrote:

hi all!

i'm wondering if there's a way to determinate if a query was "launch" by
my code (ex. session.query(Entity)...) or by the internals of sqlalchemy
(backref, relationship, etc). i think it's better to use a example,
based on *adjacency_list.py*:

http://pastebin.com/q3yx36vn

in the code, you'll notice there's only one query *literally* written
(in the main script), but "STEP" is called more than once (by
internals). my question is: can I differ between them?

thanks a lot!
richard.

--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
<>

Re: [sqlalchemy] custom queries

2016-01-13 Thread Richard Gerd Kuesters
yup! i already was going this way. it would be impossible to 
"automagically" do this without the performance sacrifice ... lol. well, 
if this looks reasonable in some use cases, can this sort of "feature" 
be implemented in future sa releases?


best regards,
richard.

On 01/13/2016 04:41 PM, Mike Bayer wrote:

or, place a marker in your own queries:

query(User).execution_options(my_query=True).all()



On 01/13/2016 01:40 PM, Mike Bayer wrote:


similar, you'd need to use sys.exc_info() and walk through the stack
trace to programmatically determine the origin of a Python statement.
You could do this inside the before_execute() event, for example.




On 01/13/2016 01:31 PM, Richard Gerd Kuesters wrote:

Mike, thanks for your attention and i'm sorry, i was not clear enough in
my question.

i would like to know if there's a way to tell if a query was fired by
sqlalchemy internals or by my coded query (programatically).


thanks a lot!
richard.

On 01/13/2016 04:11 PM, Mike Bayer wrote:

sure, use pdb to step through and use the "where" command to show where
each call originates.

alternatively, if this is for profiling, you can use print_callers() as
in the example at
http://docs.sqlalchemy.org/en/rel_1_0/faq/performance.html#code-profiling which
will show the origins of calls, though you'd need to step through things
to see the full chain.  A tool like RunSnakeRun can provide a graphical
display instead.


On 01/13/2016 11:58 AM, Richard Gerd Kuesters wrote:

hi all!

i'm wondering if there's a way to determinate if a query was "launch" by
my code (ex. session.query(Entity)...) or by the internals of sqlalchemy
(backref, relationship, etc). i think it's better to use a example,
based on *adjacency_list.py*:

http://pastebin.com/q3yx36vn

in the code, you'll notice there's only one query *literally* written
(in the main script), but "STEP" is called more than once (by
internals). my question is: can I differ between them?

thanks a lot!
richard.

--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
<>

[sqlalchemy] custom queries

2016-01-13 Thread Richard Gerd Kuesters

hi all!

i'm wondering if there's a way to determinate if a query was "launch" by 
my code (ex. session.query(Entity)...) or by the internals of sqlalchemy 
(backref, relationship, etc). i think it's better to use a example, 
based on *adjacency_list.py*:


http://pastebin.com/q3yx36vn

in the code, you'll notice there's only one query *literally* written 
(in the main script), but "STEP" is called more than once (by 
internals). my question is: can I differ between them?


thanks a lot!
richard.

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
<>

[sqlalchemy] pgsql + jsonb + orm update = possible bug?

2015-10-09 Thread Richard Gerd Kuesters
Hello! I was working with a JSONB column in postgres and I noticed that 
no updates were issued when changing some inside value, so I have to 
issue "*flag_modified*" everytime I change my JSONB attribute. Here's a 
sample code that shows this:


   # -*- coding: utf-8 -*-

   from __future__ import unicode_literals


   from sqlalchemy import Column, Integer, create_engine
   from sqlalchemy.orm import Session
   from sqlalchemy.orm.attributes import flag_modified
   from sqlalchemy.ext.hybrid import hybrid_property
   from sqlalchemy.ext.declarative import declarative_base
   from sqlalchemy.dialects.postgresql import JSONB


   Base = declarative_base()


   class EntityA(Base):
__tablename__ = 'entity_a'

a_id = Column(Integer, primary_key=True)
a_value = Column(JSONB, nullable=False)


   class EntityB(Base):
__tablename__ = 'entity_b'

b_id = Column(Integer, primary_key=True)
_b_value = Column(JSONB, nullable=False)

@hybrid_property
def b_value(self):
return self._b_value

@b_value.setter
def b_value(self, value):
self._b_value = value


   class EntityC(Base):
__tablename__ = 'entity_c'

c_id = Column(Integer, primary_key=True)
_c_value = Column(JSONB, nullable=False)

@hybrid_property
def c_value(self):
return self._c_value

@c_value.setter
def c_value(self, value):
self._c_value = value
flag_modified(self, '_c_value')


   if __name__ == '__main__':
engine =
   create_engine('postgresql://test:test123@127.0.0.1/testing', echo=False)
Base.metadata.create_all(engine)
session = Session(engine)

# testing A, without hybrid property

a_test = EntityA()
a_test.a_value = dict(hello='world', test=1, enabled=True)

session.add(a_test)
session.commit()

print('EntityA, after insert:', a_test.a_value)

json_obj_a = a_test.a_value
json_obj_a['hello'] = 'foo'
a_test.a_value = json_obj_a

session.commit()

# assert a_test.a_value.get('hello') == 'foo'  # error
assert a_test.a_value.get('hello') == 'world'  # works

print('EntityA, after update:', a_test.a_value)

# testing B, with hybrid property and no flag_modified

b_test = EntityB()
b_test.b_value = dict(hello='world', test=1, enabled=True)

session.add(b_test)
session.commit()

print('EntityB, after insert:', b_test.b_value)

json_obj_b = b_test.b_value
json_obj_b['hello'] = 'bar'
b_test.b_value = json_obj_b

session.commit()

# assert b_test.b_value.get('hello') == 'bar'  # error
assert b_test.b_value.get('hello') == 'world'  # works

print('EntityB, after update:', b_test.b_value)

# testing C, with hybrid property and flag_modified

c_test = EntityC()
c_test.c_value = dict(hello='world', test=1, enabled=True)

session.add(c_test)
session.commit()

print('EntityC, after insert:', c_test.c_value)

json_obj_c = c_test.c_value
json_obj_c['hello'] = 'baz'
c_test.c_value = json_obj_c

session.commit()

assert c_test.c_value.get('hello') == 'baz'  # works
# assert c_test.c_value.get('hello') == 'world'  # error

print('EntityC, after update:', c_test.c_value)

# end test
session.close()

Base.metadata.drop_all(engine)


extra data, if needed:

   $ pip freeze
   psycopg2==2.6.1
   SQLAlchemy==1.0.8

   $ postgres --version
   postgres (PostgreSQL) 9.4.4

   $ python --version
   Python 2.7.10

   $ uname -a
   Linux marrow.polluxnet 4.2.3-1-ARCH #1 SMP PREEMPT Sat Oct 3
   18:52:50 CEST 2015 x86_64 GNU/Linux


thanks a lot, if any other information is needed, please let me know.


best regards,
richard.

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
<>

Re: [sqlalchemy] pgsql + jsonb + orm update = possible bug?

2015-10-09 Thread Richard Gerd Kuesters
thanks Mike! I'm glad I used a "?" in the subject :) I was thinking that 
something may be missing, so there it is ...


cheers,
richard.

On 10/09/2015 10:11 AM, Mike Bayer wrote:


I see no usage of Mutable, which is required if you want to detect 
updates within a JSON value. 


--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
<>

Re: [sqlalchemy] one-to-one: lost on track

2015-10-01 Thread Richard Gerd Kuesters
ok, just for the record, my "lazyness" lead me to use `lazy='joined'` in 
a backref and now things works fine :)


richard.


On 10/01/2015 09:03 AM, Richard Gerd Kuesters wrote:

hey all!

i think i got lost on track about relationships, specially one-to-one. 
i'll not go into (code) details because all my one-to-one are failing 
with the following exception:

*
*

*python2.7/site-packages/sqlalchemy/orm/query.pyc in
_no_criterion_assertion(self, meth, order_by, distinct)*
*361 raise sa_exc.InvalidRequestError(*
*362 "Query.%s() being called on a "*
*--> 363 "Query with existing criterion. " % meth)*
*364 *
*365 def _no_criterion_condition(self, meth,
order_by=True, distinct=True):*

*InvalidRequestError: Query.get() being called on a Query with
existing criterion.*


*i think* this happens because i have a custom session that applies a 
filter to all objects queried, even `session.query(A).first()`. 
perhaps someone got stuck on the same problem? faq? anything? :)


best regards and sorry for my possible irresponsible lazyness,

richard.
--
You received this message because you are subscribed to the Google 
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com 
<mailto:sqlalchemy@googlegroups.com>.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
<>

[sqlalchemy] one-to-one: lost on track

2015-10-01 Thread Richard Gerd Kuesters

hey all!

i think i got lost on track about relationships, specially one-to-one. 
i'll not go into (code) details because all my one-to-one are failing 
with the following exception:

*
*

   *python2.7/site-packages/sqlalchemy/orm/query.pyc in
   _no_criterion_assertion(self, meth, order_by, distinct)*
   *361 raise sa_exc.InvalidRequestError(*
   *362 "Query.%s() being called on a "*
   *--> 363 "Query with existing criterion. " % meth)*
   *364 *
   *365 def _no_criterion_condition(self, meth, order_by=True,
   distinct=True):*

   *InvalidRequestError: Query.get() being called on a Query with
   existing criterion.*


*i think* this happens because i have a custom session that applies a 
filter to all objects queried, even `session.query(A).first()`. perhaps 
someone got stuck on the same problem? faq? anything? :)


best regards and sorry for my possible irresponsible lazyness,

richard.

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
<>

Re: [sqlalchemy] Question about FAQ entry titled "I’m getting a warning or error about “Implicitly combining column X under attribute Y”"

2015-09-08 Thread Richard Gerd Kuesters

is your "A" class abstract and/or are you using them with polymorphism?


regards,
richard.


On 09/08/2015 07:00 AM, Piotr Dobrogost wrote:

Hi!

In the FAQ there's entry titled "I’m getting a warning or error about 
“Implicitly combining column X under attribute Y”" with the following 
example:


class A(Base):
__tablename__ = 'a'
id = Column(Integer, primary_key=True)

class B(A):
__tablename__ = 'b'
# probably not what you want, but this is a demonstration
id = column_property(Column(Integer, primary_key=True), A.id)
a_id = Column(Integer, ForeignKey('a.id'))


However trying to add yet another class just to see what happens...

class C(B):
__tablename__ = 'c'

id = column_property(Column(Integer, primary_key=True), B.id)
b_id = Column(Integer, ForeignKey('b.id'))


...results in the same kind of error again:
"sqlalchemy.exc.InvalidRequestError: Implicitly combining column b.id 
with column a.id under attribute 'id'.  Please configure one or more 
attributes for these same-named columns explicitly."


How to avoid this?

ps.
This is a follow-up to my recent post 
https://groups.google.com/forum/#!topic/sqlalchemy/n_JEgKYshnE


--
You received this message because you are subscribed to the Google 
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
.
To post to this group, send email to sqlalchemy@googlegroups.com 
.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
<>

Re: [sqlalchemy] Question about FAQ entry titled "I’m getting a warning or error about “Implicitly combining column X under attribute Y”"

2015-09-08 Thread Richard Gerd Kuesters
well, i'm sorry if i'm pouring could water on you but continuum never 
worked as expected (at least for me) and i always used history_meta for 
audit, which comes packaged with sqlalchemy as an example and is much 
more friendly if you need to add functionalities on your own :)


cheers,
richard.

link to it: 
http://docs.sqlalchemy.org/en/rel_1_0/_modules/examples/versioned_history/history_meta.html


On 09/08/2015 11:24 AM, Piotr Dobrogost wrote:

On Tuesday, September 8, 2015 at 1:37:05 PM UTC+2, Richard Kuesters wrote:

| is your "A" class abstract and/or are you using them with polymorphism?

Thank you for taking time to look at this.
If by abstract you mean abstract as defined at 
http://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/api.html?highlight=__abstract__#abstract 
then no, it's not abstract. As to polymorphism the answer is not so 
simple. Basically using this example I tried to depict situation which 
I believe takes place in SQLAlchemy-Continuum extension. This 
extension for every model creates another one recording all changes to 
the original one. Original models are polymorphic (and use joined 
table inheritance) and create simple hierarchy Node -> Content -> 
Document which can be seen at 
https://github.com/Kotti/Kotti/blob/9a8684c10fbb3c6fbf6b1265c86b732e1c416c4a/kotti/resources.py 
I'm not sure if models created by versioning extension (NodeVersion, 
ContentVersion and DocumentVersion) are meant to be polymorphic 
(supposedly as a consequence of original models being polymorphic) or 
not. Each of these models has "transaction_id" attribute mapped to 
"transaction_id" column in mapped table. The error is 
"sqlalchemy.exc.InvalidRequestError: Implicitly combining column 
contents_version.transaction_id with column 
nodes_version.transaction_id under attribute 'transaction_id'. Please 
configure one or more attributes for these same-named columns 
explicitly." By extending example from FAQ I wanted to understand 
under what circumstances could same-named columns be made to work.


Regards,
Piotr

--
You received this message because you are subscribed to the Google 
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
.
To post to this group, send email to sqlalchemy@googlegroups.com 
.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
<>

Re: [sqlalchemy] What about bit fields / bit masks?

2015-08-29 Thread Richard Gerd Kuesters
IMHO, it is better to use ints for masks because they can be indexed by 
the database. AFAIK, bits can't be indexed and any bit operator in a 
query (let's say, WHERE mybit  MYMASK) would probably result in a 
full table scan.


well, it's just my two cents from an info I got a long time ago. I might 
be wrong now, so ...



best regards,
Richard.

On 08/27/2015 06:54 AM, Cornelius Kölbel wrote:

Hello,

this is maybe more about the database design.

I want to store several boolean states of an object.
The object may also have more than one state and the available possible
states may increase in future.
So I want to avoid adding BOOL columns for every new state and I though,
hey, what about bit fields - one column, that can store many boolean
information/flags.

I understand that MySQL provides a datatype BIT, but which may lead to
problems, depending on the version and table type.
What about sqlalchemy?
Is there a reasonable way to use bit masks?

Would you recommend anyway to avoid such a design, since it is not that
what SQL originally was designed for?
I also want the program to be able to run on mysql or postgres or
whatever. So maybe choosing bit masks is a bad idea anyway, since it
might lead to problems with different database backends?

Thanks a lot for your thoughts
Cornelius



--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

[sqlalchemy] polymorphic_identity as an expression

2015-08-20 Thread Richard Gerd Kuesters

hello!

is it possible to set the polymorphic_identity mapper param as an 
expression?


example:

   __mapper_args__ = {
polymorphic_identity: in_('employee', 'recruit')
   }



thanks a lot,
richard.

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] polymorphic_identity as an expression

2015-08-20 Thread Richard Gerd Kuesters
thanks mike! that's what i thought, but was wondering if there were a 
shortcut using identity :)


cheers,
richard.


On 08/20/2015 12:15 PM, Mike Bayer wrote:
polymorphic_identity, no.  polymorphic_on, yes.work it from that 
end instead (e.g. using CASE).





On 8/20/15 10:05 AM, Richard Gerd Kuesters wrote:

hello!

is it possible to set the polymorphic_identity mapper param as an 
expression?


example:

__mapper_args__ = {
polymorphic_identity: in_('employee', 'recruit')
}



thanks a lot,
richard.
--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] loops and session

2015-08-06 Thread Richard Gerd Kuesters

thanks Mike!

ok, going further then:

1. i'm using postgres (isolation_level=REPEATABLE READ);
2. it's inside a twisted app, into a defer, _but_ the session lifecycle 
starts and ends in that defer;
3. in that same (python) process, there's a txpostgres connection 
ongoing (in another twisted defer anywhere).


can some of that cause any interference that can cause this behaviour?




On 08/06/2015 03:29 PM, Mike Bayer wrote:



On 8/6/15 1:50 PM, Richard Gerd Kuesters wrote:

well, i ran today into an issue i never seen before.

considering this simple example:

session = get_session()
objs = []

for ign in xrange(10):
o = NewObject()
objs.append(o)

session.add_all(objs)
session.commit()

for obj in objs:
print obj in session


this will print True only in the first iteration. basically, the 
other objects are not bound to a session anymore. is there any reason 
for this, or am i doing something wrong?


cant reproduce:

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()


class NewObject(Base):
__tablename__ = 'a'
id = Column(Integer, primary_key=True)

e = create_engine(sqlite://, echo=True)
Base.metadata.create_all(e)

session = Session(e)

objs = []

for ign in xrange(10):
o = NewObject()
objs.append(o)

session.add_all(objs)
session.commit()

for obj in objs:
print obj in session

output:

sql stuff...
2015-08-06 14:28:58,563 INFO sqlalchemy.engine.base.Engine COMMIT
True
True
True
True
True
True
True
True
True
True







best regards,
richard.
--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

[sqlalchemy] loops and session

2015-08-06 Thread Richard Gerd Kuesters

well, i ran today into an issue i never seen before.

considering this simple example:

   session = get_session()
   objs = []

   for ign in xrange(10):
o = NewObject()
objs.append(o)

   session.add_all(objs)
   session.commit()

   for obj in objs:
print obj in session


this will print True only in the first iteration. basically, the other 
objects are not bound to a session anymore. is there any reason for 
this, or am i doing something wrong?


best regards,
richard.

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] loops and session

2015-08-06 Thread Richard Gerd Kuesters
well, the whole function itself is not async (where the session gets 
created and closed), neither the psycopg2 connection, but inside this 
chaos, providing the function to run into it's own thread seems to work 
now ... go figure.


thanks! :)


On 08/06/2015 04:19 PM, Mike Bayer wrote:



On 8/6/15 3:03 PM, Richard Gerd Kuesters wrote:

thanks Mike!

ok, going further then:

1. i'm using postgres (isolation_level=REPEATABLE READ);
2. it's inside a twisted app, into a defer, _but_ the session 
lifecycle starts and ends in that defer;
3. in that same (python) process, there's a txpostgres connection 
ongoing (in another twisted defer anywhere).


can some of that cause any interference that can cause this behaviour?


inside of a twisted defer and this is not inside a threadpool? 
absolutely.  that's entirely chaotic and anything goes.ironic 
considering the simple and safe promises of explicit async code !










On 08/06/2015 03:29 PM, Mike Bayer wrote:



On 8/6/15 1:50 PM, Richard Gerd Kuesters wrote:

well, i ran today into an issue i never seen before.

considering this simple example:

session = get_session()
objs = []

for ign in xrange(10):
o = NewObject()
objs.append(o)

session.add_all(objs)
session.commit()

for obj in objs:
print obj in session


this will print True only in the first iteration. basically, the 
other objects are not bound to a session anymore. is there any 
reason for this, or am i doing something wrong?


cant reproduce:

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()


class NewObject(Base):
__tablename__ = 'a'
id = Column(Integer, primary_key=True)

e = create_engine(sqlite://, echo=True)
Base.metadata.create_all(e)

session = Session(e)

objs = []

for ign in xrange(10):
o = NewObject()
objs.append(o)

session.add_all(objs)
session.commit()

for obj in objs:
print obj in session

output:

sql stuff...
2015-08-06 14:28:58,563 INFO sqlalchemy.engine.base.Engine COMMIT
True
True
True
True
True
True
True
True
True
True







best regards,
richard.
--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.

To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] set vs after_flush events

2015-07-24 Thread Richard Gerd Kuesters

will this answer my second question?

 obj._sa_instance_state.committed_state
{'batch_status': STARTED(db=1),
 'updated_by': 24769797950537744L,
 'updated_on': Arrow [2015-07-24T14:02:03.360479-03:00]}

cheers,
richard.

On 07/24/2015 11:13 AM, Richard Gerd Kuesters wrote:

hi!

first, /yes/, set and after_flush are quite different events :) but 
here's what i'm trying to accomplish:


one object have an attribute, like 'state', and i would like to 
monitor and trigger some other methods if (given scenarios):


1. the program sets a new value to a state that is equal to it's 
actual state (and/or value), i can use 'set' but, does it reflect only 
the value set or when it gets commited?
1.1. and, if set to the same value, returning the old value (set with 
retval=True) will make this object dirty (supposed to be the only 
value modified) ?
2. after_flush, if one of these entity get's modified, can i track 
down what was modified, including my state column if possible?


cheers,
richard.
--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] set vs after_flush events

2015-07-24 Thread Richard Gerd Kuesters


On 07/24/2015 12:59 PM, Mike Bayer wrote:



On 7/24/15 10:13 AM, Richard Gerd Kuesters wrote:

hi!

first, /yes/, set and after_flush are quite different events :) but 
here's what i'm trying to accomplish:


one object have an attribute, like 'state', and i would like to 
monitor and trigger some other methods if (given scenarios):


1. the program sets a new value to a state that is equal to it's 
actual state (and/or value), i can use 'set' but, does it reflect 
only the value set or when it gets commited?
you set the value to the attribute, the set event receives it, if 
the attribute already *had* that value loaded then the history is a 
no-net change, no UPDATE is emitted.  If the attribute did not already 
have a value loaded, and the attribute does not specify 
active_history, then we don't know the old value and the history 
will show that the attribute has changed, from a previous value of 
NO_VALUE.


I don't know what does it reflect only the value set or when it gets 
committed means, hopefully the above answers your question.


yup, it does answer it! i'm aware of the active_history, I was just 
wondering when an updated is stated, but it seems that you already took 
care of this job :)


1.1. and, if set to the same value, returning the old value (set with 
retval=True) will make this object dirty (supposed to be the only 
value modified) ?
the object goes into session.dirty as soon as any attributes are set.  
however, in the flush, we go through the effort to look for actual net 
changes.  If there's no net change on the attribute, no UPDATE will be 
emitted in the flush, the object moves back to clean at that point.


2. after_flush, if one of these entity get's modified, can i track 
down what was modified, including my state column if possible?
yes you can look in session.dirty to find all the objects that are 
dirty, then looking in committed_state will illustrate those 
attribute that had something happen to them; though the latter part 
here is not a public system - it will work for now but I can't 
guarantee that in a future major version bump that system wouldn't 
change.   We can add public API to return .modified, e.g. a list of 
keys that received a modified event.



--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] set vs after_flush events

2015-07-24 Thread Richard Gerd Kuesters
 obj._sa_instance_state.committed_state.get('key') == 
obj._sa_instance_state.dict.get('key')

False

is this all that's necessary to track down what's modified and the past 
state (i believe to be sa_instance_state.dict) ?


cheers,
richard.

On 07/24/2015 11:34 AM, Richard Gerd Kuesters wrote:

will this answer my second question?

 obj._sa_instance_state.committed_state
{'batch_status': STARTED(db=1),
 'updated_by': 24769797950537744L,
 'updated_on': Arrow [2015-07-24T14:02:03.360479-03:00]}

cheers,
richard.

On 07/24/2015 11:13 AM, Richard Gerd Kuesters wrote:

hi!

first, /yes/, set and after_flush are quite different events :) but 
here's what i'm trying to accomplish:


one object have an attribute, like 'state', and i would like to 
monitor and trigger some other methods if (given scenarios):


1. the program sets a new value to a state that is equal to it's 
actual state (and/or value), i can use 'set' but, does it reflect 
only the value set or when it gets commited?
1.1. and, if set to the same value, returning the old value (set with 
retval=True) will make this object dirty (supposed to be the only 
value modified) ?
2. after_flush, if one of these entity get's modified, can i track 
down what was modified, including my state column if possible?


cheers,
richard.
--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] Re: set vs after_flush events

2015-07-24 Thread Richard Gerd Kuesters
well, as a general non-specific view yes, it can be another approach. 
but, for the piece of code that drove me to this question, i really need 
to use after_flush  :)


cheers,
richard.

On 07/24/2015 02:15 PM, Jonathan Vanasco wrote:

Couldn't you handle much of this with the Descriptors/Hybrids pattern?

http://docs.sqlalchemy.org/en/latest/orm/mapped_attributes.html#using-descriptors-and-hybrids


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] Re: set vs after_flush events

2015-07-24 Thread Richard Gerd Kuesters
well, application-wise it is really to run other procedures, not from 
the database or python side, but from a message broker that's expecting 
anything to happen to that value -- even if it's just a touch :)


err ... it's quite a specific architecture for dumb clients, so i'm just 
taking some extra security measures ;)



On 07/24/2015 02:52 PM, Jonathan Vanasco wrote:


On Friday, July 24, 2015 at 1:20:15 PM UTC-4, Richard Kuesters wrote:

well, as a general non-specific view yes, it can be another
approach. but, for the piece of code that drove me to this
question, i really need to use after_flush  :)



Well I mean... you could use that pattern to catch and annotate the 
object with I've changed! info, then do your cleanup in the after_flush.


What popped into my mind as another use-case is this: touching an 
object's property to mark it dirty (even if SqlAlchemy doesn't 
interpret it as such, because the value is the same), then if it's not 
updated in the flush event, send the update anyways -- so a db-side 
stored procedure runs.

--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] set vs after_flush events

2015-07-24 Thread Richard Gerd Kuesters

yes, a public api would be awesome, perhaps for a future version? :)

for now, i'll stick to that -- since it works, heh.


cheers,
richard.


On 07/24/2015 12:59 PM, Mike Bayer wrote:



On 7/24/15 10:45 AM, Richard Gerd Kuesters wrote:
 obj._sa_instance_state.committed_state.get('key') == 
obj._sa_instance_state.dict.get('key')

False

is this all that's necessary to track down what's modified and the 
past state (i believe to be sa_instance_state.dict) ?


I'd prefer you use the public APIs but sure, those are the mechanics 
of it right now.







cheers,
richard.

On 07/24/2015 11:34 AM, Richard Gerd Kuesters wrote:

will this answer my second question?

 obj._sa_instance_state.committed_state
{'batch_status': STARTED(db=1),
 'updated_by': 24769797950537744L,
 'updated_on': Arrow [2015-07-24T14:02:03.360479-03:00]}

cheers,
richard.

On 07/24/2015 11:13 AM, Richard Gerd Kuesters wrote:

hi!

first, /yes/, set and after_flush are quite different events :) but 
here's what i'm trying to accomplish:


one object have an attribute, like 'state', and i would like to 
monitor and trigger some other methods if (given scenarios):


1. the program sets a new value to a state that is equal to it's 
actual state (and/or value), i can use 'set' but, does it reflect 
only the value set or when it gets commited?
1.1. and, if set to the same value, returning the old value (set 
with retval=True) will make this object dirty (supposed to be the 
only value modified) ?
2. after_flush, if one of these entity get's modified, can i track 
down what was modified, including my state column if possible?


cheers,
richard.
--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.

To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

[sqlalchemy] set vs after_flush events

2015-07-24 Thread Richard Gerd Kuesters

hi!

first, /yes/, set and after_flush are quite different events :) but 
here's what i'm trying to accomplish:


one object have an attribute, like 'state', and i would like to monitor 
and trigger some other methods if (given scenarios):


1. the program sets a new value to a state that is equal to it's actual 
state (and/or value), i can use 'set' but, does it reflect only the 
value set or when it gets commited?
1.1. and, if set to the same value, returning the old value (set with 
retval=True) will make this object dirty (supposed to be the only value 
modified) ?
2. after_flush, if one of these entity get's modified, can i track down 
what was modified, including my state column if possible?


cheers,
richard.

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] Re: set vs after_flush events

2015-07-24 Thread Richard Gerd Kuesters
yeah, that's basically what i'm doing: gathering information about 
what's happening and sending a response as quick as i can, since most of 
the clients are step machines (they still exists), so ... :)


On 07/24/2015 04:01 PM, Jonathan Vanasco wrote:


On Friday, July 24, 2015 at 2:06:15 PM UTC-4, Richard Kuesters wrote:

well, application-wise it is really to run other procedures, not
from the database or python side, but from a message broker that's
expecting anything to happen to that value -- even if it's just a
touch :)

err ... it's quite a specific architecture for dumb clients, so
i'm just taking some extra security measures ;)


It's not really that dump of an architecture.  I picked up on the 
value/importance of a simple touch.


Just throwing out some more ideas...

We have a caching system in place for public data for a pyramid app 
using SqlAlchemy and Dogpile(redis).  When objects are fetched form 
the cache, a `postcache` hook is performed and... if the object 
requires a lot of processing... it can register the object and an 
action into a global pool.  We then use an event in Pyramid to pop and 
process everything in the pool.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] best books on DB design for sqlalchemy users?

2015-07-23 Thread Richard Gerd Kuesters
not quite sqlalchemy related, but one of the best readings i've had 
about sql was SQL Anti-Patterns: 
https://pragprog.com/book/bksqla/sql-antipatterns


it is not about how to do sql right, it's about not to do certain types 
of sql, lol.




On 07/23/2015 01:35 PM, Rich Shepard wrote:

On Thu, 23 Jul 2015, Iain Duncan wrote:


I feel like I should really take up my db game for an upcoming set of
projects, and am wondering if there are any real standout books on db
design that fit well with the design philosophy of SQLA. Recos much
appreciated!


Iain,

  Read Joe Celko's books, starting with the latest edition of SQL for
Smarties. I read his columns in Database Advisor and other magazines 
in the
1980s and have read and used almost all his books. You can't go wrong 
taking

the time to do it correctly from the gitgo.

Rich


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] strange behavior in count with custom mapper option

2015-07-16 Thread Richard Gerd Kuesters
yeah, that's a little confusing for most people (including me), but a 
simple session.query(func.count(Entity.id_)).filter(...).scalar() solved 
the issue, since it produces a statement close to what i really want.


Mike, thanks for your time! :)

best regards,
richard.


On 07/15/2015 07:50 PM, Mike Bayer wrote:

there's your two rows:

 Row (None, 24769797950537732L, datetime.datetime(2015, 7, 15, 17, 49, 
57, 410290, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=-180, 
name=None)), datetime.datetime(2015, 7, 15, 17, 49, 57, 410305, 
tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=-180, name=None)), 0L, 
24769797950537768L, 24769797950537768L, 24769797950537729L, 
u'Workstation Super Legal do Richard', '10.0.0.2', 2, 1, 50, 0)



Row (None, 24769797950537732L, datetime.datetime(2015, 7, 15, 17, 49, 
57, 410290, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=-180, 
name=None)), datetime.datetime(2015, 7, 15, 17, 49, 57, 410305, 
tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=-180, name=None)), 0L, 
24769797950537768L, 24769797950537768L, 24769797950537729L, 
u'Workstation Super Legal do Richard', '10.0.0.2', 2, 1, 50, 0)



and you can see they both are the same.  therefore count of 2, .all() 
gives you one object.




On 7/15/15 3:58 PM, Richard Gerd Kuesters wrote:

right! sorry, now here we go (again):

(Pdb) import logging
(Pdb) logging.basicConfig()
(Pdb) logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG)
(Pdb)  session.query(MachineUnit).filter(MachineUnit.id_ ==
24769797950537768).count()
2015-07-15 16:56:44,565 INFO sqlalchemy.engine.base.Engine BEGIN
(implicit)
INFO:sqlalchemy.engine.base.Engine:BEGIN (implicit)
2015-07-15 16:56:44,566 INFO sqlalchemy.engine.base.Engine SELECT
count(*) AS count_1
FROM system_unit, (SELECT system_unit.fk_updated_by AS
system_unit_fk_updated_by, system_unit.fk_created_by AS
system_unit_fk_created_by, system_unit.dt_created_on AS
system_unit_dt_created_on, system_unit.dt_updated_on AS
system_unit_updated_on, system_unit.bi_rm_timestamp AS
system_unit_bi_rm_timestamp, machine_unit.pk_fk_system_unit_id AS
machine_unit_pk_fk_system_unit_id, system_unit.pk_system_unit_id
AS system_unit_pk_system_unit_id, system_unit.fk_organization_id
AS system_unit_fk_organization_id, system_unit.u_system_unit_name
AS system_unit_u_system_unit_name, system_unit.in_ipv4 AS
system_unit_in_ipv4, system_unit.p_system_unit_type AS
system_unit_system_unit_type, system_unit.i_version AS
system_unit_i_version, machine_unit.e_machine_type AS
machine_unit_e_machine_type, machine_unit.e_printer_type AS
machine_unit_e_printer_type
FROM system_unit JOIN machine_unit ON
system_unit.pk_system_unit_id = machine_unit.pk_fk_system_unit_id
WHERE machine_unit.pk_fk_system_unit_id = %(system_unit_id_1)s
AND system_unit.bi_rm_timestamp = %(rm_timestamp_1)s) AS anon_1
WHERE system_unit.bi_rm_timestamp = %(rm_timestamp_2)s
INFO:sqlalchemy.engine.base.Engine:SELECT count(*) AS count_1
FROM system_unit, (SELECT system_unit.fk_updated_by AS
system_unit_fk_updated_by, system_unit.fk_created_by AS
system_unit_fk_created_by, system_unit.dt_created_on AS
system_unit_dt_created_on, system_unit.dt_updated_on AS
system_unit_updated_on, system_unit.bi_rm_timestamp AS
system_unit_bi_rm_timestamp, machine_unit.pk_fk_system_unit_id AS
machine_unit_pk_fk_system_unit_id, system_unit.pk_system_unit_id
AS system_unit_pk_system_unit_id, system_unit.fk_organization_id
AS system_unit_fk_organization_id, system_unit.u_system_unit_name
AS system_unit_u_system_unit_name, system_unit.in_ipv4 AS
system_unit_in_ipv4, system_unit.p_system_unit_type AS
system_unit_system_unit_type, system_unit.i_version AS
system_unit_i_version, machine_unit.e_machine_type AS
machine_unit_e_machine_type, machine_unit.e_printer_type AS
machine_unit_e_printer_type
FROM system_unit JOIN machine_unit ON
system_unit.pk_system_unit_id = machine_unit.pk_fk_system_unit_id
WHERE machine_unit.pk_fk_system_unit_id = %(system_unit_id_1)s
AND system_unit.bi_rm_timestamp = %(rm_timestamp_1)s) AS anon_1
WHERE system_unit.bi_rm_timestamp = %(rm_timestamp_2)s
2015-07-15 16:56:44,566 INFO sqlalchemy.engine.base.Engine
{'rm_timestamp_1': 0, 'system_unit_id_1': 24769797950537768,
'rm_timestamp_2': 0}
INFO:sqlalchemy.engine.base.Engine:{'rm_timestamp_1': 0,
'system_unit_id_1': 24769797950537768, 'rm_timestamp_2': 0}
2015-07-15 16:56:44,567 DEBUG sqlalchemy.engine.base.Engine Col
('count_1',)
DEBUG:sqlalchemy.engine.base.Engine:Col ('count_1',)
2015-07-15 16:56:44,568 DEBUG sqlalchemy.engine.base.Engine Row (2L,)
DEBUG:sqlalchemy.engine.base.Engine:Row (2L,)
2L
(Pdb) len(session.query(MachineUnit).filter(MachineUnit.id_ ==
24769797950537768).all())
2015-07-15 16:57:06,070 INFO sqlalchemy.engine.base.Engine

[sqlalchemy] strange behavior in count with custom mapper option

2015-07-15 Thread Richard Gerd Kuesters

hello!

i'm encountering a weird behaviur with session.count() when using a 
custom mapper that implements a where condition to every session.


first, what is happening:

 len(session.query(Entity).all()) == 1
 session.query(Entity).count() == 2

Entity is a base polymorphic entity, inherited by other classes.

my custom mapper:

class DeletedOption(MapperOption):
propagate_to_loaders = True

def process_query(self, query):
mzo = query._mapper_zero()
if hasattr(mzo, 'class_'):
parent_cls = mzo.class_
filter_crit = parent_cls.rm_timestamp == 0

if query._criterion is None:
query._criterion = filter_crit
else:
query._criterion = query._criterion  filter_crit


i remember getting this custom mapper option in a recipe ... i'm running 
sqla 1.0.6. if there's any information i can provide to enlighten this 
out, please let me know.


best regards,
richard.

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] strange behavior in count with custom mapper option

2015-07-15 Thread Richard Gerd Kuesters

oh, forgot to mention:

* this occurs even with a filter that's supposed to bring one register 
only (at the database level it works);
* in the database level, a count *without* the where clause brings the 
result i mentioned earlier.



thanks,
richard.


On 07/15/2015 03:11 PM, Richard Gerd Kuesters wrote:

hello!

i'm encountering a weird behaviur with session.count() when using a 
custom mapper that implements a where condition to every session.


first, what is happening:

 len(session.query(Entity).all()) == 1
 session.query(Entity).count() == 2

Entity is a base polymorphic entity, inherited by other classes.

my custom mapper:

class DeletedOption(MapperOption):
propagate_to_loaders = True

def process_query(self, query):
mzo = query._mapper_zero()
if hasattr(mzo, 'class_'):
parent_cls = mzo.class_
filter_crit = parent_cls.rm_timestamp == 0

if query._criterion is None:
query._criterion = filter_crit
else:
query._criterion = query._criterion  filter_crit


i remember getting this custom mapper option in a recipe ... i'm 
running sqla 1.0.6. if there's any information i can provide to 
enlighten this out, please let me know.


best regards,
richard.
--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] strange behavior in count with custom mapper option

2015-07-15 Thread Richard Gerd Kuesters

does this happen even with a filter for a PK?

the problem is:

 session.query(Entity).filter(Entity.id_ == 
24769797950537768).count() == 2
 len(session.query(Entity).filter(Entity.id_ == 
24769797950537768).all()) == 1


i don't see where i have 2 pks with the same value ... in psql:

mydb=# select count(*) from entity where id_ = 24769797950537768;
 count
---
 1
(1 row)

is this really right?


On 07/15/2015 04:02 PM, Mike Bayer wrote:



On 7/15/15 2:11 PM, Richard Gerd Kuesters wrote:

hello!

i'm encountering a weird behaviur with session.count() when using a 
custom mapper that implements a where condition to every session.


first, what is happening:

 len(session.query(Entity).all()) == 1
 session.query(Entity).count() == 2


your all() query is returning two rows that have the same primary key 
for Entity.The Query object de-duplicates redundant rows based on 
entity identity.  Turn on echo='debug' and you should see this in the 
rows coming back.


we really need an FAQ entry for this one.




Entity is a base polymorphic entity, inherited by other classes.

my custom mapper:

class DeletedOption(MapperOption):
propagate_to_loaders = True

def process_query(self, query):
mzo = query._mapper_zero()
if hasattr(mzo, 'class_'):
parent_cls = mzo.class_
filter_crit = parent_cls.rm_timestamp == 0

if query._criterion is None:
query._criterion = filter_crit
else:
query._criterion = query._criterion  filter_crit


i remember getting this custom mapper option in a recipe ... i'm 
running sqla 1.0.6. if there's any information i can provide to 
enlighten this out, please let me know.


best regards,
richard.
--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] strange behavior in count with custom mapper option

2015-07-15 Thread Richard Gerd Kuesters

thanks Mike!

here we go:

   (Pdb) session.query(MachineUnit).filter(MachineUnit.id_ ==
   24769797950537768).count()
   2015-07-15 16:43:53,114 INFO sqlalchemy.engine.base.Engine SELECT
   count(*) AS count_1
   FROM system_unit, (SELECT system_unit.fk_updated_by AS
   system_unit_fk_updated_by, system_unit.fk_created_by AS
   system_unit_fk_created_by, system_unit.dt_created_on AS
   system_unit_dt_created_on, system_unit.dt_updated_on AS
   system_unit_updated_on, system_unit.bi_rm_timestamp AS
   system_unit_bi_rm_timestamp, machine_unit.pk_fk_system_unit_id AS
   machine_unit_pk_fk_system_unit_id, system_unit.pk_system_unit_id AS
   system_unit_pk_system_unit_id, system_unit.fk_organization_id AS
   system_unit_fk_organization_id, system_unit.u_system_unit_name AS
   system_unit_u_system_unit_name, system_unit.in_ipv4 AS
   system_unit_in_ipv4, system_unit.p_system_unit_type AS
   system_unit_system_unit_type, system_unit.i_version AS
   system_unit_i_version, machine_unit.e_machine_type AS
   machine_unit_e_machine_type, machine_unit.e_printer_type AS
   machine_unit_e_printer_type
   FROM system_unit JOIN machine_unit ON system_unit.pk_system_unit_id
   = machine_unit.pk_fk_system_unit_id
   WHERE machine_unit.pk_fk_system_unit_id = %(system_unit_id_1)s AND
   system_unit.bi_rm_timestamp = %(rm_timestamp_1)s) AS anon_1
   WHERE system_unit.bi_rm_timestamp = %(rm_timestamp_2)s
   2015-07-15 16:43:53,114 INFO sqlalchemy.engine.base.Engine
   {'system_unit_id_1': 24769797950537768, 'rm_timestamp_1': 0,
   'rm_timestamp_2': 0}
   2L
   (Pdb) len(session.query(MachineUnit).filter(MachineUnit.id_ ==
   24769797950537768).all())
   2015-07-15 16:44:32,891 INFO sqlalchemy.engine.base.Engine SELECT
   system_unit.fk_updated_by AS system_unit_fk_updated_by,
   system_unit.fk_created_by AS system_unit_fk_created_by,
   system_unit.dt_created_on AS system_unit_dt_created_on,
   system_unit.dt_updated_on AS system_unit_updated_on,
   system_unit.bi_rm_timestamp AS system_unit_bi_rm_timestamp,
   machine_unit.pk_fk_system_unit_id AS
   machine_unit_pk_fk_system_unit_id, system_unit.pk_system_unit_id AS
   system_unit_pk_system_unit_id, system_unit.fk_organization_id AS
   system_unit_fk_organization_id, system_unit.u_system_unit_name AS
   system_unit_u_system_unit_name, system_unit.in_ipv4 AS
   system_unit_in_ipv4, system_unit.p_system_unit_type AS
   system_unit_system_unit_type, system_unit.i_version AS
   system_unit_i_version, machine_unit.e_machine_type AS
   machine_unit_e_machine_type, machine_unit.e_printer_type AS
   machine_unit_e_printer_type
   FROM system_unit JOIN machine_unit ON system_unit.pk_system_unit_id
   = machine_unit.pk_fk_system_unit_id
   WHERE machine_unit.pk_fk_system_unit_id = %(system_unit_id_1)s AND
   system_unit.bi_rm_timestamp = %(rm_timestamp_1)s
   2015-07-15 16:44:32,891 INFO sqlalchemy.engine.base.Engine
   {'system_unit_id_1': 24769797950537768, 'rm_timestamp_1': 0}
   1


# MachineUnit = Entity

it fits to the faq entry you mentioned earlier? :)


cheers,
richard.


On 07/15/2015 04:22 PM, Mike Bayer wrote:



On 7/15/15 3:13 PM, Richard Gerd Kuesters wrote:

does this happen even with a filter for a PK?

the problem is:

 session.query(Entity).filter(Entity.id_ == 
24769797950537768).count() == 2
 len(session.query(Entity).filter(Entity.id_ == 
24769797950537768).all()) == 1


i don't see where i have 2 pks with the same value ... in psql:

mydb=# select count(*) from entity where id_ = 24769797950537768;
 count
---
 1
(1 row)

is this really right?
what does echo='debug' say ?   both for the first query and the 
second.Also, that integer ID looks kind of like it itself could be 
hitting some overflow limit at some point.   I assume no issue for a 
simple integer in the thousands ?










On 07/15/2015 04:02 PM, Mike Bayer wrote:



On 7/15/15 2:11 PM, Richard Gerd Kuesters wrote:

hello!

i'm encountering a weird behaviur with session.count() when using a 
custom mapper that implements a where condition to every session.


first, what is happening:

 len(session.query(Entity).all()) == 1
 session.query(Entity).count() == 2


your all() query is returning two rows that have the same primary 
key for Entity.The Query object de-duplicates redundant rows 
based on entity identity.  Turn on echo='debug' and you should see 
this in the rows coming back.


we really need an FAQ entry for this one.




Entity is a base polymorphic entity, inherited by other classes.

my custom mapper:

class DeletedOption(MapperOption):
propagate_to_loaders = True

def process_query(self, query):
mzo = query._mapper_zero()
if hasattr(mzo, 'class_'):
parent_cls = mzo.class_
filter_crit = parent_cls.rm_timestamp == 0

if query._criterion is None:
query._criterion = filter_crit
else:
query._criterion = query._criterion  filter_crit


i remember getting this custom mapper option in a recipe

Re: [sqlalchemy] strange behavior in count with custom mapper option

2015-07-15 Thread Richard Gerd Kuesters

oh, the pk 24769797950537768 is a postgres biginteger.


On 07/15/2015 04:46 PM, Richard Gerd Kuesters wrote:

thanks Mike!

here we go:

(Pdb) session.query(MachineUnit).filter(MachineUnit.id_ ==
24769797950537768).count()
2015-07-15 16:43:53,114 INFO sqlalchemy.engine.base.Engine SELECT
count(*) AS count_1
FROM system_unit, (SELECT system_unit.fk_updated_by AS
system_unit_fk_updated_by, system_unit.fk_created_by AS
system_unit_fk_created_by, system_unit.dt_created_on AS
system_unit_dt_created_on, system_unit.dt_updated_on AS
system_unit_updated_on, system_unit.bi_rm_timestamp AS
system_unit_bi_rm_timestamp, machine_unit.pk_fk_system_unit_id AS
machine_unit_pk_fk_system_unit_id, system_unit.pk_system_unit_id
AS system_unit_pk_system_unit_id, system_unit.fk_organization_id
AS system_unit_fk_organization_id, system_unit.u_system_unit_name
AS system_unit_u_system_unit_name, system_unit.in_ipv4 AS
system_unit_in_ipv4, system_unit.p_system_unit_type AS
system_unit_system_unit_type, system_unit.i_version AS
system_unit_i_version, machine_unit.e_machine_type AS
machine_unit_e_machine_type, machine_unit.e_printer_type AS
machine_unit_e_printer_type
FROM system_unit JOIN machine_unit ON
system_unit.pk_system_unit_id = machine_unit.pk_fk_system_unit_id
WHERE machine_unit.pk_fk_system_unit_id = %(system_unit_id_1)s AND
system_unit.bi_rm_timestamp = %(rm_timestamp_1)s) AS anon_1
WHERE system_unit.bi_rm_timestamp = %(rm_timestamp_2)s
2015-07-15 16:43:53,114 INFO sqlalchemy.engine.base.Engine
{'system_unit_id_1': 24769797950537768, 'rm_timestamp_1': 0,
'rm_timestamp_2': 0}
2L
(Pdb) len(session.query(MachineUnit).filter(MachineUnit.id_ ==
24769797950537768).all())
2015-07-15 16:44:32,891 INFO sqlalchemy.engine.base.Engine SELECT
system_unit.fk_updated_by AS system_unit_fk_updated_by,
system_unit.fk_created_by AS system_unit_fk_created_by,
system_unit.dt_created_on AS system_unit_dt_created_on,
system_unit.dt_updated_on AS system_unit_updated_on,
system_unit.bi_rm_timestamp AS system_unit_bi_rm_timestamp,
machine_unit.pk_fk_system_unit_id AS
machine_unit_pk_fk_system_unit_id, system_unit.pk_system_unit_id
AS system_unit_pk_system_unit_id, system_unit.fk_organization_id
AS system_unit_fk_organization_id, system_unit.u_system_unit_name
AS system_unit_u_system_unit_name, system_unit.in_ipv4 AS
system_unit_in_ipv4, system_unit.p_system_unit_type AS
system_unit_system_unit_type, system_unit.i_version AS
system_unit_i_version, machine_unit.e_machine_type AS
machine_unit_e_machine_type, machine_unit.e_printer_type AS
machine_unit_e_printer_type
FROM system_unit JOIN machine_unit ON
system_unit.pk_system_unit_id = machine_unit.pk_fk_system_unit_id
WHERE machine_unit.pk_fk_system_unit_id = %(system_unit_id_1)s AND
system_unit.bi_rm_timestamp = %(rm_timestamp_1)s
2015-07-15 16:44:32,891 INFO sqlalchemy.engine.base.Engine
{'system_unit_id_1': 24769797950537768, 'rm_timestamp_1': 0}
1


# MachineUnit = Entity

it fits to the faq entry you mentioned earlier? :)


cheers,
richard.


On 07/15/2015 04:22 PM, Mike Bayer wrote:



On 7/15/15 3:13 PM, Richard Gerd Kuesters wrote:

does this happen even with a filter for a PK?

the problem is:

 session.query(Entity).filter(Entity.id_ == 
24769797950537768).count() == 2
 len(session.query(Entity).filter(Entity.id_ == 
24769797950537768).all()) == 1


i don't see where i have 2 pks with the same value ... in psql:

mydb=# select count(*) from entity where id_ = 24769797950537768;
 count
---
 1
(1 row)

is this really right?
what does echo='debug' say ?   both for the first query and the 
second.Also, that integer ID looks kind of like it itself could 
be hitting some overflow limit at some point.   I assume no issue for 
a simple integer in the thousands ?










On 07/15/2015 04:02 PM, Mike Bayer wrote:



On 7/15/15 2:11 PM, Richard Gerd Kuesters wrote:

hello!

i'm encountering a weird behaviur with session.count() when using 
a custom mapper that implements a where condition to every session.


first, what is happening:

 len(session.query(Entity).all()) == 1
 session.query(Entity).count() == 2


your all() query is returning two rows that have the same primary 
key for Entity.The Query object de-duplicates redundant rows 
based on entity identity.  Turn on echo='debug' and you should see 
this in the rows coming back.


we really need an FAQ entry for this one.




Entity is a base polymorphic entity, inherited by other classes.

my custom mapper:

class DeletedOption(MapperOption):
propagate_to_loaders = True

def process_query(self, query):
mzo = query._mapper_zero()
if hasattr(mzo, 'class_'):
parent_cls = mzo.class_
filter_crit = parent_cls.rm_timestamp == 0

if query._criterion is None

Re: [sqlalchemy] strange behavior in count with custom mapper option

2015-07-15 Thread Richard Gerd Kuesters
 AS
   system_unit_updated_on, system_unit.bi_rm_timestamp AS
   system_unit_bi_rm_timestamp, machine_unit.pk_fk_system_unit_id AS
   machine_unit_pk_fk_system_unit_id, system_unit.pk_system_unit_id AS
   system_unit_pk_system_unit_id, system_unit.fk_organization_id AS
   system_unit_fk_organization_id, system_unit.u_system_unit_name AS
   system_unit_u_system_unit_name, system_unit.in_ipv4 AS
   system_unit_in_ipv4, system_unit.p_system_unit_type AS
   system_unit_system_unit_type, system_unit.i_version AS
   system_unit_i_version, machine_unit.e_machine_type AS
   machine_unit_e_machine_type, machine_unit.e_printer_type AS
   machine_unit_e_printer_type
   FROM system_unit JOIN machine_unit ON system_unit.pk_system_unit_id
   = machine_unit.pk_fk_system_unit_id
   WHERE machine_unit.pk_fk_system_unit_id = %(system_unit_id_1)s AND
   system_unit.bi_rm_timestamp = %(rm_timestamp_1)s
   2015-07-15 16:57:06,070 INFO sqlalchemy.engine.base.Engine
   {'system_unit_id_1': 24769797950537768, 'rm_timestamp_1': 0}
   INFO:sqlalchemy.engine.base.Engine:{'system_unit_id_1':
   24769797950537768, 'rm_timestamp_1': 0}
   2015-07-15 16:57:06,071 DEBUG sqlalchemy.engine.base.Engine Col
   ('system_unit_fk_updated_by', 'system_unit_fk_created_by',
   'system_unit_dt_created_on', 'system_unit_updated_on',
   'system_unit_bi_rm_timestamp', 'machine_unit_pk_fk_system_unit_id',
   'system_unit_pk_system_unit_id', 'system_unit_fk_organization_id',
   'system_unit_u_system_unit_name', 'system_unit_in_ipv4',
   'system_unit_system_unit_type', 'system_unit_i_version',
   'machine_unit_e_machine_type', 'machine_unit_e_printer_type')
   DEBUG:sqlalchemy.engine.base.Engine:Col
   ('system_unit_fk_updated_by', 'system_unit_fk_created_by',
   'system_unit_dt_created_on', 'system_unit_updated_on',
   'system_unit_bi_rm_timestamp', 'machine_unit_pk_fk_system_unit_id',
   'system_unit_pk_system_unit_id', 'system_unit_fk_organization_id',
   'system_unit_u_system_unit_name', 'system_unit_in_ipv4',
   'system_unit_system_unit_type', 'system_unit_i_version',
   'machine_unit_e_machine_type', 'machine_unit_e_printer_type')
   2015-07-15 16:57:06,071 DEBUG sqlalchemy.engine.base.Engine Row
   (None, 24769797950537732L, datetime.datetime(2015, 7, 15, 17, 49,
   57, 410290, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=-180,
   name=None)), datetime.datetime(2015, 7, 15, 17, 49, 57, 410305,
   tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=-180, name=None)), 0L,
   24769797950537768L, 24769797950537768L, 24769797950537729L,
   u'Workstation Super Legal do Richard', '10.0.0.2', 2, 1, 50, 0)
   DEBUG:sqlalchemy.engine.base.Engine:Row (None, 24769797950537732L,
   datetime.datetime(2015, 7, 15, 17, 49, 57, 410290,
   tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=-180, name=None)),
   datetime.datetime(2015, 7, 15, 17, 49, 57, 410305,
   tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=-180, name=None)), 0L,
   24769797950537768L, 24769797950537768L, 24769797950537729L,
   u'Workstation Super Legal do Richard', '10.0.0.2', 2, 1, 50, 0)
   1



On 07/15/2015 04:53 PM, Mike Bayer wrote:



On 7/15/15 3:46 PM, Richard Gerd Kuesters wrote:

thanks Mike!

here we go:

(Pdb) session.query(MachineUnit).filter(MachineUnit.id_ ==
24769797950537768).count()
2015-07-15 16:43:53,114 INFO sqlalchemy.engine.base.Engine SELECT
count(*) AS count_1
FROM system_unit, (SELECT system_unit.fk_updated_by AS
system_unit_fk_updated_by, system_unit.fk_created_by AS
system_unit_fk_created_by, system_unit.dt_created_on AS
system_unit_dt_created_on, system_unit.dt_updated_on AS
system_unit_updated_on, system_unit.bi_rm_timestamp AS
system_unit_bi_rm_timestamp, machine_unit.pk_fk_system_unit_id AS
machine_unit_pk_fk_system_unit_id, system_unit.pk_system_unit_id
AS system_unit_pk_system_unit_id, system_unit.fk_organization_id
AS system_unit_fk_organization_id, system_unit.u_system_unit_name
AS system_unit_u_system_unit_name, system_unit.in_ipv4 AS
system_unit_in_ipv4, system_unit.p_system_unit_type AS
system_unit_system_unit_type, system_unit.i_version AS
system_unit_i_version, machine_unit.e_machine_type AS
machine_unit_e_machine_type, machine_unit.e_printer_type AS
machine_unit_e_printer_type
FROM system_unit JOIN machine_unit ON
system_unit.pk_system_unit_id = machine_unit.pk_fk_system_unit_id
WHERE machine_unit.pk_fk_system_unit_id = %(system_unit_id_1)s
AND system_unit.bi_rm_timestamp = %(rm_timestamp_1)s) AS anon_1
WHERE system_unit.bi_rm_timestamp = %(rm_timestamp_2)s
2015-07-15 16:43:53,114 INFO sqlalchemy.engine.base.Engine
{'system_unit_id_1': 24769797950537768, 'rm_timestamp_1': 0,
'rm_timestamp_2': 0}
2L
(Pdb) len(session.query(MachineUnit).filter(MachineUnit.id_ ==
24769797950537768).all())
2015-07-15 16:44:32,891 INFO sqlalchemy.engine.base.Engine SELECT
system_unit.fk_updated_by AS system_unit_fk_updated_by,
system_unit.fk_created_by

Re: [sqlalchemy] strange behavior in count with custom mapper option

2015-07-15 Thread Richard Gerd Kuesters
 machine_unit.pk_fk_system_unit_id = 24769797950537768
   AND system_unit.bi_rm_timestamp = 0) AS anon_1
   pollux-# WHERE system_unit.bi_rm_timestamp = 0;
 count_1
   -
   2
   (1 row)



count_1 == 2 ... even if I remove the where bi_rm_timestamp = 0 (from 
the two clauses), the result is the same:


   pollux=# SELECT count(*) AS count_1
   pollux-# FROM system_unit, (
   pollux(# SELECT system_unit.fk_updated_by AS
   system_unit_fk_updated_by, system_unit.fk_created_by AS
   system_unit_fk_created_by, system_unit.dt_created_on AS
   system_unit_dt_created_on, system_unit.dt_updated_on AS
   system_unit_updated_on,
   pollux(# system_unit.bi_rm_timestamp AS system_unit_bi_rm_timestamp,
   machine_unit.pk_fk_system_unit_id AS
   machine_unit_pk_fk_system_unit_id, system_unit.pk_system_unit_id AS
   system_unit_pk_system_unit_id, system_unit.fk_organization_id AS
   pollux(# system_unit_fk_organization_id,
   system_unit.u_system_unit_name AS system_unit_u_system_unit_name,
   system_unit.in_ipv4 AS system_unit_in_ipv4,
   system_unit.p_system_unit_type AS system_unit_system_unit_type,
   system_unit.i_version AS
   pollux(# system_unit_i_version, machine_unit.e_machine_type AS
   machine_unit_e_machine_type, machine_unit.e_printer_type AS
   machine_unit_e_printer_type
   pollux(# FROM system_unit JOIN machine_unit ON
   system_unit.pk_system_unit_id = machine_unit.pk_fk_system_unit_id
   pollux(# WHERE machine_unit.pk_fk_system_unit_id =
   24769797950537768) AS anon_1;
 count_1
   -
   2
   (1 row)


faq? :)



On 07/15/2015 04:58 PM, Richard Gerd Kuesters wrote:

right! sorry, now here we go (again):




--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

[sqlalchemy] is it two or more levels of polymorphism possible?

2015-07-15 Thread Richard Gerd Kuesters

hi all,

i was wondering if there's a way to create more than one level of 
polymorphic entities in sa. quick example:


   class Foo(Base):
...
__mapper_args__ = { ... }

   class Bar(Foo):
...
__mapper_args__ = { ??? }  # --- polymorphic_identity for ... two?


   class Baz(Bar):  # --- is this possible?
   ...



cheers,
Richard.

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] is it two or more levels of polymorphism possible?

2015-07-15 Thread Richard Gerd Kuesters


oh, yes, i was thinking about cascading polymorphic_on, like you mentioned.

but, no problem, i'll try to workaround my problem with a more simple 
approach (the old soft-delete dilemma) ...


thanks for your help, Mike!

best regards,
richard.


On 07/15/2015 10:46 AM, Mike Bayer wrote:



On 7/15/15 9:09 AM, Richard Gerd Kuesters wrote:

hi all,

i was wondering if there's a way to create more than one level of 
polymorphic entities in sa. quick example:


class Foo(Base):
...
__mapper_args__ = { ... }

class Bar(Foo):
...
__mapper_args__ = { ??? }  # --- polymorphic_identity for
... two?


class Baz(Bar):  # --- is this possible?
   ...




yes, you give a new polymorphic_identity to Baz separate from 
Bar.  The only requirement is that they are all using the same 
column on Foo for the differentiation (cascading polymorphic_on 
columns isn't supported yet).





cheers,
Richard.
--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] How to do a revision table or How to get a 1:1 and 1:n relationship between the same tables to work properly

2015-06-18 Thread Richard Gerd Kuesters

have you taken a look at this approach?

https://bitbucket.org/zzzeek/sqlalchemy/src/4a25c10e27147917e93e6893df13b2b55673e0a7/examples/versioned_history/?at=master


chers,
richard.

On 06/18/2015 08:44 AM, Adrian wrote:
I hadn't seen that part of the documentation - doing it that way works 
fine now!
I ended up using a signal to update `revisions` automatically when 
setting `current_revision`:

https://github.com/ThiefMaster/indico/blob/f300c3b9dc8d499b4d745dee74edceff53e7ffb4/indico/modules/events/notes/models/notes.py#L159-L164
Is there any better way to do this or is that the way to go?

I'd definitely advise doing it that way, that's the supported way
to do
a favorite id approach and is more relationally correct (e.g. not
possible to have multiple favorites).It seems like you read the
docs at

http://docs.sqlalchemy.org/en/rel_1_0/orm/relationship_persistence.html#rows-that-point-to-themselves-mutually-dependent-rows

http://docs.sqlalchemy.org/en/rel_1_0/orm/relationship_persistence.html#rows-that-point-to-themselves-mutually-dependent-rows,

so I'd give that a revisit and feel free to share the errors from
that case.

--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

[sqlalchemy] get referencing foreign table + column

2015-06-18 Thread Richard Gerd Kuesters
hello all! i think this is a quick question: is there a way to get the 
referencing table and column from a given foreign key column, rather 
then list(col.impl.parent_token.expression.foreign_keys)[0] ?


best regards,
richard.

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] creating indexes from inherited fields

2015-06-02 Thread Richard Gerd Kuesters

thanks a lot, Mike!

good catch of yours. the answer was in front of me all the time and i 
couldn't see it ... my mistake, thanks for pointing the right direction ;)



best regards,
richard.


On 06/02/2015 03:17 PM, Mike Bayer wrote:



On 6/2/15 12:59 PM, Richard Gerd Kuesters wrote:

thanks again Mike!

almost there. the problem now are inherited tables ...

taken from my example code, let's say I have a table that inherits 
SomeOtherClass; then, the error is something like:


sqlalchemy.exc.ArgumentError: Index 'ix_adapter_created_on' is 
against table 'adapter', and cannot be associated with table 
'http_adapter'.


in the example above, http_error inherits from adapter.


take a look at using has_inherited_table(), the section in 
http://docs.sqlalchemy.org/en/rel_1_0/orm/extensions/declarative/mixins.html#controlling-table-inheritance-with-mixins 
has clues






best regards,
richard.

On 06/02/2015 01:45 PM, Mike Bayer wrote:



On 6/2/15 12:05 PM, Richard Gerd Kuesters wrote:
oh, sorry Mike, I forgot to mention that I use TimestampMixin in 
other classes aswell, so I got an existent index error (something 
like that). Is there a way I don't need to declare the index name? 
(IMHO this appears to be the problem).


indexes have to be named something so you'd have to figure out a 
naming convention based on tables/column names.   There should be an 
existing convention for indexes so if you set None as the name it 
should make one up for you like ix_tablename_columnname




thanks a lot!
richard.

On 06/02/2015 12:28 PM, Mike Bayer wrote:



On 6/2/15 10:16 AM, Richard Gerd Kuesters wrote:

hi all, again :)

how can I create an index in fields inherited by other classes?

example:


class TimestampMixin(object):
updated_on = Column(DateTime)  # i wanted to create three 
indexes in this field, updated_on, updated_on.asc() and 
updated_on.desc()



class SomeOtherClass(Base, TimestampMixin):
__tablename__ = 'some_table'
id = Column(Integer)



Index('ix_some_other_class_01', SomeOtherClass.updated_on)
Index('ix_some_other_class_02', SomeOtherClass.updated_on.asc())
Index('ix_some_other_class_03', SomeOtherClass.updated_on.desc())


I just want to avoid repetition, if possible :)


you could use a __table_args__() callable with @declared_attr.  Or 
use a mapping event like __declare_first__() or __declare_last__() 
(these are hooked into the before_configured / after_configured 
events which you could also use directly, e.g. 
http://docs.sqlalchemy.org/en/rel_1_0/orm/events.html?highlight=before_configure#sqlalchemy.orm.events.MapperEvents.before_configured)








best regards,
richard.
--
You received this message because you are subscribed to the 
Google Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.

To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.

To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.

To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options

[sqlalchemy] creating indexes from inherited fields

2015-06-02 Thread Richard Gerd Kuesters

hi all, again :)

how can I create an index in fields inherited by other classes?

example:


class TimestampMixin(object):
updated_on = Column(DateTime)  # i wanted to create three indexes 
in this field, updated_on, updated_on.asc() and updated_on.desc()



class SomeOtherClass(Base, TimestampMixin):
__tablename__ = 'some_table'
id = Column(Integer)



Index('ix_some_other_class_01', SomeOtherClass.updated_on)
Index('ix_some_other_class_02', SomeOtherClass.updated_on.asc())
Index('ix_some_other_class_03', SomeOtherClass.updated_on.desc())


I just want to avoid repetition, if possible :)


best regards,
richard.

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] creating indexes from inherited fields

2015-06-02 Thread Richard Gerd Kuesters
oh, sorry Mike, I forgot to mention that I use TimestampMixin in other 
classes aswell, so I got an existent index error (something like 
that). Is there a way I don't need to declare the index name? (IMHO this 
appears to be the problem).


thanks a lot!
richard.

On 06/02/2015 12:28 PM, Mike Bayer wrote:



On 6/2/15 10:16 AM, Richard Gerd Kuesters wrote:

hi all, again :)

how can I create an index in fields inherited by other classes?

example:


class TimestampMixin(object):
updated_on = Column(DateTime)  # i wanted to create three indexes 
in this field, updated_on, updated_on.asc() and updated_on.desc()



class SomeOtherClass(Base, TimestampMixin):
__tablename__ = 'some_table'
id = Column(Integer)



Index('ix_some_other_class_01', SomeOtherClass.updated_on)
Index('ix_some_other_class_02', SomeOtherClass.updated_on.asc())
Index('ix_some_other_class_03', SomeOtherClass.updated_on.desc())


I just want to avoid repetition, if possible :)


you could use a __table_args__() callable with @declared_attr.  Or use 
a mapping event like __declare_first__() or __declare_last__() (these 
are hooked into the before_configured / after_configured events which 
you could also use directly, e.g. 
http://docs.sqlalchemy.org/en/rel_1_0/orm/events.html?highlight=before_configure#sqlalchemy.orm.events.MapperEvents.before_configured)








best regards,
richard.
--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] creating indexes from inherited fields

2015-06-02 Thread Richard Gerd Kuesters

thanks again Mike!

almost there. the problem now are inherited tables ...

taken from my example code, let's say I have a table that inherits 
SomeOtherClass; then, the error is something like:


sqlalchemy.exc.ArgumentError: Index 'ix_adapter_created_on' is against 
table 'adapter', and cannot be associated with table 'http_adapter'.


in the example above, http_error inherits from adapter.


best regards,
richard.

On 06/02/2015 01:45 PM, Mike Bayer wrote:



On 6/2/15 12:05 PM, Richard Gerd Kuesters wrote:
oh, sorry Mike, I forgot to mention that I use TimestampMixin in 
other classes aswell, so I got an existent index error (something 
like that). Is there a way I don't need to declare the index name? 
(IMHO this appears to be the problem).


indexes have to be named something so you'd have to figure out a 
naming convention based on tables/column names.   There should be an 
existing convention for indexes so if you set None as the name it 
should make one up for you like ix_tablename_columnname




thanks a lot!
richard.

On 06/02/2015 12:28 PM, Mike Bayer wrote:



On 6/2/15 10:16 AM, Richard Gerd Kuesters wrote:

hi all, again :)

how can I create an index in fields inherited by other classes?

example:


class TimestampMixin(object):
updated_on = Column(DateTime)  # i wanted to create three 
indexes in this field, updated_on, updated_on.asc() and 
updated_on.desc()



class SomeOtherClass(Base, TimestampMixin):
__tablename__ = 'some_table'
id = Column(Integer)



Index('ix_some_other_class_01', SomeOtherClass.updated_on)
Index('ix_some_other_class_02', SomeOtherClass.updated_on.asc())
Index('ix_some_other_class_03', SomeOtherClass.updated_on.desc())


I just want to avoid repetition, if possible :)


you could use a __table_args__() callable with @declared_attr.  Or 
use a mapping event like __declare_first__() or __declare_last__() 
(these are hooked into the before_configured / after_configured 
events which you could also use directly, e.g. 
http://docs.sqlalchemy.org/en/rel_1_0/orm/events.html?highlight=before_configure#sqlalchemy.orm.events.MapperEvents.before_configured)








best regards,
richard.
--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.

To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

[sqlalchemy] how to return an array of dicts

2015-06-01 Thread Richard Gerd Kuesters

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 (web 
/ rpc usage), and I wonder if I must go from the cycle .



class A(Base):
attr_one = Column(..)
attr_two = Column(..)
attr_three = Column(..)
attr_four = Column(..)
attr_five = Column(..)

data = session.query(A.attr_one, A.attr_four)  # ok, got a query object
result = data.all()  # got a result proxy
wanted_result = map(lambda r: r._as_dict(), data.all())  # iterate 
through the result proxy, calling the _as_dict() method from row_proxy. 
it does the job, but is that really necessary?



my question is if there's any way of simplifying the query just for 
json purposes, since imho the need of some proxies here may be an 
overkill. but ... i might be wrong :)



best regards,
richard.

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

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

2015-06-01 Thread Richard Gerd Kuesters

thanks Simon!

yes, i'm already using hooks so I can pass datetime, decimal, enums and 
so on; of course, it can help if I have to go with the result proxy. i 
just wonder if there's another way of doing this without having 
sqlalchemy to provide me helpers of proxy objects. i'm thinking about 
straight, performance-wize optimization :)


best regards,
richard.

On 06/01/2015 10:00 AM, Simon King wrote:

On Mon, Jun 1, 2015 at 1:51 PM, Richard Gerd Kuesters
rich...@pollux.com.br 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 (web /
rpc usage), and I wonder if I must go from the cycle .


class A(Base):
 attr_one = Column(..)
 attr_two = Column(..)
 attr_three = Column(..)
 attr_four = Column(..)
 attr_five = Column(..)

data = session.query(A.attr_one, A.attr_four)  # ok, got a query object
result = data.all()  # got a result proxy
wanted_result = map(lambda r: r._as_dict(), data.all())  # iterate through
the result proxy, calling the _as_dict() method from row_proxy. it does the
job, but is that really necessary?


my question is if there's any way of simplifying the query just for json
purposes, since imho the need of some proxies here may be an overkill. but
... i might be wrong :)


I'm not aware of any way of getting SQLAlchemy to return plain old
dicts. How are you converting your Python dicts to JSON? JSON
converters often have a hook point where you can define how custom
objects are converted to JSON. Here's how you could do it in Pyramid:

http://pyramid.readthedocs.org/en/latest/narr/renderers.html#using-the-add-adapter-method-of-a-custom-json-renderer

And the Python json.dump function accepts a default parameter that
could do custom serialization.

Hope that helps,

Simon



--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

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

2015-06-01 Thread Richard Gerd Kuesters

Thanks Jonathan,

I agree with you, 100%. I have methods for that also, when I have to 
deal with the real objects and queries and stuff.


The point, in my question, is that I have some services that are not 
vital to my application, but are used constantly -- and it just spits 
out data. I'm just trying to work on some edges that might help me 
(saving memory, I/O, etc). I can even put a plain old select :)


This question is, kind of, general and not specific to JSON, in my point 
of view.



best regards,
richard.

On 06/01/2015 01:28 PM, Jonathan Vanasco wrote:

All my models inherit from an additional base class with this method:

def columns_as_dict(self):
return a dict of the columns; does not handle relationships
return dict((col.name, getattr(self, col.name)) for col in 
sqlalchemy_orm.class_mapper(self.__class__).mapped_table.c)


so when returning a JSON array, I just do something like;

 return [i.columns_as_dict() for i in results]

I prefer this for several reasons:

- I don't think (anymore) that sqlalchemy should return raw data. I'm 
not fine with it's internal constructs after departing from the 
recommended usage a few times and finding myself creating more 
problems than I solved.


- I easily can override columns_as_dict() on classes to define only 
those columns that I want returned.


- IIRC, The result_proxy/row_proxy aren't always fetched from the 
database, there could still be data on the connection - or you could 
be on an unloaded lazy-loaded relation.  Running a list comprehension 
lets me slurp all that data, and close up the DB resources sooner. 
 This has made pinpointing bugs a lot easier than having unloaded data 
accessed in a template (which often produces hard-to-figure out 
tracebacks as the db is nestled in the template, which is nestled in 
your app).


There are probably a dozen better reasons for why I prefer this method 
, these just popped up in my head.

--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

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

2015-06-01 Thread Richard Gerd Kuesters

argh!

 results = map(lambda r: dict(r.items()), 
session.execute(my_select).fetchall())


much simplier :)  but, the question persists: is this the best approach 
for a raw data dictionary result query?



best regards,
richard.

On 06/01/2015 10:22 AM, Richard Gerd Kuesters wrote:
well, i can use select and zip ... don't know if this is the best 
approach:


 foo = session.execute(my_select)  # my_select have the same rules 
as the session.query(A..., 
A).filter(...).order_by(...).offset(...).limit()

 results = map(lambda r: dict(foo.keys(), r), foo.fetchall())

any thoughts? :)


On 06/01/2015 10:08 AM, Richard Gerd Kuesters wrote:

thanks Simon!

yes, i'm already using hooks so I can pass datetime, decimal, enums 
and so on; of course, it can help if I have to go with the result 
proxy. i just wonder if there's another way of doing this without 
having sqlalchemy to provide me helpers of proxy objects. i'm 
thinking about straight, performance-wize optimization :)


best regards,
richard.

On 06/01/2015 10:00 AM, Simon King wrote:

On Mon, Jun 1, 2015 at 1:51 PM, Richard Gerd Kuesters
rich...@pollux.com.br  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 (web /
rpc usage), and I wonder if I must go from the cycle .


class A(Base):
 attr_one = Column(..)
 attr_two = Column(..)
 attr_three = Column(..)
 attr_four = Column(..)
 attr_five = Column(..)

data = session.query(A.attr_one, A.attr_four)  # ok, got a query object
result = data.all()  # got a result proxy
wanted_result = map(lambda r: r._as_dict(), data.all())  # iterate through
the result proxy, calling the _as_dict() method from row_proxy. it does the
job, but is that really necessary?


my question is if there's any way of simplifying the query just for json
purposes, since imho the need of some proxies here may be an overkill. but
... i might be wrong :)


I'm not aware of any way of getting SQLAlchemy to return plain old
dicts. How are you converting your Python dicts to JSON? JSON
converters often have a hook point where you can define how custom
objects are converted to JSON. Here's how you could do it in Pyramid:

http://pyramid.readthedocs.org/en/latest/narr/renderers.html#using-the-add-adapter-method-of-a-custom-json-renderer

And the Python json.dump function accepts a default parameter that
could do custom serialization.

Hope that helps,

Simon



--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

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

2015-06-01 Thread Richard Gerd Kuesters

well, i can use select and zip ... don't know if this is the best approach:

 foo = session.execute(my_select)  # my_select have the same rules as 
the session.query(A..., 
A).filter(...).order_by(...).offset(...).limit()

 results = map(lambda r: dict(foo.keys(), r), foo.fetchall())

any thoughts? :)


On 06/01/2015 10:08 AM, Richard Gerd Kuesters wrote:

thanks Simon!

yes, i'm already using hooks so I can pass datetime, decimal, enums 
and so on; of course, it can help if I have to go with the result 
proxy. i just wonder if there's another way of doing this without 
having sqlalchemy to provide me helpers of proxy objects. i'm thinking 
about straight, performance-wize optimization :)


best regards,
richard.

On 06/01/2015 10:00 AM, Simon King wrote:

On Mon, Jun 1, 2015 at 1:51 PM, Richard Gerd Kuesters
rich...@pollux.com.br  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 (web /
rpc usage), and I wonder if I must go from the cycle .


class A(Base):
 attr_one = Column(..)
 attr_two = Column(..)
 attr_three = Column(..)
 attr_four = Column(..)
 attr_five = Column(..)

data = session.query(A.attr_one, A.attr_four)  # ok, got a query object
result = data.all()  # got a result proxy
wanted_result = map(lambda r: r._as_dict(), data.all())  # iterate through
the result proxy, calling the _as_dict() method from row_proxy. it does the
job, but is that really necessary?


my question is if there's any way of simplifying the query just for json
purposes, since imho the need of some proxies here may be an overkill. but
... i might be wrong :)


I'm not aware of any way of getting SQLAlchemy to return plain old
dicts. How are you converting your Python dicts to JSON? JSON
converters often have a hook point where you can define how custom
objects are converted to JSON. Here's how you could do it in Pyramid:

http://pyramid.readthedocs.org/en/latest/narr/renderers.html#using-the-add-adapter-method-of-a-custom-json-renderer

And the Python json.dump function accepts a default parameter that
could do custom serialization.

Hope that helps,

Simon



--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] restrict child count?

2015-05-19 Thread Richard Gerd Kuesters

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 return the same exactly number of rows, including 
where filters and so on. it is something like a physical rule, where 
my parent is (really) a box and the children its items (so, i cannot put 
more items then the box's limit).


either way, creating a relationship with limit *can* provide me that 
sort of behaviour?


i mean, i'm just asking this because it may be already done by someone. 
if not, that's not a problem -- i'll have to managed something by myself :)



ps: sorry for my bad english, sometimes i can't make understandable 
questions :)



best regards,
richard.

On 05/19/2015 11:16 AM, Mike Bayer wrote:



On 5/19/15 8:57 AM, Richard Gerd Kuesters wrote:

hi!

this may be a weird question, but is there a way i can restrict the 
number of children in a relationship? not by limit ...


how is that different?   Anytime in SQL you want to get only the first 
N of M, LIMIT or its equivalents must be involved.


two options are:

1. write the exact SQL for the primary + relationship you want, then 
use contains_eager() to specify it as a collection load.  the SQL has 
to be along the lines of SELECT * FROM primary LEFT OUTER JOIN 
secondary WHERE secondary.id IS NULL or secondary.id IN (select id 
FROM secondary AS sec_2 LIMIT N WHERE 
sec_2.primary_id=secondary.primary_id)


2. load the collections individually:

from sqlalchemy.orm.attributes import set_committed_value

for item in things:
child_items = sess.query(Child).with_parent(item).limit(N).all()
set_committed_value(item, child_items, child_items)


scenario: i have a one to many rel, where the parent have 3 values 
(row, column, depth) that creates a max child count of row * column * 
depth (yes, like the 3d stuff) ... so, count(child) = max_child, 
this sort of stuff.


if i could pull of postgres specific constraint for this, even better ...

best regards,
richard.
--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] restrict child count?

2015-05-19 Thread Richard Gerd Kuesters

bingo! thanks Simon. that's exactly the question :)

well, the checks on the cube are already there (they must have a value 
higher then 0 to have a volume), but i must not increment the cube 
children more then it's maximum capacity. i'm considering an event 
listener as well, but i'm wondering if it can't be done at database 
level, using postgres?


or, what would be the better approach scenario for this? a trigger, an 
event, both?




On 05/19/2015 01:13 PM, Simon King wrote:

On Tue, May 19, 2015 at 4:06 PM, Mike Bayer mike...@zzzcomputing.com 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 return the same exactly number of rows, including where
filters and so on. it is something like a physical rule, where my parent
is (really) a box and the children its items (so, i cannot put more items
then the box's limit).

either way, creating a relationship with limit *can* provide me that sort of
behaviour?

I don't understand what the behavior is here.   No LIMIT, yet there is a
limit.   An assertion?I have no idea what you mean. The
relationship 1. emits SQL 2. loads the results into objects.Are we
talking about 1. or 2. ?



I'm guessing he's looking for something like this:

class Cube(Base):
 __table_name__ = 'cube'
 id = sa.Column(sa.Integer, primary_key=True)
 rows = sa.Column(sa.Integer)
 cols = sa.Column(sa.Integer)
 depth = sa.Column(sa.Integer)

 @property
 def volume(self):
 return self.rows * self.cols * self.depth


class Cell(Base):
 __table_name__ = 'cell'
 id = sa.Column(sa.Integer, primary_key=True)
 cube_id = sa.Column(sa.ForeignKey(Cube.id))
 row = sa.Column(sa.Integer)
 col = sa.Column(sa.Integer)
 depth = sa.Column(sa.Integer)

 __table_args__ = (
 sa.UniqueConstraint('cube_id', 'row', 'col', 'depth')
 )

 cube = saorm.relationship(Cube, backref='cells')

Now, given an instance of Cube, how can you ensure that it is
impossible to add more than Cube.volume cells to the Cube.cells
relationship? I imagine it is possible by attaching an event listener
to Cube.cells and doing the validation in there.

If Richard's data really is structured like this, I'd probably instead
want to enforce that:

 0 = cell.row  cell.cube.rows
 0 = cell.col  cell.cube.cols
 0 = cell.depth  cell.cube.depth

I think you could probably do this with SQLAlchemy validators. I don't
know enough Postgres, but I suspect you could also enforce it at the
database level.

Simon



--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

[sqlalchemy] restrict child count?

2015-05-19 Thread Richard Gerd Kuesters

hi!

this may be a weird question, but is there a way i can restrict the 
number of children in a relationship? not by limit ...


scenario: i have a one to many rel, where the parent have 3 values (row, 
column, depth) that creates a max child count of row * column * depth 
(yes, like the 3d stuff) ... so, count(child) = max_child, this sort of 
stuff.


if i could pull of postgres specific constraint for this, even better ...

best regards,
richard.

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] Re: restrict child count?

2015-05-19 Thread Richard Gerd Kuesters
i know, i'm sorry for that. i first posted it here since my whole 
application is managed by sqlalchemy, so that's why i asked for 
something. i mentioned postgresql because it's the database that i use 
and there's a lot of database specific solutions bundled with sa. but, 
even if no rdbms agnostic solution can be provided to such situation 
using sqlalchemy, i'll sure dive into a trigger :)


best regards,
richard.

On 05/19/2015 02:10 PM, Mike Bayer wrote:


On 5/19/15 12:18 PM, Jonathan Vanasco wrote:

I think I might understand you...

You have a BOX, which could be a variable amount of sizes, and each 
size can hold a variable amount of items.


You want to create a rule(s) that will ensure you do not have too 
many things in each box.


If that is that case:

1. You could use Triggers in PostgreSQL to ensure that you are within 
the correct dimensions on insert and update.
2. You might be able use events in sqlalchemy to inspect the 
collection and figure out if the number of items is allowablw



from my POV this is more of a SQL/database question, not really 
SQLAlchemy.Not a problem to post here but I wish there were some 
way for me to know which questions are SQLAlchemy-API-specific; other 
folks and/or stackoverflow can take care of general Postgresql / SQL / 
schema design questions.








--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] polymorphic objects

2015-04-28 Thread Richard Gerd Kuesters
yeah, i know. sorry for the late question, i think i was a bit too tired 
to continue coding. anyway, i circumvented the problem by using a select 
using A.__table__, which works for what I need (i have a heavily 
modified hierarchical extension based on Mariano Mara's code 
(https://pypi.python.org/pypi/sqla-hierarchy)). when it comes to 
polymorphism, i forgot that i had to use select instead of query to 
retrieve my objects :)


best regards,
richard.

On 04/27/2015 07:41 PM, Mike Bayer wrote:



On 4/27/15 4:31 PM, Richard Gerd Kuesters wrote:
well, i'm having trouble dealing with polymorphic objects. i mean, 
the functionality is fine, i just don't know how to obtain the main 
object.


let me be clear: i have A, which is my main object, and is inherited 
by B and C. I would like to work with the A object, even though it's 
polymorphic identity refers to B or C. I know it's not the default 
behavior, but can I obtain A from a query?


perhaps you could be more specific.

If a query returns B and C objects, if those inherit from A, they 
*are* A objects.






thanks a lot!
richard.
--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

[sqlalchemy] polymorphic objects

2015-04-27 Thread Richard Gerd Kuesters
well, i'm having trouble dealing with polymorphic objects. i mean, the 
functionality is fine, i just don't know how to obtain the main object.


let me be clear: i have A, which is my main object, and is inherited by 
B and C. I would like to work with the A object, even though it's 
polymorphic identity refers to B or C. I know it's not the default 
behavior, but can I obtain A from a query?


thanks a lot!
richard.

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] Making a new type out of Postgres DATERANGE + Psycopg2 DateRange

2015-04-24 Thread Richard Gerd Kuesters

perhaps this could help you?

http://sqlalchemy-utils.readthedocs.org/en/latest/range_data_types.html#datetimerangetype


richard.


On 04/24/2015 10:09 AM, Dimitris Theodorou wrote:

Hi,

I am using psycopg2 and trying to put together a new daterange type 
that combines the following:


1. A custom daterange class which provides various useful helpers 
(backwards/forwards iteration, intersection).
2. The psycopg2 DateRange that fills in with some helpers of its own 
(contains, comparisons) and takes care of marshaling the object 
from/to the db
3. The DATERANGE sqlalchemy/postgres type to take care of emiting of 
SQL operators and DDL, and so that I can use it both when querying and 
when declaring Columns()


So my naive approach is the following, going by the guideline at 
http://docs.sqlalchemy.org/en/latest/core/compiler.html#subclassing-guidelines:


|
|
|frompsycopg2.extras importDateRange
fromsqlalchemy.dialects.postgresql importDATERANGE

classMyDateRange(TypeDecorator,DateRange):

  impl =DATERANGE

defintersection():
#...
|
|


|This crashes when emitting a table.create() statement.

When I look at the documentation on how to create/modify types I am 
left dumfounded and I realize I would need a significant trial and 
error investment to figure out how things work. Does anyone else have 
experience with such an attempt? I'd rather not  become an expert in 
sqlalchemy type extension before I can make this work.


Thanks,
Dimitris
--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] SQLAlchemy as plain-SQL generator

2015-04-22 Thread Richard Gerd Kuesters
well, i know that repeating (query) is somehow strange, i believe the 
main reason is that *compile()**.process*are not bound to the query 
anymore (*i might be wrong*). well, for me it was a one time solution, 
perhaps a little digging can bring you a better approach :)


cheers,
richard.


On 04/22/2015 09:36 AM, Pavel S wrote:

Hi Richard,

thanks, your solution works. ( I don't need formatted output)

However using /query/ twice in the expression looks to me a bit 
awkward. Isn't there some shortcut?



Dne středa 22. dubna 2015 14:27:41 UTC+2 Richard Kuesters napsal(a):

hi,

you must use a specific dialect so sqlalchemy can create it for
you. not the best usage, imho, but here it goes:

*stmt = query.compile().process(query, literal_binds=True)*

i don't know if you want it formated or what, if so,
*sqlparse*provides a good way to do it.

but, again, this will only work if you BIND an engine to your
metadata, so sqlalchemy can write the right sql for you. also,
your query should be a *select()*object, like your example.

this worked for me for some time, using SA 0.9, i don't know about
1.0, but it should work too.


cheers,
richard.


On 04/22/2015 04:26 AM, Pavel S wrote:

Hello,

I have pythonic application which imports custom module written
in C++ using boost::python.
The module creates database connection(s) and executes queries.
The python calls various methods on that module and passes plain
SQL into them. Results are then returned to python.

I would like to use SQLALchemy Core to generate plain SQL strings
which will be passed the module.

Lets say I want to generate the following string:

|
SELECT A,B FROM TblWHERE C =Foo;
|

The equivalent in SA is:

|
query =select([
Tbl.c.A,
Tbl.c.B
]).where(
Tbl.c.C ==Foo
)
|

How can I produce the string from that query?
-- 
You received this message because you are subscribed to the

Google Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it,
send an email to sqlalchemy+...@googlegroups.com javascript:.
To post to this group, send email to sqlal...@googlegroups.com
javascript:.
Visit this group at http://groups.google.com/group/sqlalchemy
http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout
https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] SQLAlchemy as plain-SQL generator

2015-04-22 Thread Richard Gerd Kuesters
yeah, well, that's much simpler. in my scenario, where i had to use this 
piece of code, literal_binds are necessary since the query is somehow 
huge, with lots of alias and parameters :)



On 04/22/2015 11:07 AM, Mike Bayer wrote:



On 4/22/15 8:27 AM, Richard Gerd Kuesters wrote:

hi,

you must use a specific dialect so sqlalchemy can create it for you. 
not the best usage, imho, but here it goes:


*stmt = query.compile().process(query, literal_binds=True)*


OK since Pavel noted the double compile, if you want the literal_binds 
part (not clear if that is needed here?), it goes into compile()


stmt = str(query.compile(compile_kwargs={literal_binds: True}))







i don't know if you want it formated or what, if so, 
*sqlparse*provides a good way to do it.


but, again, this will only work if you BIND an engine to your 
metadata, so sqlalchemy can write the right sql for you. also, your 
query should be a *select()*object, like your example.


this worked for me for some time, using SA 0.9, i don't know about 
1.0, but it should work too.



cheers,
richard.


On 04/22/2015 04:26 AM, Pavel S wrote:

Hello,

I have pythonic application which imports custom module written in 
C++ using boost::python.

The module creates database connection(s) and executes queries.
The python calls various methods on that module and passes plain SQL 
into them. Results are then returned to python.


I would like to use SQLALchemy Core to generate plain SQL strings 
which will be passed the module.


Lets say I want to generate the following string:

|
SELECT A,B FROM TblWHERE C =Foo;
|

The equivalent in SA is:

|
query =select([
Tbl.c.A,
Tbl.c.B
]).where(
Tbl.c.C ==Foo
)
|

How can I produce the string from that query?
--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] SQLAlchemy as plain-SQL generator

2015-04-22 Thread Richard Gerd Kuesters

hi,

you must use a specific dialect so sqlalchemy can create it for you. not 
the best usage, imho, but here it goes:


*stmt = query.compile().process(query, literal_binds=True)*

i don't know if you want it formated or what, if so, *sqlparse*provides 
a good way to do it.


but, again, this will only work if you BIND an engine to your metadata, 
so sqlalchemy can write the right sql for you. also, your query should 
be a *select()*object, like your example.


this worked for me for some time, using SA 0.9, i don't know about 1.0, 
but it should work too.



cheers,
richard.


On 04/22/2015 04:26 AM, Pavel S wrote:

Hello,

I have pythonic application which imports custom module written in C++ 
using boost::python.

The module creates database connection(s) and executes queries.
The python calls various methods on that module and passes plain SQL 
into them. Results are then returned to python.


I would like to use SQLALchemy Core to generate plain SQL strings 
which will be passed the module.


Lets say I want to generate the following string:

|
SELECT A,B FROM TblWHERE C =Foo;
|

The equivalent in SA is:

|
query =select([
Tbl.c.A,
Tbl.c.B
]).where(
Tbl.c.C ==Foo
)
|

How can I produce the string from that query?
--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
attachment: richard.vcf

Re: [sqlalchemy] polymorphic inheritance and unique constraints

2015-04-15 Thread Richard Gerd Kuesters

hello Mike!

so ... ok, based on this link 
http://docs.sqlalchemy.org/en/latest/faq/ormconfiguration.html#i-m-getting-a-warning-or-error-about-implicitly-combining-column-x-under-attribute-y 
(yeah yeah, well, rtfm for me), I was able to make it work like this:


   code

   class ContainerInstance(CoreMixin, TimestampMixin):

container_instance_id = CoreMixin.column_id()
parent_id = CoreMixin.column_fk(container_instance_id,
   nullable=False)
batch_id = CoreMixin.column_fk(Batch.id_, nullable=False)
container_instance_type =
   Column(EnumDictForInt(ContainerInstanceEnum), nullable=False,
   index=True)

__mapper_args__ = {
polymorphic_on: container_instance_type,
polymorphic_identity: ContainerInstanceEnum.NONE
}


   class ContainerAggregation(ContainerInstance):

container_instance_id =
   CoreMixin.column_fk(ContainerInstance.id_, primary_key=True)
container_descriptor_id =
   CoreMixin.column_fk(ContainerDescriptor.id_, nullable=False)
# tada!
batch_id = column_property(Column(BigInteger),
   ContainerInstance.batch_id)

__mapper_args__ = {
polymorphic_identity: ContainerInstanceEnum.AGGREGATION
}


   UniqueConstraint(ContainerAggregation.container_descriptor_id,
   ContainerAggregation.batch_id)

   /code


which brings me the question: I'm targeting *only* postgresql, so I have 
no need to pursue an agnostic approach in terms of inheritance. i do 
know that postgres inheritance system was discussed a lot in here, but, 
in my case - where i do want to have a constraint between parent and 
children - isn't it better to use postgres inheritance instead of 
duplicating the value to another table?


well, i did notice the sqlalchemy example of postgres inheritance 
https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/PostgreSQLInheritance, 
which uses written ddl and triggers. the problem is that i have extra 
fields in the inheritance table, which I think it is not a very good 
approach to postgres inheritance, but, either way, from your experience, 
what would be your tip?


ps: i found this link 
http://postgresql.nabble.com/Constraint-to-ensure-value-does-NOT-exist-in-another-table-td4493651.html 
interesting and may be another solution to this, since i already have a 
table descriptor (the polymorphic_on expression). of course, the 
approach does require an extra table, but with events I can easily make 
it work in sqlalchemy.



cheers,
richard.


On 04/14/2015 08:40 AM, Richard Gerd Kuesters | Pollux Automation wrote:

here, a better illustration with my actual code:

http://pastebin.com/RxS8Lzft


best regards,
richard.

On 04/13/2015 06:30 PM, Mike Bayer wrote:



On 4/13/15 4:59 PM, Richard Gerd Kuesters | Pollux Automation wrote:
well, this didn't work with upstream 1.0 - sorry, I was in another 
project and couldn't test it myself.



you're not doing the same thing this user was doing in any case...



Traceback (most recent call last):
  File database_test.py, line 46, in module
from plx.db.core import *
  File ../src/plx/db/core.py, line 901, in module
UniqueConstraint(ContainerInstance.batch_id, 
ContainerAggregation.container_descriptor_id,)
  File 
/home/richard/.pyenv/versions/vpak-pollux-2.7.9/lib/python2.7/site-packages/sqlalchemy/sql/schema.py, 
line 2464, in __init__
ColumnCollectionMixin.__init__(self, *columns, 
_autoattach=_autoattach)
  File 
/home/richard/.pyenv/versions/vpak-pollux-2.7.9/lib/python2.7/site-packages/sqlalchemy/sql/schema.py, 
line 2393, in __init__

self._check_attach()
  File 
/home/richard/.pyenv/versions/vpak-pollux-2.7.9/lib/python2.7/site-packages/sqlalchemy/sql/schema.py, 
line 2429, in _check_attach

table.description)
sqlalchemy.exc.ArgumentError: Column(s) 
'container_aggregation.fk_container_descriptor_id' are not part of 
table 'container_instance'.


I got sqlalchemy from git, today.

 sqlalchemy.__version__
'1.0.0'

container_aggretation is a subclass of container_instance. I'm not 
using concrete inheritance here, may this be the problem?


anything else, it's Python 2.7.9 + Linux + PostgreSQL 9.4.1.


cheers,
richard.

On 03/24/2015 08:49 PM, Michael Bayer wrote:

are these two separate constraints?  I just looked and it seems like they are 
distinct.

I just added a fix to 1.0 because someone was hacking around something similar 
to this.

The easiest way to get these for the moment is just to create the 
UniqueConstraint outside of the class definition.

class Foo(Base):
 # …

class Bar(Foo):
# …

UniqueConstraint(Bar.x, Foo.y)

that way all the columns are set up, should just work.



Richard Gerd Kuesters | Polluxrich...@pollux.com.br  wrote:


well, understanding better the docs for column conflicts, can i use a 
declared_attr in a unique constraint? if yes, my problem is solved :)


On 03/24/2015 10:33 AM, Michael Bayer wrote:

Richard Gerd Kuesters | Pollux
rich

Re: [sqlalchemy] polymorphic inheritance and unique constraints

2015-04-15 Thread Richard Gerd Kuesters


nevermind. i'm again victim of rtfm :)

http://docs.sqlalchemy.org/en/latest/dialects/postgresql.html#postgresql-table-options

great work on this, btw. it'll simplify my life *A LOT* :)


best regards,
richard.

On 04/15/2015 10:10 AM, Richard Gerd Kuesters wrote:

hello Mike!

so ... ok, based on this link 
http://docs.sqlalchemy.org/en/latest/faq/ormconfiguration.html#i-m-getting-a-warning-or-error-about-implicitly-combining-column-x-under-attribute-y 
(yeah yeah, well, rtfm for me), I was able to make it work like this:


code

class ContainerInstance(CoreMixin, TimestampMixin):

container_instance_id = CoreMixin.column_id()
parent_id = CoreMixin.column_fk(container_instance_id,
nullable=False)
batch_id = CoreMixin.column_fk(Batch.id_, nullable=False)
container_instance_type =
Column(EnumDictForInt(ContainerInstanceEnum), nullable=False,
index=True)

__mapper_args__ = {
polymorphic_on: container_instance_type,
polymorphic_identity: ContainerInstanceEnum.NONE
}


class ContainerAggregation(ContainerInstance):

container_instance_id =
CoreMixin.column_fk(ContainerInstance.id_, primary_key=True)
container_descriptor_id =
CoreMixin.column_fk(ContainerDescriptor.id_, nullable=False)
# tada!
batch_id = column_property(Column(BigInteger),
ContainerInstance.batch_id)

__mapper_args__ = {
polymorphic_identity: ContainerInstanceEnum.AGGREGATION
}


UniqueConstraint(ContainerAggregation.container_descriptor_id,
ContainerAggregation.batch_id)

/code


which brings me the question: I'm targeting *only* postgresql, so I 
have no need to pursue an agnostic approach in terms of inheritance. i 
do know that postgres inheritance system was discussed a lot in here, 
but, in my case - where i do want to have a constraint between parent 
and children - isn't it better to use postgres inheritance instead of 
duplicating the value to another table?


well, i did notice the sqlalchemy example of postgres inheritance 
https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/PostgreSQLInheritance, 
which uses written ddl and triggers. the problem is that i have extra 
fields in the inheritance table, which I think it is not a very good 
approach to postgres inheritance, but, either way, from your 
experience, what would be your tip?


ps: i found this link 
http://postgresql.nabble.com/Constraint-to-ensure-value-does-NOT-exist-in-another-table-td4493651.html 
interesting and may be another solution to this, since i already have 
a table descriptor (the polymorphic_on expression). of course, the 
approach does require an extra table, but with events I can easily 
make it work in sqlalchemy.



cheers,
richard.


On 04/14/2015 08:40 AM, Richard Gerd Kuesters | Pollux Automation wrote:

here, a better illustration with my actual code:

http://pastebin.com/RxS8Lzft


best regards,
richard.

On 04/13/2015 06:30 PM, Mike Bayer wrote:



On 4/13/15 4:59 PM, Richard Gerd Kuesters | Pollux Automation wrote:
well, this didn't work with upstream 1.0 - sorry, I was in another 
project and couldn't test it myself.



you're not doing the same thing this user was doing in any case...



Traceback (most recent call last):
  File database_test.py, line 46, in module
from plx.db.core import *
  File ../src/plx/db/core.py, line 901, in module
UniqueConstraint(ContainerInstance.batch_id, 
ContainerAggregation.container_descriptor_id,)
  File 
/home/richard/.pyenv/versions/vpak-pollux-2.7.9/lib/python2.7/site-packages/sqlalchemy/sql/schema.py, 
line 2464, in __init__
ColumnCollectionMixin.__init__(self, *columns, 
_autoattach=_autoattach)
  File 
/home/richard/.pyenv/versions/vpak-pollux-2.7.9/lib/python2.7/site-packages/sqlalchemy/sql/schema.py, 
line 2393, in __init__

self._check_attach()
  File 
/home/richard/.pyenv/versions/vpak-pollux-2.7.9/lib/python2.7/site-packages/sqlalchemy/sql/schema.py, 
line 2429, in _check_attach

table.description)
sqlalchemy.exc.ArgumentError: Column(s) 
'container_aggregation.fk_container_descriptor_id' are not part of 
table 'container_instance'.


I got sqlalchemy from git, today.

 sqlalchemy.__version__
'1.0.0'

container_aggretation is a subclass of container_instance. I'm not 
using concrete inheritance here, may this be the problem?


anything else, it's Python 2.7.9 + Linux + PostgreSQL 9.4.1.


cheers,
richard.

On 03/24/2015 08:49 PM, Michael Bayer wrote:

are these two separate constraints?  I just looked and it seems like they are 
distinct.

I just added a fix to 1.0 because someone was hacking around something similar 
to this.

The easiest way to get these for the moment is just to create the 
UniqueConstraint outside of the class definition.

class Foo(Base):
 # …

class Bar(Foo):
# …

UniqueConstraint(Bar.x, Foo.y)

that way all the columns are set up, should just work.



Richard Gerd

Re: [sqlalchemy] polymorphic inheritance and unique constraints

2015-04-15 Thread Richard Gerd Kuesters
oops, i forgot to comment out the fk to the parent table and now it 
doesn't work: sqlalchemy.exc.NoForeignKeysError: Can't find any foreign 
key relationships between 'container_instance' and 'container_aggregation'.


well, it doesn't need it if it's inherited (both db and software level), 
right?




On 04/15/2015 02:55 PM, Richard Gerd Kuesters wrote:

the table definitions are listed here: http://pastebin.com/RxS8Lzft

i'm using polymorphic associations, but with inheritance (INHERITS) 
there's no need to do it (imho), so the fk column to the parent table 
(which is also the pk) can be overriden.


using add_is_dependent_on did the trick. i didn't know of such a 
feature ... thanks for bring it on :) although, is there a way to use 
it in declarative, intead of: 
MyModel.__table__.add_is_dependent_on(MyParentModel.__table__) ?



cheers,
richard.

On 04/15/2015 02:44 PM, Mike Bayer wrote:



On 4/15/15 1:07 PM, Richard Gerd Kuesters wrote:


ok, now i have an issue. i don't know why, but sqlalchemy seems to 
issue the create table command of inherited postgresql tables before 
the base one in metadata.create_all(). commenting the inherited 
table, issuing create all, 
what do your table defs look like?   The tables are created in order 
of FK dependency, and up until 1.0 there was no ordering beyond 
that.  in 1.0 they will be by table name if there are no FK dependencies.


if you're using this with INHERITS types of setups then you should 
establish which table is dependent on which using add_is_dependent_on():


http://docs.sqlalchemy.org/en/rel_0_9/core/metadata.html?highlight=add_is_dependent_on#sqlalchemy.schema.Table.add_is_dependent_on





then uncomment the table and issuing create all again seems to work, 
but ... it's a heck of a workaround (if i think in terms of code).


i even tried to use serializable isolation level, but no result. 
importing models in the desired order doesn't affect the behavior 
either. well, i'm out of options :)


a little help?


best regards,
richard.

On 04/15/2015 11:48 AM, Richard Gerd Kuesters wrote:


nevermind. i'm again victim of rtfm :)

http://docs.sqlalchemy.org/en/latest/dialects/postgresql.html#postgresql-table-options

great work on this, btw. it'll simplify my life *A LOT* :)


best regards,
richard.

On 04/15/2015 10:10 AM, Richard Gerd Kuesters wrote:

hello Mike!

so ... ok, based on this link 
http://docs.sqlalchemy.org/en/latest/faq/ormconfiguration.html#i-m-getting-a-warning-or-error-about-implicitly-combining-column-x-under-attribute-y 
(yeah yeah, well, rtfm for me), I was able to make it work like this:


code

class ContainerInstance(CoreMixin, TimestampMixin):

container_instance_id = CoreMixin.column_id()
parent_id = CoreMixin.column_fk(container_instance_id,
nullable=False)
batch_id = CoreMixin.column_fk(Batch.id_, nullable=False)
container_instance_type =
Column(EnumDictForInt(ContainerInstanceEnum), nullable=False,
index=True)

__mapper_args__ = {
polymorphic_on: container_instance_type,
polymorphic_identity: ContainerInstanceEnum.NONE
}


class ContainerAggregation(ContainerInstance):

container_instance_id =
CoreMixin.column_fk(ContainerInstance.id_, primary_key=True)
container_descriptor_id =
CoreMixin.column_fk(ContainerDescriptor.id_, nullable=False)
# tada!
batch_id = column_property(Column(BigInteger),
ContainerInstance.batch_id)

__mapper_args__ = {
polymorphic_identity: ContainerInstanceEnum.AGGREGATION
}


UniqueConstraint(ContainerAggregation.container_descriptor_id,
ContainerAggregation.batch_id)

/code


which brings me the question: I'm targeting *only* postgresql, so 
I have no need to pursue an agnostic approach in terms of 
inheritance. i do know that postgres inheritance system was 
discussed a lot in here, but, in my case - where i do want to have 
a constraint between parent and children - isn't it better to use 
postgres inheritance instead of duplicating the value to another 
table?


well, i did notice the sqlalchemy example of postgres inheritance 
https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/PostgreSQLInheritance, 
which uses written ddl and triggers. the problem is that i have 
extra fields in the inheritance table, which I think it is not a 
very good approach to postgres inheritance, but, either way, from 
your experience, what would be your tip?


ps: i found this link 
http://postgresql.nabble.com/Constraint-to-ensure-value-does-NOT-exist-in-another-table-td4493651.html 
interesting and may be another solution to this, since i already 
have a table descriptor (the polymorphic_on expression). of 
course, the approach does require an extra table, but with events 
I can easily make it work in sqlalchemy.



cheers,
richard.


On 04/14/2015 08:40 AM, Richard Gerd Kuesters | Pollux Automation 
wrote:

here, a better

Re: [sqlalchemy] polymorphic inheritance and unique constraints

2015-04-15 Thread Richard Gerd Kuesters
well, i'm almost given up ... i'm using concrete now, but it seems that 
something isn't right.


the error:

   sqlalchemy.exc.ArgumentError: When configuring property 'updated_by'
   on Mapper|ContainerInstance|pjoin, column
   'container_instance.fk_updated_by' is not represented in the
   mapper's table. Use the `column_property()` function to force this
   column to be mapped as a read-only attribute.

now, what makes me a little hopeless:

1. i have a base object (a simple object), that have some attributes 
that i want in ALL of my tables (created_at, updated_at, created_by, 
upated_by), which all of them are @declared_attr;
2. my base object is a declarative_base which uses the object above 
described as the cls parameter;
3. then, i inherit AbstractConcreteBase and my declarative object to the 
parent class, having all FKs in it as @declared_attr too;

4. from bla import *, exception.

ps: using ConcreteBase, the error is: AttributeError: type object 
'ContainerInstance' has no attribute '__mapper__'




On 04/15/2015 03:13 PM, Richard Gerd Kuesters wrote:

oh, right, concrete! abstract concrete can also do the trick?


On 04/15/2015 03:10 PM, Mike Bayer wrote:



On 4/15/15 1:59 PM, Richard Gerd Kuesters wrote:
oops, i forgot to comment out the fk to the parent table and now it 
doesn't work: sqlalchemy.exc.NoForeignKeysError: Can't find any 
foreign key relationships between 'container_instance' and 
'container_aggregation'.


well, it doesn't need it if it's inherited (both db and software 
level), right?

correct, you'd use a concrete setup here from a SQLA perspective.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
default-signature
Atenciosamente,

*Richard Gerd Kuesters*
*Pollux Automation*
Tel.: (47) 3025-9019
rich...@pollux.com.br | www.pollux.com.br
http://www.pollux.com.br/



• Linhas de Montagem
• Inspeção e Testes
• Robótica
• Identificação e Rastreabilidade
• Software para Manufatura


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] polymorphic inheritance and unique constraints

2015-04-15 Thread Richard Gerd Kuesters

oh, right, concrete! abstract concrete can also do the trick?


On 04/15/2015 03:10 PM, Mike Bayer wrote:



On 4/15/15 1:59 PM, Richard Gerd Kuesters wrote:
oops, i forgot to comment out the fk to the parent table and now it 
doesn't work: sqlalchemy.exc.NoForeignKeysError: Can't find any 
foreign key relationships between 'container_instance' and 
'container_aggregation'.


well, it doesn't need it if it's inherited (both db and software 
level), right?

correct, you'd use a concrete setup here from a SQLA perspective.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] polymorphic inheritance and unique constraints

2015-04-15 Thread Richard Gerd Kuesters

the table definitions are listed here: http://pastebin.com/RxS8Lzft

i'm using polymorphic associations, but with inheritance (INHERITS) 
there's no need to do it (imho), so the fk column to the parent table 
(which is also the pk) can be overriden.


using add_is_dependent_on did the trick. i didn't know of such a 
feature ... thanks for bring it on :) although, is there a way to use it 
in declarative, intead of: 
MyModel.__table__.add_is_dependent_on(MyParentModel.__table__) ?



cheers,
richard.

On 04/15/2015 02:44 PM, Mike Bayer wrote:



On 4/15/15 1:07 PM, Richard Gerd Kuesters wrote:


ok, now i have an issue. i don't know why, but sqlalchemy seems to 
issue the create table command of inherited postgresql tables before 
the base one in metadata.create_all(). commenting the inherited 
table, issuing create all, 
what do your table defs look like?   The tables are created in order 
of FK dependency, and up until 1.0 there was no ordering beyond that.  
in 1.0 they will be by table name if there are no FK dependencies.


if you're using this with INHERITS types of setups then you should 
establish which table is dependent on which using add_is_dependent_on():


http://docs.sqlalchemy.org/en/rel_0_9/core/metadata.html?highlight=add_is_dependent_on#sqlalchemy.schema.Table.add_is_dependent_on





then uncomment the table and issuing create all again seems to work, 
but ... it's a heck of a workaround (if i think in terms of code).


i even tried to use serializable isolation level, but no result. 
importing models in the desired order doesn't affect the behavior 
either. well, i'm out of options :)


a little help?


best regards,
richard.

On 04/15/2015 11:48 AM, Richard Gerd Kuesters wrote:


nevermind. i'm again victim of rtfm :)

http://docs.sqlalchemy.org/en/latest/dialects/postgresql.html#postgresql-table-options

great work on this, btw. it'll simplify my life *A LOT* :)


best regards,
richard.

On 04/15/2015 10:10 AM, Richard Gerd Kuesters wrote:

hello Mike!

so ... ok, based on this link 
http://docs.sqlalchemy.org/en/latest/faq/ormconfiguration.html#i-m-getting-a-warning-or-error-about-implicitly-combining-column-x-under-attribute-y 
(yeah yeah, well, rtfm for me), I was able to make it work like this:


code

class ContainerInstance(CoreMixin, TimestampMixin):

container_instance_id = CoreMixin.column_id()
parent_id = CoreMixin.column_fk(container_instance_id,
nullable=False)
batch_id = CoreMixin.column_fk(Batch.id_, nullable=False)
container_instance_type =
Column(EnumDictForInt(ContainerInstanceEnum), nullable=False,
index=True)

__mapper_args__ = {
polymorphic_on: container_instance_type,
polymorphic_identity: ContainerInstanceEnum.NONE
}


class ContainerAggregation(ContainerInstance):

container_instance_id =
CoreMixin.column_fk(ContainerInstance.id_, primary_key=True)
container_descriptor_id =
CoreMixin.column_fk(ContainerDescriptor.id_, nullable=False)
# tada!
batch_id = column_property(Column(BigInteger),
ContainerInstance.batch_id)

__mapper_args__ = {
polymorphic_identity: ContainerInstanceEnum.AGGREGATION
}


UniqueConstraint(ContainerAggregation.container_descriptor_id,
ContainerAggregation.batch_id)

/code


which brings me the question: I'm targeting *only* postgresql, so I 
have no need to pursue an agnostic approach in terms of 
inheritance. i do know that postgres inheritance system was 
discussed a lot in here, but, in my case - where i do want to have 
a constraint between parent and children - isn't it better to use 
postgres inheritance instead of duplicating the value to another table?


well, i did notice the sqlalchemy example of postgres inheritance 
https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/PostgreSQLInheritance, 
which uses written ddl and triggers. the problem is that i have 
extra fields in the inheritance table, which I think it is not a 
very good approach to postgres inheritance, but, either way, from 
your experience, what would be your tip?


ps: i found this link 
http://postgresql.nabble.com/Constraint-to-ensure-value-does-NOT-exist-in-another-table-td4493651.html 
interesting and may be another solution to this, since i already 
have a table descriptor (the polymorphic_on expression). of course, 
the approach does require an extra table, but with events I can 
easily make it work in sqlalchemy.



cheers,
richard.


On 04/14/2015 08:40 AM, Richard Gerd Kuesters | Pollux Automation 
wrote:

here, a better illustration with my actual code:

http://pastebin.com/RxS8Lzft


best regards,
richard.

On 04/13/2015 06:30 PM, Mike Bayer wrote:



On 4/13/15 4:59 PM, Richard Gerd Kuesters | Pollux Automation wrote:
well, this didn't work with upstream 1.0 - sorry, I was in 
another project and couldn't test it myself.



you're not doing the same thing this user

Re: [sqlalchemy] polymorphic inheritance and unique constraints

2015-04-15 Thread Richard Gerd Kuesters
yup, i know (this pattern) it is not ideal; i was just testing the new 
features of sa 1.0 regarding postgres (since i'm actually hands-on). i 
should rewrite a whole part of my model (and listeners and extensions 
and so on), which are already working with polymorphism.


i will change this pattern, but for now i had to know where i can go 
with those features to reach any other gain in postgres. i listed my 
steps in 1,2,3,4 so it's easier to spot where my mistake was (because i 
was sure it was mine).


:)

when i got the time this kind of implementation deserves, then i'll hook 
up on rewriting the model. thanks for the support and sorry if this 
wasted your time!



cheers,
richard.


On 04/15/2015 04:09 PM, Mike Bayer wrote:
The pattern you're doing is not what Posgresql INHERITS is really 
intended for.   PG's feature is intended for transparent sharding of 
data to different tablespaces, not to simulate OR-mapped class 
hierarchies.  The keyword is mis-named in this regard. Concrete inh is 
in all cases a tough road to travel because it's difficult to relate 
things to a whole set of tables which each act as the table for a class.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] polymorphic inheritance and unique constraints

2015-04-14 Thread Richard Gerd Kuesters | Pollux Automation
sorry, i mean i couldn't test it earlier, when i first asked the 
question :) it was not another co-worker, lol.


cheers,
richard.

On 04/13/2015 06:30 PM, Mike Bayer wrote:



On 4/13/15 4:59 PM, Richard Gerd Kuesters | Pollux Automation wrote:
well, this didn't work with upstream 1.0 - sorry, I was in another 
project and couldn't test it myself.



you're not doing the same thing this user was doing in any case...



Traceback (most recent call last):
  File database_test.py, line 46, in module
from plx.db.core import *
  File ../src/plx/db/core.py, line 901, in module
UniqueConstraint(ContainerInstance.batch_id, 
ContainerAggregation.container_descriptor_id,)
  File 
/home/richard/.pyenv/versions/vpak-pollux-2.7.9/lib/python2.7/site-packages/sqlalchemy/sql/schema.py, 
line 2464, in __init__
ColumnCollectionMixin.__init__(self, *columns, 
_autoattach=_autoattach)
  File 
/home/richard/.pyenv/versions/vpak-pollux-2.7.9/lib/python2.7/site-packages/sqlalchemy/sql/schema.py, 
line 2393, in __init__

self._check_attach()
  File 
/home/richard/.pyenv/versions/vpak-pollux-2.7.9/lib/python2.7/site-packages/sqlalchemy/sql/schema.py, 
line 2429, in _check_attach

table.description)
sqlalchemy.exc.ArgumentError: Column(s) 
'container_aggregation.fk_container_descriptor_id' are not part of 
table 'container_instance'.


I got sqlalchemy from git, today.

 sqlalchemy.__version__
'1.0.0'

container_aggretation is a subclass of container_instance. I'm not 
using concrete inheritance here, may this be the problem?


anything else, it's Python 2.7.9 + Linux + PostgreSQL 9.4.1.


cheers,
richard.

On 03/24/2015 08:49 PM, Michael Bayer wrote:

are these two separate constraints?  I just looked and it seems like they are 
distinct.

I just added a fix to 1.0 because someone was hacking around something similar 
to this.

The easiest way to get these for the moment is just to create the 
UniqueConstraint outside of the class definition.

class Foo(Base):
 # …

class Bar(Foo):
# …

UniqueConstraint(Bar.x, Foo.y)

that way all the columns are set up, should just work.



Richard Gerd Kuesters | Polluxrich...@pollux.com.br  wrote:


well, understanding better the docs for column conflicts, can i use a 
declared_attr in a unique constraint? if yes, my problem is solved :)


On 03/24/2015 10:33 AM, Michael Bayer wrote:

Richard Gerd Kuesters | Pollux
rich...@pollux.com.br
  wrote:



hi all!

i'm dealing with a little problem here. i have a parent table and its two 
inheritances. there is a value that both children have and must be unique along 
either types. is there a way to move this column to the parent and use a 
constraint in the child? my implementation is postgres 9.4+ with psycopg2 only.

if this is single table inheritance then the constraint would most ideally
be placed on the parent class.

if you’re trying to make this “magic” such that you can semantically keep
the unique constraints on the child classes, you’d need to build out a
conditional approach within @declared_attr. IMO I think this is an idealized
edge case that in the real world doesn’t matter much - just do what works
(put the col / constraint on the base).

the approach is described at

http://docs.sqlalchemy.org/en/rel_0_9/orm/extensions/declarative/inheritance.html#resolving-column-conflicts
.
You’d need to make this work for both the column and the constraint.




as a simple example (i'm just creating this example to simplify things), this 
works:

class MyParent(Base):

 foo_id = Column(Integer, Sequence('foo_id_seq'), primary_key=True)
 foo_name = Column(Unicode(64), nullable=False)
 foo_type = Column(Integer, nullable=False)

 __mapper_args__ = {
 polymorphic_on: foo_type,
 polymorphic_identity: 0
 }


class MyChild1(MyParent):

 foo_id = Column(Integer, ForeignKey(MyParent.foo_id), primary_key=True)
 bar_id = Column(Integer, ForeignKey(AnotherEntity.bar_id), nullable=False)
 child1_specific_name = Column(Unicode(5), nullable=False)
 child1_baz_stuff = Column(Boolean, default=False)

 __mapper_args__ = {
 polymorphic_identity: 1
 }

 __table_args__ = (
 UniqueConstraint(bar_id, child1_specific_name,),  # works, bar_id is 
in MyChild1
 )


class MyChild2(MyParent):

 foo_id = Column(Integer, ForeignKey(MyParent.foo_id), primary_key=True)
 bar_id = Column(Integer, ForeignKey(AnotherEntity.bar_id), nullable=False)
 child2_specific_code = Column(UUID, nullable=False)
 child2_baz_stuff = Column(Float, nullable=False)
 
 __mapper_args__ = {

 polymorphic_identity: 2
 }

 __table_args__ = (
 UniqueConstraint(bar_id, child2_specific_code,),  # works, bar_id is 
in MyChild2
 )


but i would like to do this, if possible:

class MyParent(Base):

 foo_id = Column(Integer, Sequence('foo_id_seq'), primary_key=True)
 foo_name = Column(Unicode(64

Re: [sqlalchemy] polymorphic inheritance and unique constraints

2015-04-13 Thread Richard Gerd Kuesters | Pollux Automation
well, this didn't work with upstream 1.0 - sorry, I was in another 
project and couldn't test it myself.


Traceback (most recent call last):
  File database_test.py, line 46, in module
from plx.db.core import *
  File ../src/plx/db/core.py, line 901, in module
UniqueConstraint(ContainerInstance.batch_id, 
ContainerAggregation.container_descriptor_id,)
  File 
/home/richard/.pyenv/versions/vpak-pollux-2.7.9/lib/python2.7/site-packages/sqlalchemy/sql/schema.py, 
line 2464, in __init__

ColumnCollectionMixin.__init__(self, *columns, _autoattach=_autoattach)
  File 
/home/richard/.pyenv/versions/vpak-pollux-2.7.9/lib/python2.7/site-packages/sqlalchemy/sql/schema.py, 
line 2393, in __init__

self._check_attach()
  File 
/home/richard/.pyenv/versions/vpak-pollux-2.7.9/lib/python2.7/site-packages/sqlalchemy/sql/schema.py, 
line 2429, in _check_attach

table.description)
sqlalchemy.exc.ArgumentError: Column(s) 
'container_aggregation.fk_container_descriptor_id' are not part of table 
'container_instance'.


I got sqlalchemy from git, today.

 sqlalchemy.__version__
'1.0.0'

container_aggretation is a subclass of container_instance. I'm not using 
concrete inheritance here, may this be the problem?


anything else, it's Python 2.7.9 + Linux + PostgreSQL 9.4.1.


cheers,
richard.

On 03/24/2015 08:49 PM, Michael Bayer wrote:

are these two separate constraints?  I just looked and it seems like they are 
distinct.

I just added a fix to 1.0 because someone was hacking around something similar 
to this.

The easiest way to get these for the moment is just to create the 
UniqueConstraint outside of the class definition.

class Foo(Base):
 # …

class Bar(Foo):
# …

UniqueConstraint(Bar.x, Foo.y)

that way all the columns are set up, should just work.



Richard Gerd Kuesters | Pollux rich...@pollux.com.br wrote:


well, understanding better the docs for column conflicts, can i use a 
declared_attr in a unique constraint? if yes, my problem is solved :)


On 03/24/2015 10:33 AM, Michael Bayer wrote:

Richard Gerd Kuesters | Pollux
rich...@pollux.com.br
  wrote:



hi all!

i'm dealing with a little problem here. i have a parent table and its two 
inheritances. there is a value that both children have and must be unique along 
either types. is there a way to move this column to the parent and use a 
constraint in the child? my implementation is postgres 9.4+ with psycopg2 only.

if this is single table inheritance then the constraint would most ideally
be placed on the parent class.

if you’re trying to make this “magic” such that you can semantically keep
the unique constraints on the child classes, you’d need to build out a
conditional approach within @declared_attr. IMO I think this is an idealized
edge case that in the real world doesn’t matter much - just do what works
(put the col / constraint on the base).

the approach is described at

http://docs.sqlalchemy.org/en/rel_0_9/orm/extensions/declarative/inheritance.html#resolving-column-conflicts
.
You’d need to make this work for both the column and the constraint.




as a simple example (i'm just creating this example to simplify things), this 
works:

class MyParent(Base):

 foo_id = Column(Integer, Sequence('foo_id_seq'), primary_key=True)
 foo_name = Column(Unicode(64), nullable=False)
 foo_type = Column(Integer, nullable=False)

 __mapper_args__ = {
 polymorphic_on: foo_type,
 polymorphic_identity: 0
 }


class MyChild1(MyParent):

 foo_id = Column(Integer, ForeignKey(MyParent.foo_id), primary_key=True)
 bar_id = Column(Integer, ForeignKey(AnotherEntity.bar_id), nullable=False)
 child1_specific_name = Column(Unicode(5), nullable=False)
 child1_baz_stuff = Column(Boolean, default=False)

 __mapper_args__ = {
 polymorphic_identity: 1
 }

 __table_args__ = (
 UniqueConstraint(bar_id, child1_specific_name,),  # works, bar_id is 
in MyChild1
 )


class MyChild2(MyParent):

 foo_id = Column(Integer, ForeignKey(MyParent.foo_id), primary_key=True)
 bar_id = Column(Integer, ForeignKey(AnotherEntity.bar_id), nullable=False)
 child2_specific_code = Column(UUID, nullable=False)
 child2_baz_stuff = Column(Float, nullable=False)
 
 __mapper_args__ = {

 polymorphic_identity: 2
 }

 __table_args__ = (
 UniqueConstraint(bar_id, child2_specific_code,),  # works, bar_id is 
in MyChild2
 )


but i would like to do this, if possible:

class MyParent(Base):

 foo_id = Column(Integer, Sequence('foo_id_seq'), primary_key=True)
 foo_name = Column(Unicode(64), nullable=False)
 foo_type = Column(Integer, nullable=False)
 bar_id = Column(Integer, ForeignKey(AnotherEntity.bar_id), nullable=False) 
 # since both child uses bar_id, why not having it on the parent?

 __mapper_args__ = {
 polymorphic_on: foo_type,
 polymorphic_identity: 0
 }


class

Re: [sqlalchemy] Any recommended approach for creating a new dialect?

2015-04-08 Thread Richard Gerd Kuesters | Pollux Automation
Mike, I remember an article of yours where you described much of the 
process of creating a new dialect for SA, for a Java database if I'm not 
mistaken. I wasn't able to find it, though.


:)

On 04/08/2015 01:19 AM, Mike Bayer wrote:



On 4/7/15 1:59 PM, Ralph Heinkel wrote:

Hello dialect experts,

what would be the best approach for creating a SqlAlchemy dialect for 
a new database system?
Are there any recipes available for this area, or is the way to go to 
read code of existing dialects and derive my own dialect from those?


I had a first glance at some built-in dialects, and also some in 
external packages ... it is not always obvious to me why certain 
classes and methods have been implemented.
The obvious thing is to create a subclass of 
sqlalchemy.enginedefault.DefaultDialect, but how would I know which 
methods and class attributes to override/implement, except for going 
through the trial and error approach?
And then there are other classes which are implemented in some 
dialects, like compiler.DDLCompiler, compiler.GenericTypeCompiler, 
and so on ... where and how would I start best?


Any help would be very much appreciated.

Start with the README for new dialects:

https://bitbucket.org/zzzeek/sqlalchemy/src/44a9820b4e02f65b3884fa2c016efce9663e4910/README.dialects.rst?at=master

that will show the guidelines for writing new dialects.

Then to see some examples of that layout, take a look at some of the 
3rd party dialects listed at:


http://docs.sqlalchemy.org/en/latest/dialects/index.html#production-ready

Also the sqlalchemy-access dialect is basically something of a 
demo for the layout, which I basically put there after extracting it 
from SQLAlchemy main where it had been for many years.   It might not 
be 100% up to date, but mostly follows that guideline and even passed 
tests at one point, that's at 
https://bitbucket.org/zzzeek/sqlalchemy-access.


The key thing you'll be doing is running the suite tests, which will 
be part of the test suite within your own dialect.  So yes, you start 
with a fairly plain subclass of DefaultDialect, then you probably want 
to get a hello world kind of program going where you just see if 
create_engine and then engine.execute(select * from table) work 
at all, and then the suite tests should test a lot more.








Ciao ciao

Ralph
--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] is True vs ==True

2015-03-30 Thread Richard Gerd Kuesters | Pollux

there's this:

* import sqlalchemy as sa**
** sa.sql.null()**
**sqlalchemy.sql.elements.Null object at 0x7f8a70065c50**
** sa.sql.false()**
**sqlalchemy.sql.elements.False_ object at 0x7f8a6fb13050**
** sa.sql.true()**
**sqlalchemy.sql.elements.True_ object at 0x7f8a70065c50**
*
so, you can still use __eq__ and pep-8 will not complain, because 
there's no way to implement is True or is None. then you'll have this:


*session.query(Rischio.c.codice).select_from(Rischio).filter(Rischio.c.peso_gruppo 
== sa.**sql.true()**)*


:)

On 03/30/2015 10:52 AM, Jose Soares wrote:
Hmm! in this case we must distinguish between the python syntax and 
the sqlalchemy syntax.:-(

j
On 30/03/2015 12:37, Simon King wrote:

On Mon, Mar 30, 2015 at 10:59 AM, Jose Soares
jose.soa...@sferacarta.com 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 behavior?


--

print
session.query(Rischio.c.codice).select_from(Rischio).filter(Rischio.c.peso_gruppo 


== True)

SELECT caratteristica_rischio.codice AS caratteristica_rischio_codice
FROM caratteristica_rischio
WHERE caratteristica_rischio.peso_gruppo = true

print
session.query(Rischio.c.codice).select_from(Rischio).filter(Rischio.c.peso_gruppo 


is True)
SELECT caratteristica_rischio.codice AS caratteristica_rischio_codice
FROM caratteristica_rischio
WHERE false


I don't think you can. SQLAlchemy expressions define an __eq__
method to enable expression == value-style constructs. There is no
equivalent hook in Python for the is operator, so there is no way
SQLAlchemy could use it.

Simon





--
Richard Gerd Kuesters
Pollux Automation
rich...@pollux.com.br mailto:rich...@pollux.com.br | www.pollux.com.br 
http://www.pollux.com.br



•Linhas de Montagem
•Inspeção e Testes
•Robótica   •Identificação e Rastreabilidade
•Software para Manufatura

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Table Views

2015-03-26 Thread Richard Gerd Kuesters | Pollux
you can use a select as a mapped object if you want, but i don't know if 
that's what you're looking for.



On 03/26/2015 01:54 PM, Philip Martin wrote:
am trying to setup schemas particularly related to financial reference 
data.  The data doesn't change very often, but I want to setup a good 
schema where changing one table row changes the data in the whole 
system, but also create table views the most useful aspects of the 
data reside in one table.


For example, say we have something like:


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] polymorphic inheritance and unique constraints

2015-03-25 Thread Richard Gerd Kuesters | Pollux

hell yeah! that's exactly what i was looking for :)

is it in the 1.0.0b3 or upstream?

best regards,
richard.

On 03/24/2015 08:49 PM, Michael Bayer wrote:

are these two separate constraints?  I just looked and it seems like they are 
distinct.

I just added a fix to 1.0 because someone was hacking around something similar 
to this.

The easiest way to get these for the moment is just to create the 
UniqueConstraint outside of the class definition.

class Foo(Base):
 # …

class Bar(Foo):
# …

UniqueConstraint(Bar.x, Foo.y)

that way all the columns are set up, should just work.



Richard Gerd Kuesters | Pollux rich...@pollux.com.br wrote:


well, understanding better the docs for column conflicts, can i use a 
declared_attr in a unique constraint? if yes, my problem is solved :)


On 03/24/2015 10:33 AM, Michael Bayer wrote:

Richard Gerd Kuesters | Pollux
rich...@pollux.com.br
  wrote:



hi all!

i'm dealing with a little problem here. i have a parent table and its two 
inheritances. there is a value that both children have and must be unique along 
either types. is there a way to move this column to the parent and use a 
constraint in the child? my implementation is postgres 9.4+ with psycopg2 only.

if this is single table inheritance then the constraint would most ideally
be placed on the parent class.

if you’re trying to make this “magic” such that you can semantically keep
the unique constraints on the child classes, you’d need to build out a
conditional approach within @declared_attr. IMO I think this is an idealized
edge case that in the real world doesn’t matter much - just do what works
(put the col / constraint on the base).

the approach is described at

http://docs.sqlalchemy.org/en/rel_0_9/orm/extensions/declarative/inheritance.html#resolving-column-conflicts
.
You’d need to make this work for both the column and the constraint.




as a simple example (i'm just creating this example to simplify things), this 
works:

class MyParent(Base):

 foo_id = Column(Integer, Sequence('foo_id_seq'), primary_key=True)
 foo_name = Column(Unicode(64), nullable=False)
 foo_type = Column(Integer, nullable=False)

 __mapper_args__ = {
 polymorphic_on: foo_type,
 polymorphic_identity: 0
 }


class MyChild1(MyParent):

 foo_id = Column(Integer, ForeignKey(MyParent.foo_id), primary_key=True)
 bar_id = Column(Integer, ForeignKey(AnotherEntity.bar_id), nullable=False)
 child1_specific_name = Column(Unicode(5), nullable=False)
 child1_baz_stuff = Column(Boolean, default=False)

 __mapper_args__ = {
 polymorphic_identity: 1
 }

 __table_args__ = (
 UniqueConstraint(bar_id, child1_specific_name,),  # works, bar_id is 
in MyChild1
 )


class MyChild2(MyParent):

 foo_id = Column(Integer, ForeignKey(MyParent.foo_id), primary_key=True)
 bar_id = Column(Integer, ForeignKey(AnotherEntity.bar_id), nullable=False)
 child2_specific_code = Column(UUID, nullable=False)
 child2_baz_stuff = Column(Float, nullable=False)
 
 __mapper_args__ = {

 polymorphic_identity: 2
 }

 __table_args__ = (
 UniqueConstraint(bar_id, child2_specific_code,),  # works, bar_id is 
in MyChild2
 )


but i would like to do this, if possible:

class MyParent(Base):

 foo_id = Column(Integer, Sequence('foo_id_seq'), primary_key=True)
 foo_name = Column(Unicode(64), nullable=False)
 foo_type = Column(Integer, nullable=False)
 bar_id = Column(Integer, ForeignKey(AnotherEntity.bar_id), nullable=False) 
 # since both child uses bar_id, why not having it on the parent?

 __mapper_args__ = {
 polymorphic_on: foo_type,
 polymorphic_identity: 0
 }


class MyChild1(MyParent):

 foo_id = Column(Integer, ForeignKey(MyParent.foo_id), primary_key=True)
 child1_specific_name = Column(Unicode(5), nullable=False)
 child1_baz_stuff = Column(Boolean, default=False)

 __mapper_args__ = {
 polymorphic_identity: 1
 }

 __table_args__ = (
 UniqueConstraint(MyParent.bar_id, child1_specific_name,),  # will it 
work?
 )


class MyChild2(MyParent):

 foo_id = Column(Integer, ForeignKey(MyParent.foo_id), primary_key=True)
 child2_specific_code = Column(UUID, nullable=False)
 child2_baz_stuff = Column(Float, nullable=False)
 
 __mapper_args__ = {

 polymorphic_identity: 2
 }

 __table_args__ = (
 UniqueConstraint(MyParent.bar_id, child2_specific_code,),  # will it 
work?
 )


well, will it work without being a concrete inheritance? :)


best regards,
richard.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to
sqlalchemy+unsubscr...@googlegroups.com
.
To post to this group, send email to
sqlalchemy@googlegroups.com
.
Visit

[sqlalchemy] polymorphic inheritance and unique constraints

2015-03-24 Thread Richard Gerd Kuesters | Pollux

hi all!

i'm dealing with a little problem here. i have a parent table and its 
two inheritances. there is a value that both children have and must be 
unique along either types. is there a way to move this column to the 
parent and use a constraint in the child? my implementation is postgres 
9.4+ with psycopg2 only.


as a simple example (i'm just creating this example to simplify things), 
this works:



   class MyParent(Base):

foo_id = Column(Integer, Sequence('foo_id_seq'), primary_key=True)
foo_name = Column(Unicode(64), nullable=False)
foo_type = Column(Integer, nullable=False)

__mapper_args__ = {
polymorphic_on: foo_type,
polymorphic_identity: 0
}


   class MyChild1(MyParent):

foo_id = Column(Integer, ForeignKey(MyParent.foo_id),
   primary_key=True)
bar_id = Column(Integer, ForeignKey(AnotherEntity.bar_id),
   nullable=False)
child1_specific_name = Column(Unicode(5), nullable=False)
child1_baz_stuff = Column(Boolean, default=False)

__mapper_args__ = {
polymorphic_identity: 1
}

__table_args__ = (
UniqueConstraint(bar_id, child1_specific_name,),  # works,
   bar_id is in MyChild1
)


   class MyChild2(MyParent):

foo_id = Column(Integer, ForeignKey(MyParent.foo_id),
   primary_key=True)
bar_id = Column(Integer, ForeignKey(AnotherEntity.bar_id),
   nullable=False)
child2_specific_code = Column(UUID, nullable=False)
child2_baz_stuff = Column(Float, nullable=False)

__mapper_args__ = {
polymorphic_identity: 2
}

__table_args__ = (
UniqueConstraint(bar_id, child2_specific_code,),  # works,
   bar_id is in MyChild2
)



but i would like to do this, if possible:


   class MyParent(Base):

foo_id = Column(Integer, Sequence('foo_id_seq'), primary_key=True)
foo_name = Column(Unicode(64), nullable=False)
foo_type = Column(Integer, nullable=False)
bar_id = Column(Integer, ForeignKey(AnotherEntity.bar_id),
   nullable=False)  # since both child uses bar_id, why not having it
   on the parent?

__mapper_args__ = {
polymorphic_on: foo_type,
polymorphic_identity: 0
}


   class MyChild1(MyParent):

foo_id = Column(Integer, ForeignKey(MyParent.foo_id),
   primary_key=True)
child1_specific_name = Column(Unicode(5), nullable=False)
child1_baz_stuff = Column(Boolean, default=False)

__mapper_args__ = {
polymorphic_identity: 1
}

__table_args__ = (
UniqueConstraint(MyParent.bar_id, child1_specific_name,), 
   # will it work?

)


   class MyChild2(MyParent):

foo_id = Column(Integer, ForeignKey(MyParent.foo_id),
   primary_key=True)
child2_specific_code = Column(UUID, nullable=False)
child2_baz_stuff = Column(Float, nullable=False)

__mapper_args__ = {
polymorphic_identity: 2
}

__table_args__ = (
UniqueConstraint(MyParent.bar_id, child2_specific_code,), 
   # will it work?

)



well, will it work without being a concrete inheritance? :)


best regards,
richard.

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] polymorphic inheritance and unique constraints

2015-03-24 Thread Richard Gerd Kuesters | Pollux

thanks again, Mike!

just a question: to make the constraint in the parent, shouldn't i move 
other columns that composes the constraint to the parent too?



cheers,
richard.

On 03/24/2015 10:33 AM, Michael Bayer wrote:


Richard Gerd Kuesters | Pollux rich...@pollux.com.br wrote:


hi all!

i'm dealing with a little problem here. i have a parent table and its two 
inheritances. there is a value that both children have and must be unique along 
either types. is there a way to move this column to the parent and use a 
constraint in the child? my implementation is postgres 9.4+ with psycopg2 only.

if this is single table inheritance then the constraint would most ideally
be placed on the parent class.

if you’re trying to make this “magic” such that you can semantically keep
the unique constraints on the child classes, you’d need to build out a
conditional approach within @declared_attr. IMO I think this is an idealized
edge case that in the real world doesn’t matter much - just do what works
(put the col / constraint on the base).

the approach is described at
http://docs.sqlalchemy.org/en/rel_0_9/orm/extensions/declarative/inheritance.html#resolving-column-conflicts.
You’d need to make this work for both the column and the constraint.



as a simple example (i'm just creating this example to simplify things), this 
works:

class MyParent(Base):

 foo_id = Column(Integer, Sequence('foo_id_seq'), primary_key=True)
 foo_name = Column(Unicode(64), nullable=False)
 foo_type = Column(Integer, nullable=False)

 __mapper_args__ = {
 polymorphic_on: foo_type,
 polymorphic_identity: 0
 }


class MyChild1(MyParent):

 foo_id = Column(Integer, ForeignKey(MyParent.foo_id), primary_key=True)
 bar_id = Column(Integer, ForeignKey(AnotherEntity.bar_id), nullable=False)
 child1_specific_name = Column(Unicode(5), nullable=False)
 child1_baz_stuff = Column(Boolean, default=False)

 __mapper_args__ = {
 polymorphic_identity: 1
 }

 __table_args__ = (
 UniqueConstraint(bar_id, child1_specific_name,),  # works, bar_id is 
in MyChild1
 )


class MyChild2(MyParent):

 foo_id = Column(Integer, ForeignKey(MyParent.foo_id), primary_key=True)
 bar_id = Column(Integer, ForeignKey(AnotherEntity.bar_id), nullable=False)
 child2_specific_code = Column(UUID, nullable=False)
 child2_baz_stuff = Column(Float, nullable=False)
 
 __mapper_args__ = {

 polymorphic_identity: 2
 }

 __table_args__ = (
 UniqueConstraint(bar_id, child2_specific_code,),  # works, bar_id is 
in MyChild2
 )


but i would like to do this, if possible:

class MyParent(Base):

 foo_id = Column(Integer, Sequence('foo_id_seq'), primary_key=True)
 foo_name = Column(Unicode(64), nullable=False)
 foo_type = Column(Integer, nullable=False)
 bar_id = Column(Integer, ForeignKey(AnotherEntity.bar_id), nullable=False) 
 # since both child uses bar_id, why not having it on the parent?

 __mapper_args__ = {
 polymorphic_on: foo_type,
 polymorphic_identity: 0
 }


class MyChild1(MyParent):

 foo_id = Column(Integer, ForeignKey(MyParent.foo_id), primary_key=True)
 child1_specific_name = Column(Unicode(5), nullable=False)
 child1_baz_stuff = Column(Boolean, default=False)

 __mapper_args__ = {
 polymorphic_identity: 1
 }

 __table_args__ = (
 UniqueConstraint(MyParent.bar_id, child1_specific_name,),  # will it 
work?
 )


class MyChild2(MyParent):

 foo_id = Column(Integer, ForeignKey(MyParent.foo_id), primary_key=True)
 child2_specific_code = Column(UUID, nullable=False)
 child2_baz_stuff = Column(Float, nullable=False)
 
 __mapper_args__ = {

 polymorphic_identity: 2
 }

 __table_args__ = (
 UniqueConstraint(MyParent.bar_id, child2_specific_code,),  # will it 
work?
 )


well, will it work without being a concrete inheritance? :)


best regards,
richard.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] auto column naming (declarative)

2015-03-23 Thread Richard Gerd Kuesters | Pollux

hi all!

i remember bumping into this somewhere, but now that i need it, i can't 
find. Murphy ... well, here's the question:


* the company i work have a certain convention on naming columns in 
the database level, like dt_ for datetime, u_ for unicode, ut_ for 
unicodetext, and so on.


the question is, can't I use a event listener to do this by my own? a 
type is bound to a format, it's quite simple dict. example:


...
last_update = Column(dt_last_update, DateTime, on_update=func, 
default=func)

...

To:

...
last_update = Column(DateTime, on_update=func, default=func)  # 
dt_last_update is automatically created since it's a DateTime type (at 
the database level only)

...


best regards,
richard.

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] auto column naming (declarative)

2015-03-23 Thread Richard Gerd Kuesters | Pollux
thanks Mike! i'll be hooking up to this event. i remember using a 
working example of this a while ago, that's why i questioned :) but 
there's no problem creating one from scratch :)


best regards,
richard.

On 03/23/2015 01:39 PM, Michael Bayer wrote:

the before_parent_attach() event could do this, sure.  Might be a little tricky:

http://docs.sqlalchemy.org/en/rel_0_9/core/events.html?highlight=before_parent_attach#sqlalchemy.events.DDLEvents.before_parent_attach

Richard Gerd Kuesters | Pollux rich...@pollux.com.br wrote:


hi all!

i remember bumping into this somewhere, but now that i need it, i can't find. 
Murphy ... well, here's the question:

* the company i work have a certain convention on naming columns in the database level, like 
dt_ for datetime, u_ for unicode, ut_ for unicodetext, and so on.

the question is, can't I use a event listener to do this by my own? a type is 
bound to a format, it's quite simple dict. example:

 ...
 last_update = Column(dt_last_update, DateTime, on_update=func, 
default=func)
 ...

To:

 ...
 last_update = Column(DateTime, on_update=func, default=func)  # 
dt_last_update is automatically created since it's a DateTime type (at the 
database level only)
 ...


best regards,
richard.

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Old but Gold - SQLA + Twisted

2014-09-08 Thread Richard Gerd Kuesters

hello all :)

from the past years, i've been working on solutions to the problem 
described by Jean (we are co-workers, and we use twisted and sqlalchemy, 
A LOT), and as everybody may already know, it's a very complicated 
combination, since we have to do a lot of code around to have a 
consistent application.


ok, that's not bad, but ... since we are a team of several developers, 
from 'grey haired pythonistas' to 'fishes in a barrel', it's hard to 
mantain a quality standard, so we decided to take ALL our codebase based 
on twisted and sqlalchemy to give it a try on creating a better 
integration between them, specially if you are more acquainted to 
asynchronous programming.


*RESULTS*

1. we were able to create an asynchronous sqlalchemy, but it relies
   on deep object copy, so every promise (or deferred, on twisted's
   language) generates an overhead that is not welcome in our standards
   (or every programmer with a brain, lol);

2. without deep copy, furthermore we were able to have again a fully
   promise version of sqlalchemy, but we had to left aside all the ORM
   codebase and work only with low level sqlalchemy. that's a good
   result, but again, we'll have a problem with the fishes not using
   the ORM.


*THE PROBLEM*


SO, after reading a lot about the internals of sqlalchemy AND tons of 
solutions out there (sAsync, etc, etc) we always ended up with the same 
problem: thread safety. the orm design of sqlalchemy, specially the 
session states, are all designed to be thread safe (Mike, correct me if 
i'm wrong), so from there the work might be huge, but we are willing to 
work on a solution - specially if our main rdbms, postgres, have one (if 
not the best) of dialects implementations in sa. this solution we expect 
even to publish for others to use :)

*
**THREAD SAFETY*

ok, as Jean already stated (those are actually my words) that 99,9% of 
the programmers who uses sqlalchemy are quite happy with the solutions 
it already provides, which are in fact very, very usable. we have no 
problem with that.


but, what if we want to go further on this? i mean, we can already 
control a lot of things in sqlalchemy. i mean, a lot, really. it is very 
flexible in almost all aspects. but ... why it isn't when the subject is 
the session state? or it is and we are missing something?


*FINAL THOUGHTS*

the bottom line is not about twisted, just to be clear, but to implement 
a non thread safe session state system that can work with async 
frameworks (gevent, twisted, tornado) and so on. is that really possible?



my best regards,
richard.



On 09/05/2014 11:23 AM, Jean Marcel Duvoisin Shmidt wrote:

Hi everyone!

I have a more complex and architectural question to make,
it will be a bit long, but I want to make myself clear as I already 
have done some research ;D


in our company we have some *really* cool stuff made out of SQLA, we 
wrote over its ORM an abstraction to allow us to
build the same schema on the same database but in different 'database 
level schema' (from Postgresql), allowing us to
use the same codebase, same database, same architecture and separate 
clients content easily. We also managed to build
a EAV (entity, attribute, value) database in top of that, that allow 
us to change the database schema any time, any way,
and get it running it without touching the DB... aaannnddd in top of 
that we got a Schematics to represent the database

schema and allow us to work as a ORM over the SQLAORM.

Yeh its crazy, but it works, and its really *fast*. We handle 
thousands of client in that way, and we are happy with it, not

counting how flexible is the code and the database now.

But here comes the problem. We want to scale it up (not just out), and 
we made some tests on the past with SQLA + Twisted
using, Gevent, Twisted, Psycopg. First we managed successfully to 
integrate the SQLA-Core + SQLA-ORM + Our EAV-ORM
with twisted using twisted.deferToThread, with works nicely but it is 
not exactly what we wanted. This takes out all the purpose
of using twisted in the first place, as we end up with a threaded 
model, where queries are running in threads, and we have a
main thread managing all of that. What we really wanted is to make the 
app *assyncronous* on top of the ORM.


Than we managed to use assync features of Psycopg with twisted, and in 
a similar mode that is done with Alchimia. We where
able to make it work with SQLA-Core. But we found out that the ORM is 
completely designed with the synchronous paradigm,
for logical reasons of course - as 99.9% of the users will use it 
synchronously, and we though that the best way to make it
work is overwrite the Session, Query, SessionQuery and other classes 
to make it work with the deferred concept

(collection, CollectionAdapter, Attributes, and so on).

As an app developer there is no problem to create a session and all 
the ambient to handle every request on SQLA.
With provides isolation avoiding any concurrent problems, this 

Re: [sqlalchemy] Old but Gold - SQLA + Twisted

2014-09-08 Thread Richard Gerd Kuesters

hello Mike!

yeap, that would be the point. even though the object might already have 
this value somewhere, the result would be a promise, always.



best regards,
richard.


On 09/08/2014 11:31 AM, Michael Bayer wrote:

so anytime you say:

myobject.someattribute

you return a promise?  because with the ORM, any attribute can trigger 
a SQL query.






On Sep 8, 2014, at 9:08 AM, Richard Gerd Kuesters 
rich...@humantech.com.br mailto:rich...@humantech.com.br wrote:



hello all :)

from the past years, i've been working on solutions to the problem 
described by Jean (we are co-workers, and we use twisted and 
sqlalchemy, A LOT), and as everybody may already know, it's a very 
complicated combination, since we have to do a lot of code around to 
have a consistent application.


ok, that's not bad, but ... since we are a team of several 
developers, from 'grey haired pythonistas' to 'fishes in a barrel', 
it's hard to mantain a quality standard, so we decided to take ALL 
our codebase based on twisted and sqlalchemy to give it a try on 
creating a better integration between them, specially if you are more 
acquainted to asynchronous programming.


*RESULTS*

 1. we were able to create an asynchronous sqlalchemy, but it
relies on deep object copy, so every promise (or deferred, on
twisted's language) generates an overhead that is not welcome in
our standards (or every programmer with a brain, lol);

 2. without deep copy, furthermore we were able to have again a fully
promise version of sqlalchemy, but we had to left aside all the
ORM codebase and work only with low level sqlalchemy. that's a
good result, but again, we'll have a problem with the fishes not
using the ORM.


*THE PROBLEM*


SO, after reading a lot about the internals of sqlalchemy AND tons of 
solutions out there (sAsync, etc, etc) we always ended up with the 
same problem: thread safety. the orm design of sqlalchemy, specially 
the session states, are all designed to be thread safe (Mike, correct 
me if i'm wrong), so from there the work might be huge, but we are 
willing to work on a solution - specially if our main rdbms, 
postgres, have one (if not the best) of dialects implementations in 
sa. this solution we expect even to publish for others to use :)

*
**THREAD SAFETY*

ok, as Jean already stated (those are actually my words) that 99,9% 
of the programmers who uses sqlalchemy are quite happy with the 
solutions it already provides, which are in fact very, very usable. 
we have no problem with that.


but, what if we want to go further on this? i mean, we can already 
control a lot of things in sqlalchemy. i mean, a lot, really. it is 
very flexible in almost all aspects. but ... why it isn't when the 
subject is the session state? or it is and we are missing something?


*FINAL THOUGHTS*

the bottom line is not about twisted, just to be clear, but to 
implement a non thread safe session state system that can work with 
async frameworks (gevent, twisted, tornado) and so on. is that really 
possible?



my best regards,
richard.



On 09/05/2014 11:23 AM, Jean Marcel Duvoisin Shmidt wrote:

Hi everyone!

I have a more complex and architectural question to make,
it will be a bit long, but I want to make myself clear as I already 
have done some research ;D


in our company we have some *really* cool stuff made out of SQLA, we 
wrote over its ORM an abstraction to allow us to
build the same schema on the same database but in different 
'database level schema' (from Postgresql), allowing us to
use the same codebase, same database, same architecture and separate 
clients content easily. We also managed to build
a EAV (entity, attribute, value) database in top of that, that allow 
us to change the database schema any time, any way,
and get it running it without touching the DB... aaannnddd in top of 
that we got a Schematics to represent the database

schema and allow us to work as a ORM over the SQLAORM.

Yeh its crazy, but it works, and its really *fast*. We handle 
thousands of client in that way, and we are happy with it, not

counting how flexible is the code and the database now.

But here comes the problem. We want to scale it up (not just out), 
and we made some tests on the past with SQLA + Twisted
using, Gevent, Twisted, Psycopg. First we managed successfully to 
integrate the SQLA-Core + SQLA-ORM + Our EAV-ORM
with twisted using twisted.deferToThread, with works nicely but it 
is not exactly what we wanted. This takes out all the purpose
of using twisted in the first place, as we end up with a threaded 
model, where queries are running in threads, and we have a
main thread managing all of that. What we really wanted is to make 
the app *assyncronous* on top of the ORM.


Than we managed to use assync features of Psycopg with twisted, and 
in a similar mode that is done with Alchimia. We where
able to make it work with SQLA-Core. But we found out that the ORM 
is completely designed

Re: [sqlalchemy] Old but Gold - SQLA + Twisted

2014-09-08 Thread Richard Gerd Kuesters
the thing is i'm comfortable with all that. what i'm trying to automate, 
somehow, is the need to let my fishes transit around deferreds (or 
threads) objects that once belongs to one session and can easily be lost 
if its states changes in this process, including proper session handling 
(open, use, close).


i'm not talking about something magical here. let's say i need to 
integrate my app with another network apps -- that may have some 
latency, or want to spawn a task based on some object that needs to be 
found first, then just say to the user: hey, i'll work on it and 
that's it, i'll request a promise and close the connection to the user.




On 09/08/2014 11:59 AM, Michael Bayer wrote:
its almost like if it could return a promise, but then some kind of 
syntactical magic would just handle that we already know it's there, 
and just hide it, and then just do some kind of deferment so that we 
can just write the next line of code right below it. because promises 
and deferreds, it is 100% pre-determined when these will happen!   if 
only this completely predictable, repetitive, boilerplate task of 
receiving a deferral then waiting til the next line of code in the 
operation could be...somehow...*automated*.



or to put it another way: why are you comfortable with the ORM's 
implicit SQL on attribute access, but not with gevent's implicit 
defer on IO ?








On Sep 8, 2014, at 10:47 AM, Richard Gerd Kuesters 
rich...@humantech.com.br mailto:rich...@humantech.com.br wrote:



hello Mike!

yeap, that would be the point. even though the object might already 
have this value somewhere, the result would be a promise, always.



best regards,
richard.


On 09/08/2014 11:31 AM, Michael Bayer wrote:

so anytime you say:

myobject.someattribute

you return a promise?  because with the ORM, any attribute can 
trigger a SQL query.






On Sep 8, 2014, at 9:08 AM, Richard Gerd Kuesters 
rich...@humantech.com.br mailto:rich...@humantech.com.br wrote:



hello all :)

from the past years, i've been working on solutions to the 
problem described by Jean (we are co-workers, and we use twisted 
and sqlalchemy, A LOT), and as everybody may already know, it's a 
very complicated combination, since we have to do a lot of code 
around to have a consistent application.


ok, that's not bad, but ... since we are a team of several 
developers, from 'grey haired pythonistas' to 'fishes in a barrel', 
it's hard to mantain a quality standard, so we decided to take ALL 
our codebase based on twisted and sqlalchemy to give it a try on 
creating a better integration between them, specially if you are 
more acquainted to asynchronous programming.


*RESULTS*

 1. we were able to create an asynchronous sqlalchemy, but it
relies on deep object copy, so every promise (or deferred, on
twisted's language) generates an overhead that is not welcome
in our standards (or every programmer with a brain, lol);

 2. without deep copy, furthermore we were able to have again a
fully promise version of sqlalchemy, but we had to left aside
all the ORM codebase and work only with low level sqlalchemy.
that's a good result, but again, we'll have a problem with the
fishes not using the ORM.


*THE PROBLEM*


SO, after reading a lot about the internals of sqlalchemy AND tons 
of solutions out there (sAsync, etc, etc) we always ended up with 
the same problem: thread safety. the orm design of sqlalchemy, 
specially the session states, are all designed to be thread safe 
(Mike, correct me if i'm wrong), so from there the work might be 
huge, but we are willing to work on a solution - specially if our 
main rdbms, postgres, have one (if not the best) of dialects 
implementations in sa. this solution we expect even to publish for 
others to use :)

*
**THREAD SAFETY*

ok, as Jean already stated (those are actually my words) that 99,9% 
of the programmers who uses sqlalchemy are quite happy with the 
solutions it already provides, which are in fact very, very usable. 
we have no problem with that.


but, what if we want to go further on this? i mean, we can already 
control a lot of things in sqlalchemy. i mean, a lot, really. it is 
very flexible in almost all aspects. but ... why it isn't when the 
subject is the session state? or it is and we are missing something?


*FINAL THOUGHTS*

the bottom line is not about twisted, just to be clear, but to 
implement a non thread safe session state system that can work with 
async frameworks (gevent, twisted, tornado) and so on. is that 
really possible?



my best regards,
richard.



On 09/05/2014 11:23 AM, Jean Marcel Duvoisin Shmidt wrote:

Hi everyone!

I have a more complex and architectural question to make,
it will be a bit long, but I want to make myself clear as I 
already have done some research ;D


in our company we have some *really* cool stuff made out of SQLA, 
we wrote over its ORM an abstraction to allow us to
build the same schema on the same database

Re: [sqlalchemy] another quick question regarding abstract classes

2014-06-11 Thread Richard Gerd Kuesters

thanks again Mike! i'll work this here :)

my best regards,
richard.


On 06/10/2014 07:14 PM, Mike Bayer wrote:

On Tue Jun 10 15:36:09 2014, Richard Gerd Kuesters wrote:

so, here i am again with another weird question, but it may be
interesting for what it may come (i dunno yet).

the problem: i have a collection of abstract classes that, when
requested, the function (that does the request) checks in a internal
dictionary if that class was already created or creates it by using
declarative_base(cls=MyAbstractClass), that later can have an engine
and then work against a database.

i use this format because i work with multiple backends from multiple
sources, so abstract classes are a *must* here. now, the problem:
foreign keys and relationships. it's driving me nuts.

ok, let's say I have 2 classes, Foo and Bar, where Bar have one FK to 
Foo.



class Foo(object):
__abstract__ = True
foo_id = Column(...)
...

class Bar(object):
__abstract__ = True
foo_id = Column(ForeignKey(...))




/(those classes are just examples and weren't further coded because
it's a conceptual question)/

i know that the code might be wrong, because i can use @declared_attr
here and furthermore help sqlalchemy act accordingly (i don't know if
this is the right way to say it in english, but it is not a complain
about sqlalchemy actions).

ok, suppose I created two subclasses, one from each abstract model
(Foo and Bar) in a postgres database with some named schema, let's say
sc1. we then have sc1.foo and sc1.bar.

now, i want to create a third table, also from Bar, but in the sc2
schema, where its foreign key will reference sc1.foo, which postgres
supports nicely.

how can i work this out, in a pythonic and sqlalchemy friendly way?
does @declared_attr solves this? or do I have to map that foreign key
(and furthermore relationships) in the class mapper, before using it,
like a @classmethod of some kind?



@declared_attr can help since the decorated function is called with 
cls as an argument.  You can look on cls for __table_args__ or 
some other attribute if you need, and you can create a Table on the 
fly to serve as secondary, see 
http://docs.sqlalchemy.org/en/rel_0_9/_modules/examples/generic_associations/table_per_related.html 
for an example of what this looks like.







best regards and sorry for my english,
richard.

--
You received this message because you are subscribed to the Google
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com
mailto:sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.




--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] another quick question regarding abstract classes

2014-06-10 Thread Richard Gerd Kuesters
so, here i am again with another weird question, but it may be 
interesting for what it may come (i dunno yet).


the problem: i have a collection of abstract classes that, when 
requested, the function (that does the request) checks in a internal 
dictionary if that class was already created or creates it by using 
declarative_base(cls=MyAbstractClass), that later can have an engine 
and then work against a database.


i use this format because i work with multiple backends from multiple 
sources, so abstract classes are a *must* here. now, the problem: 
foreign keys and relationships. it's driving me nuts.


ok, let's say I have 2 classes, Foo and Bar, where Bar have one FK to Foo.


   class Foo(object):
__abstract__ = True
foo_id = Column(...)
...

   class Bar(object):
__abstract__ = True
foo_id = Column(ForeignKey(...))




/(those classes are just examples and weren't further coded because it's 
a conceptual question)/


i know that the code might be wrong, because i can use @declared_attr 
here and furthermore help sqlalchemy act accordingly (i don't know if 
this is the right way to say it in english, but it is not a complain 
about sqlalchemy actions).


ok, suppose I created two subclasses, one from each abstract model (Foo 
and Bar) in a postgres database with some named schema, let's say sc1. 
we then have sc1.foo and sc1.bar.


now, i want to create a third table, also from Bar, but in the sc2 
schema, where its foreign key will reference sc1.foo, which postgres 
supports nicely.


how can i work this out, in a pythonic and sqlalchemy friendly way? does 
@declared_attr solves this? or do I have to map that foreign key (and 
furthermore relationships) in the class mapper, before using it, like a 
@classmethod of some kind?



best regards and sorry for my english,
richard.

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Entity name - multiple schema - relationship

2014-05-19 Thread Richard Gerd Kuesters
yes. but i'll always have to use a bind anyway. this routing style has a 
problem to identify what entity you're querying (and then the mapper) 
when using functions, either at column level 
session.query(func.count(MyObj.attribute)) or at the query level 
itself session.query(MyObj.attribute).count(), among other functions 
(exists, etc).


best regards,
richard.


On 05/18/2014 05:04 PM, Michael Bayer wrote:
well if you're working with the RoutingSession example you can 
manufacture get_bind() and using_bind() to work in any way you want.   
  If you have the engine, as the example shows, 
session.using_bind(some_bind).query(...)



http://techspot.zzzeek.org/2012/01/11/django-style-database-routers-in-sqlalchemy/


On May 18, 2014, at 3:28 PM, Richard Gerd Kuesters 
rich...@humantech.com.br wrote:


yeah, well, i was using implicit for little things and explicit for 
the bigger ones, but it seems that even small things are error prone 
:) i was just wondering if there's a faster way to do it, even 
explicit, so i can get a class (whatever it is) to query against an 
engine i know (so there's the key to make things work). if I have a 
metadata bind to some engine, is there a quick (and performatic) way 
to know it?




Em 2014-05-18 16:21, Michael Bayer escreveu:



On May 18, 2014, at 12:10 PM, Richard Gerd Kuesters 
rich...@humantech.com.br mailto:rich...@humantech.com.br wrote:


well, this part is still working, as long as i remember. my biggest 
problem now - and has been for the last couple of years - is to 
manage this mayhem of classes and engines AND sessions, because 
everyone wants to go online with their data. i'm writting and 
rewriting a session manager that can simplify my life for a 
long time, i got close to get things done with your 
RoutingSession vertical example, but it doesn't work very well with 
functions, session.query(...).count() or .exists() and so on. i'm 
writing code as hell and still far from an acceptable, performatic 
session router (?) for a class that can come from anywhere, for 
one or more specific engines, without grind string ids everywhere.


well, i think my problem have a lot of weaknesses to discuss ... 
but, one at a time.


for now, any tips on enterprise multi-everything session routing? :)

you're trying to route to different sessions based on the 
intricacies of what's inside a SELECT statement?  See I just would 
never do that, it's very complicated and error prone.   I'd have an 
explicit node name sent in right at the top.  Explicit is better 
than implicit.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] SQLAlchemy and Informix advice

2014-05-19 Thread Richard Gerd Kuesters

Hi Massimo!

In the past, I have used SQLAlchemy to connect to Informix (using the 
db2 driver), but it was for pure lazyness -- I had to write everything 
by hand, and my application already was using SQLAlchemy, so ... But 
that was back in 2007. Those codes are long dead and not in my possession.


Let's see if I can address those problems better for you:

*1. */Does anyone know if the Informix support is something will be 
added?/: you can see all official dialects supported by SQLAlchemy in 
here: http://docs.sqlalchemy.org/en/rel_0_9/dialects/index.html


All supported dialects in SQLAlchemy have something in common (IMHO): 
SQL, obviously. Informix have support to SQL, of couse, but it also have 
a lot of other tools, spatial support, JSON and so on; that I may find 
hard see completely supported by SQLAlchemy. Of course, there are some 
engines that looks quite familiar to these, PostgreSQL, -but- I think 
it's support in SQLAlchemy is a completely different subject.


Are you planning to use SQLAlchemy ORM on top of Informix for common SQL 
tasks? If so, you can adapt - or even contribute - to the ibm_db_sa 
adapter :) Here's a good lecture: 
http://techspot.zzzeek.org/2012/10/25/supporting-a-very-interesting-new-database/ 
-- but, of course, the SQLAlchemy source code is the best way to know 
how dialects works under the hood.


If you're planning to use with the new JSON integration, boy I think you 
should stick to the roots somewhere, away from SQLAlchemy and close to 
Mongo's adapters (somewhere else I had bumped with MongoAlchemy 
http://www.mongoalchemy.org/, that provides a quite similar API to 
Mongo as SQLAlchemy offers to others RDBMs, but IMHO it looks like a 
huge waste of code time since SQL and NoSQL databases have just one 
thing in common: they store data somewhere).


*2. */Does this mean I can only use SQLAlchemy Core features and not 
the ORM?/: I don't know about that anymore, since everything I write to 
Informix (if and when applied) are not SQLAlchemy (or even Python) 
related, at all.


If you provide more information about what you're trying to accomplish, 
it may still be possible with SQLAlcheny, given some circumstances.



Best regards,
Richard.


On 05/19/2014 08:50 AM, Massimo Valle wrote:
I'm exploring SQLAlchemy features for a new project which must use an 
IBM Informix database.
Found the ibm_db and ibm_db_sa modules to integrate with SQLAlchemy 
and successfully connected to the database after some tries.


I found the ibm_db_sa module only supports DB2 and NOT Informix. At 
least this is what was answered me on the project page.


Now I have a couple of newbie questions for the SQLAlchemy experts:

1. Does anyone know if the Informix support is something will be 
added? (planned, considering). I don't know if this module is 
developed from IBM or SQLAlchemy so, I'm not even sure to whom address 
this question.
2. I see, I can connect to my Informix database, but can't use the 
ibm_db_sa module. Does this mean I can only use SQLAlchemy Core 
features and not the ORM? That would be sad since the ORM is exactly 
what I planned to use.


Thanks for help,

Massimo Valle

--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Re: SQLAlchemy and Informix advice

2014-05-19 Thread Richard Gerd Kuesters
Massimo, git it a try to the dialect that Mike passed you. I think it 
should give you a better start then using the ibm_db_sa module.



On 05/19/2014 10:40 AM, Massimo Valle wrote:


Thank you Richard,

about the 2nd question, sorry but I'm new to SQLAlchemy and trying to 
find a way, so using the ORM for SQL access to Informix is my goal. 
Following the tutorial, I found for the ORM I have to create a Session 
and my guess is for doing this, I need the SQLAlchemy module support 
through the ibm_db_sa module. At this time it spits an error because 
it expects a DB2 database (no Informix support). Or, is there another 
way to do it?
Unfortunately I have no time to contribute to the module for Infornix 
support, therefore I'm looking if there is a way to achieve my goal 
(that's using the ORM) as it's now.


thanks again for your help,

Massimo Valle



On Monday, May 19, 2014 1:50:04 PM UTC+2, Massimo Valle wrote:

I'm exploring SQLAlchemy features for a new project which must use
an IBM Informix database.
Found the ibm_db and ibm_db_sa modules to integrate with
SQLAlchemy and successfully connected to the database after some
tries.

I found the ibm_db_sa module only supports DB2 and NOT Informix.
At least this is what was answered me on the project page.

Now I have a couple of newbie questions for the SQLAlchemy experts:

1. Does anyone know if the Informix support is something will be
added? (planned, considering). I don't know if this module is
developed from IBM or SQLAlchemy so, I'm not even sure to whom
address this question.
2. I see, I can connect to my Informix database, but can't use the
ibm_db_sa module. Does this mean I can only use SQLAlchemy Core
features and not the ORM? That would be sad since the ORM is
exactly what I planned to use.

Thanks for help,

Massimo Valle

--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Entity name - multiple schema - relationship

2014-05-18 Thread Richard Gerd Kuesters
 

thanks Mike for your help, and I'm very, very sorry for consuming your
time with my awkard questions. 

anyway, what i said about my app is just part of it. imagine that i have
a lot of mapped classes to integrate my application (online, cloud
based, message based, etc etc) against some other popular ones --
including backend specific support -- such as (opensources) sugarcrm,
vtiger, openerp [...], and closed source -- dynamics, sap, etc etc etc 

i mean, i have a mayhem of mapped classes with a hell of different
configurations [and attributes [and versions [and engines ]]] that make
it a very, very hard to mantain, with oceans of scenarios that only sqla
[plus python] can make possible. 

i'm still digging sqlalchemy docs and source code (since 0.3) - plus
everything else you can find on github, adapters, pypi ... 

well, this part is still working, as long as i remember. my biggest
problem now - and has been for the last couple of years - is to manage
this mayhem of classes and engines AND sessions, because everyone wants
to go online with their data. i'm writting and rewriting a session
manager that can simplify my life for a long time, i got close to
get things done with your RoutingSession vertical example, but it
doesn't work very well with functions, session.query(...).count() or
.exists() and so on. i'm writing code as hell and still far from an
acceptable, performatic session router (?) for a class that can come
from anywhere, for one or more specific engines, without grind string
ids everywhere. 

well, i think my problem have a lot of weaknesses to discuss ... but,
one at a time. 

for now, any tips on enterprise multi-everything session routing? :) 

my best regards, 

richard. 

Em 2014-05-18 11:34, Michael Bayer escreveu: 

 thats why I have a hard time with your questions, you seem to have some 
 deeply unusual and intricate application that is lending itself to needing 
 all these new patterns. That's not to say I don't have some unusual patterns 
 in some of my applications, but when those use cases come up I had to work 
 pretty intensely to figure out how to make them work. 
 
 On May 17, 2014, at 8:47 PM, Richard Gerd Kuesters rich...@humantech.com.br 
 wrote: 
 
 in fact, i map classes against different metadata for different schemas, 
 since i like to have specialized parts of my app distributed in the database 
 (the postgres part). another part of my app generated sqlite databases on the 
 fly, based on the same structures conceived earlier. kinda strange situation 
 to explain, in a matter of fact. 
 
 Em 2014-05-17 18:37, Michael Bayer escreveu: 
 Just a thought if you're really mapping tons of classes on the fly as some 
 kind of en masse table gateway maybe look at automap
 
 Sent from my iPhone 
 
 On May 17, 2014, at 1:43 PM, Richard Kuesters rkuest...@gmail.com wrote:
 
 hi! sorry for bringing this up so late - sometimes we just have no time to 
 get in sync with all threads :) this is a subject that interests me. i mean, 
 let me explain my current condition: 
 
 i have a set of declarative classes that i get by calling a function, passing 
 it's declarative base as argument (so i can use them more then once, which 
 happens a lot). 
 
 reading about tometadata() made me think about simplifying this process: 
 cloning / copying stubs of my classes to new metadata, or even simplifying my 
 classes. what would be the appropriate approach, if any? 
 
 today i have this (and is not something i like): 
 
 DEF GET_GROUP_BAZ(DECL_BASE_OBJ): 
 
 CLASS FOO(DECL_BASE_OBJ): 
 ... # CLASS DEFINITION 
 
 CLASS BAR(DECL_BASE_OBJ): 
  # CLASS DEFINITION 
 
 RETURN DICT(FOO_CLS=FOO, BAR_CLS=BAR) 
 
 what i think would be more appropriate, but does relationships and all 
 special arguments (tablename, tableargs, etc) be a @declared_attr?: 
 
 CLASS FOO(OBJECT): 
 __ABSTRACT__ = TRUE # NECESSARY IN THIS CASE? 
 ... # SAME DEFINITION OF FOO 
 
 CLASS BAR(OBJECT): 
 __ABSTRACT__ = TRUE # ? 
 ... # SAME DEFINITION 
 
 DEF RUN(): 
 CLS_TO_APP1 = DICT(FOO_CLS=DECLARATIVE_BASE(CLS=FOO, NAME=APP1FOO), 
 BAR_CLS=DECLARATIVE_BASE(CLS=BAR, NAME=APP1BAR)) 
 CLS_TO_APP2 = DICT(FOO_CLS=DECLARATIVE_BASE(CLS=FOO, NAME=APP2FOO), 
 BAR_CLS=DECLARATIVE_BASE(CLS=BAR, NAME=APP2BAR)) 
 
 or i should have a declarative base with metadata bound to nothing and then 
 clone / copy / do something else? 
 
 best regards, 
 richard. 
 
 On Tue, May 6, 2014 at 12:21 PM, Michael Bayer mike...@zzzcomputing.com 
 wrote:
 
 set_shard is a special method added by the horizontal sharding extension. 
 
 you can do cross schema queries if you organize the schema names in terms of 
 which ones apply to the dynamic shard and which ones to the fixed shard, 
 if that's how it works. 
 
 If OTOH you literally need to join against multiple, dynamically named shards 
 at one time, then you need to spell those out explicitly. it gets more ugly 
 but if you want a Table that is on the fly linked to a certain schema

Re: [sqlalchemy] Entity name - multiple schema - relationship

2014-05-18 Thread Richard Gerd Kuesters
 

yeah, well, i was using implicit for little things and explicit for the
bigger ones, but it seems that even small things are error prone :) i
was just wondering if there's a faster way to do it, even explicit, so
i can get a class (whatever it is) to query against an engine i know (so
there's the key to make things work). if I have a metadata bind to some
engine, is there a quick (and performatic) way to know it? 

Em 2014-05-18 16:21, Michael Bayer escreveu: 

 On May 18, 2014, at 12:10 PM, Richard Gerd Kuesters 
 rich...@humantech.com.br wrote: 
 
 well, this part is still working, as long as i remember. my biggest problem 
 now - and has been for the last couple of years - is to manage this mayhem 
 of classes and engines AND sessions, because everyone wants to go online 
 with their data. i'm writting and rewriting a session manager that can 
 simplify my life for a long time, i got close to get things done with 
 your RoutingSession vertical example, but it doesn't work very well with 
 functions, session.query(...).count() or .exists() and so on. i'm writing 
 code as hell and still far from an acceptable, performatic session router 
 (?) for a class that can come from anywhere, for one or more specific 
 engines, without grind string ids everywhere. 
 
 well, i think my problem have a lot of weaknesses to discuss ... but, one at 
 a time. 
 
 for now, any tips on enterprise multi-everything session routing? :)
 
 you're trying to route to different sessions based on the intricacies of 
 what's inside a SELECT statement? See I just would never do that, it's very 
 complicated and error prone. I'd have an explicit node name sent in right at 
 the top. Explicit is better than implicit.
 

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Entity name - multiple schema - relationship

2014-05-17 Thread Richard Gerd Kuesters
 

in fact, i map classes against different metadata for different schemas,
since i like to have specialized parts of my app distributed in the
database (the postgres part). another part of my app generated sqlite
databases on the fly, based on the same structures conceived earlier.
kinda strange situation to explain, in a matter of fact. 

Em 2014-05-17 18:37, Michael Bayer escreveu: 

 Just a thought if you're really mapping tons of classes on the fly as some 
 kind of en masse table gateway maybe look at automap
 
 Sent from my iPhone 
 
 On May 17, 2014, at 1:43 PM, Richard Kuesters rkuest...@gmail.com wrote:
 
 hi! sorry for bringing this up so late - sometimes we just have no time to 
 get in sync with all threads :) this is a subject that interests me. i mean, 
 let me explain my current condition: 
 
 i have a set of declarative classes that i get by calling a function, passing 
 it's declarative base as argument (so i can use them more then once, which 
 happens a lot). 
 
 reading about tometadata() made me think about simplifying this process: 
 cloning / copying stubs of my classes to new metadata, or even simplifying my 
 classes. what would be the appropriate approach, if any? 
 
 today i have this (and is not something i like): 
 
 DEF GET_GROUP_BAZ(DECL_BASE_OBJ): 
 
 CLASS FOO(DECL_BASE_OBJ): 
 ... # CLASS DEFINITION 
 
 CLASS BAR(DECL_BASE_OBJ): 
  # CLASS DEFINITION 
 
 RETURN DICT(FOO_CLS=FOO, BAR_CLS=BAR) 
 
 what i think would be more appropriate, but does relationships and all 
 special arguments (tablename, tableargs, etc) be a @declared_attr?: 
 
 CLASS FOO(OBJECT): 
 __ABSTRACT__ = TRUE # NECESSARY IN THIS CASE? 
 ... # SAME DEFINITION OF FOO 
 
 CLASS BAR(OBJECT): 
 __ABSTRACT__ = TRUE # ? 
 ... # SAME DEFINITION 
 
 DEF RUN(): 
 CLS_TO_APP1 = DICT(FOO_CLS=DECLARATIVE_BASE(CLS=FOO, NAME=APP1FOO), 
 BAR_CLS=DECLARATIVE_BASE(CLS=BAR, NAME=APP1BAR)) 
 CLS_TO_APP2 = DICT(FOO_CLS=DECLARATIVE_BASE(CLS=FOO, NAME=APP2FOO), 
 BAR_CLS=DECLARATIVE_BASE(CLS=BAR, NAME=APP2BAR)) 
 
 or i should have a declarative base with metadata bound to nothing and then 
 clone / copy / do something else? 
 
 best regards, 
 richard. 
 
 On Tue, May 6, 2014 at 12:21 PM, Michael Bayer mike...@zzzcomputing.com 
 wrote:
 
 set_shard is a special method added by the horizontal sharding extension. 
 
 you can do cross schema queries if you organize the schema names in terms of 
 which ones apply to the dynamic shard and which ones to the fixed shard, 
 if that's how it works. 
 
 If OTOH you literally need to join against multiple, dynamically named shards 
 at one time, then you need to spell those out explicitly. it gets more ugly 
 but if you want a Table that is on the fly linked to a certain schema 
 explicitly you can use table.tometadata(), see 
 http://docs.sqlalchemy.org/en/rel_0_9/core/metadata.html?highlight=tometadata#sqlalchemy.schema.Table.tometadata
  [1]. 
 
 On May 6, 2014, at 3:06 AM, Julien Meyer julien.mey...@gmail.com wrote: 
 
 My real database schema is a little more complex. 
 In reality, I have one database by company. In each database, I have multiple 
 schemas who contain the same table structure. 
 
 The solution schema name execution will not work in the case when I need to 
 access to more than one schema by request. 
 
 The Horizontal sharding can work : one engine by schema and set the search 
 path when creating the engine. During the request processing, I can identify 
 wich schema to use and with the use of set_shard on the Query object (not 
 found in the documentation, normal ?), I can easely select the good shard to 
 use. 
 But I don't know how I can make a cross schema query in this case? 
 
 Le lundi 5 mai 2014 19:12:06 UTC+2, Michael Bayer a écrit : 
 part of a feature that will make this kind of thing more direct is the 
 schema name execution argument feature, which is 
 https://bitbucket.org/zzzeek/sqlalchemy/issue/2685/default-schema-as-an-execution-argument
  [2]. 
 
 This application is somewhat of a multi-tenancy application; technically 
 its horizontally partitioned but if you know society up front and for the 
 duration of an operation, you can just set that and be done with it. 
 
 Assuming this is the case an easy way to do this for now is just to set the 
 search path on your postgresql connection before such an operation 
 proceeds. That way when you refer to table X or Y, it will be in terms of 
 whatever search path you've set, see 5.7.3 at 
 http://www.postgresql.org/docs/8.1/static/ddl-schemas.html [3]. 
 
 There's no need in that case to use any kind of explicit horizontal 
 sharding. Only if you need queries that are going to refer to multiple 
 schemas at once does the HS feature come into play (and if that were the case 
 I'd look into PG table inheritance). 
 
 On May 5, 2014, at 8:41 AM, Julien Meyer julien...@gmail.com [4] wrote: 
 
 I need some help and advices to create a mapping. 
 
 The context : 
 - Multiple schemas on postgresql 

Re: [sqlalchemy] selects, mappers and foreign keys

2014-05-11 Thread Richard Gerd Kuesters
 

thanks Mike! 

the problem is that the other side is also a selectable, so: 

foo = relationship(Remote, primaryjoin=myselect.c.foo ==
myotherselect.c.bar) 

myselect.c.foo *is* a foreign key to some table primary key that is the
value of myotherselect.c.bar, but i can't figure out why or how to make
foreign keys to be detected, basically because i'm trying to use some
weird postgres queries using recursivity and connect paths, so in the
end the error I always get is: 

/path/to/lib/python2.7/site-packages/sqlalchemy/sql/elements.pyc in
_only_column_elements(element, name)
 3348 raise exc.ArgumentError(
 3349 Column-based expression object expected for argument 
- 3350 '%s'; got: '%s', type %s % (name, element, type(element)))
 3351 return element
 3352 

ArgumentError: Column-based expression object expected for argument
'foreign_keys'; got: 'None', type type 'NoneType' 

perhaps i'm asking too much of everything? :) 

best regards, 

richard. 

Em 2014-05-11 00:01, Michael Bayer escreveu: 

 On May 10, 2014, at 7:13 PM, Richard Gerd Kuesters rich...@humantech.com.br 
 wrote: 
 
 hi all! 
 
 situation: i'm mapping a select as a class, using mapper. so far so good. 
 
 problem: some of my selected columns *are* foreign keys in their respective 
 tables, but i would like to say to sqla that they're foreign keys to another 
 mapped class, which have the pks from which those fks are pointing. 
 
 the first question is: how? or
 
 should be able to use relationship(), set up primaryjoin with foreign() 
 
 foo = relationship(Remote, primaryjoin=myselect.c.foo == 
 foreign(table.c.foo)) 
 
 it's a little weird i guess, should work out in modern versions 
 
 the second question: is there a way to inherit properties (like fks) OR 
 cheat declaring foreign keys that doesn't exists at the database level ?
 
 sure, use ForeignKey() on your Column(), doesn't matter if it's not in the 
 DB, or use in relationship foreign_keys / foreign() annotation 
 
 my best regards, 
 
 richard.
 

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] selects, mappers and foreign keys

2014-05-11 Thread Richard Gerd Kuesters
 

thanks Mike, that worked fine. my code, though, didn't went further
(i'll have to debug a little bit more) :) 

best regards, 

richard. 

Em 2014-05-11 14:43, Michael Bayer escreveu: 

 On May 11, 2014, at 10:38 AM, Richard Gerd Kuesters 
 rich...@humantech.com.br wrote: 
 
 thanks Mike! 
 
 the problem is that the other side is also a selectable, so: 
 
 foo = relationship(Remote, primaryjoin=myselect.c.foo == 
 myotherselect.c.bar)
 
 so again, i can see this might have issues, but in theory (meaning, if it 
 doesn't work, I should be able to make it work), it would be: 
 
 foo = relationship(Remote, primaryjoin=myselect.c.foo == 
 remote(foreign(myotherselect.c.bar)))

 

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] selects, mappers and foreign keys

2014-05-10 Thread Richard Gerd Kuesters
 

hi all! 

situation: i'm mapping a select as a class, using mapper. so far so
good. 

problem: some of my selected columns *are* foreign keys in their
respective tables, but i would like to say to sqla that they're foreign
keys to another mapped class, which have the pks from which those fks
are pointing. 

the first question is: how? or 

the second question: is there a way to inherit properties (like fks) OR
cheat declaring foreign keys that doesn't exists at the database level
? 

my best regards, 

richard. 

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] sqlite3 recursivity

2014-04-29 Thread Richard Gerd Kuesters
 

well, i thought it would be wiser to ask before :) i don't know if cte
is available for all dialects :) i'll give it a try and return asap :) 

best regards, 

richard. 

Em 2014-04-26 15:24, Michael Bayer escreveu: 

 what happens if you just try it? the syntax looks entirely standard. 
 
 On Apr 26, 2014, at 2:10 PM, Richard Gerd Kuesters rich...@humantech.com.br 
 wrote: 
 
 hi all! 
 
 as some already know, sqlite3 version 3.8.x (i'm not quite sure if it's 
 3.8.x, i might be wrong), but it has now support for recursivity using the 
 with operator: https://sqlite.org/lang_with.html [1] 
 
 well - probably mike can answear this better - will sqla provide basic 
 support for it, like we already have in postgres using cte? or in the near 
 future we'll only find 3rd part implementations, since it will take time 
 for the world to use this version up? 
 
 best regards, 
 
 richard. 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy [2].
 For more options, visit https://groups.google.com/d/optout [3].
 

Links:
--
[1] https://sqlite.org/lang_with.html
[2] http://groups.google.com/group/sqlalchemy
[3] https://groups.google.com/d/optout

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] self referential hybrid expression

2014-04-28 Thread Richard Gerd Kuesters

hi all,

i have a class that have a self reference through *_parent*. this class 
is mapped against an selectable, not a class (this information is 
useful, lol)


ok, so, using @hybrid_property, i can easily get the amount of children 
of this class:



*@hybrid_property**
**def child_count(self):**
**kls = self.__class__**
**session = object_session(self)**
**sel = select(**
** [**
** func.count(kls.id_)**
** ],**
** and_(**
** self.id_ == kls._parent,**
** or_(**
** self.language_id == kls.language_id,**
** kls.language_id.is_(sql.null())**
** )**
** )**
**)**
**return session.execute(sel).scalar()*


but, how can I transform it into an expression, so I can use it on a 
query, like *session.query(cls).filter(cls.child_count == 3).all()* ? i 
already did a lot of *@some_property.expression*, but I'm having a bit 
of a trouble on this one :)


any help would be appreciated ...


best regards,
richard.

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] sqlite3 recursivity

2014-04-26 Thread Richard Gerd Kuesters
 

hi all! 

as some already know, sqlite3 version 3.8.x (i'm not quite sure if it's
3.8.x, i might be wrong), but it has now support for recursivity using
the with operator: https://sqlite.org/lang_with.html [1] 

well - probably mike can answear this better - will sqla provide basic
support for it, like we already have in postgres using cte? or in the
near future we'll only find 3rd part implementations, since it will
take time for the world to use this version up? 

best regards, 

richard. 

Links:
--
[1] https://sqlite.org/lang_with.html

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] job offer for python programmer - brazil

2014-04-17 Thread Richard Gerd Kuesters

Hi all!

First of all: it's Mike approved :P

I'm Richard, CTO of Humantech Knowledge Management, a brazilian based 
technology company with enphasis on data management, mining, storage, 
and so son. We are engaged with the opensource community, interacting 
and contributing (most of all bug patches, but sometimes we are able to 
share bigger things to the community). We are not stuck by programming 
languages, we simply choose the best one for each job, so you'll find in 
our team C, C++, C#, Java, Python, PHP, JavaScript, ActionScript, Bash, 
LISP, Perl, Tcl (and even Assembly!) programmers with great experience, 
having worked from the small to the biggest IT companies in the world. 
Our solutions cover a lot of scenarios, from desktops to tablets, with a 
great expertise in network systems and integrations.


We are currently searching for a Python programmer, specially if he (or 
she) already have experience with the framework that makes the heart of 
all our systems work: *SQLAlchemy* :)


The sallary is compatible to the experience of the programmer, with 
extras provided (such as a health plan).


Anyone interested, can contact me directly or navigate in our sites for 
more information - Humantech http://www.humantech.com.br/, Collabo 
http://www.collabo.com.br/, our github https://github.com/humantech 
- but, we are sorry since it's just brazilian portuguese ATM.



Cheers!
Richard.


/just fyi:/

 Original Message 
Subject:Re: question about sqlalchemy list
Date:   Thu, 17 Apr 2014 14:58:15 -0400
From:   Michael Bayer mike...@zzzcomputing.com
To: Richard Gerd Kuesters rich...@humantech.com.br



hi Richard -

feel free to forward it on, it's fine.

- mike


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] defining a relationship with IS NOT

2014-04-15 Thread Richard Gerd Kuesters

interesting, i didn't knew that :D

i was using shomething like (for softwares such as st2, which has pep8 
checking):


## variables

NULL = None  # f**k pep-8
TRUE = True  # f**k pep-8
FALSE = False  # f**k pep-8

so, somecol != NULL is not acused as violating pep8, lol.

well, just for fun :)

On 04/15/2014 02:44 AM, Michael Bayer wrote:

there's an isnot() operator, use that


On Apr 14, 2014, at 7:17 PM, Jonathan Vanasco jonat...@findmeon.com 
mailto:jonat...@findmeon.com wrote:



I'm on postgres and have a boolean column that allows NULL values.

I need to create a relationship between 2 ORM classes , where there 
is a filter that states IS NOT TRUE.


The ORM likes these 2 commands :
photo = sa.orm.relationship(Photo, primaryjoin=and_( 
Useraccount.photo_id==Photo.id , Photo.is 
http://Photo.is_deletion_scheduled != True ))
  photo = sa.orm.relationship(Photo, primaryjoin=and_( 
Useraccount.photo_id==Photo.id , Photo.is 
http://Photo.is_deletion_scheduled  True ))


however they don't compare correct in Postgresql.  I need this to 
work, however the mapper doesn't like it:
photo = sa.orm.relationship(Photo, primaryjoin=and_( 
Useraccount.photo_id==Photo.id , Photo.is 
http://Photo.is_deletion_scheduled IS NOT True ))


if I were doing a column comparison, I would do
Photo.is http://Photo.is_deletion_scheduled.op('IS NOT')(True)

anyone have an idea ?

--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] defining a relationship with IS NOT

2014-04-15 Thread Richard Gerd Kuesters

yeah, that's why I shared this :) good to know, i'll use that from now on ;)

my best regards,
richard.


On 04/15/2014 09:32 AM, Wichert Akkerman wrote:


On 15 Apr 2014, at 13:25, Richard Gerd Kuesters 
rich...@humantech.com.br mailto:rich...@humantech.com.br wrote:



interesting, i didn't knew that :D

i was using shomething like (for softwares such as st2, which has 
pep8 checking):


## variables

NULL = None  # f**k pep-8
TRUE = True  # f**k pep-8
FALSE = False  # f**k pep-8


You can also use sqlalchemy.sql.null(), sqlalchemy.sql.true() and 
sqlalchemy.sql.false()


Wichert.

--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Re: database design question

2014-04-09 Thread Richard Gerd Kuesters
yeah, that's the pain i'm trying to avoid :) i'll probably end up 
managing multiple connections, but that's a particular design of my app 
(plugin based, multiple subprocesses, and so on) ... :)



On 04/08/2014 06:48 PM, Jonathan Vanasco wrote:
I had a similar situation years ago.  We had software that helped 
automate online promotions for music releases.  Everyone insisted on 
keeping their data separate; forcing different databases was required 
by contract and we were strong-armed into it.  Today, things would be 
different.


I ended up having everything in a different client-specific database 
for each promotion.  The company stuff , like our global email/user 
directory, was handled in a company database.  Originally, I used 
SQL users and permissions that would give read/write to the company 
and a single client.  Eventually, I moved all of the company stuff 
into a centralized service -- multiple applications would talk to that 
service instead of the database.  The reason for all this trickery was 
a mix of permissions/security, DB administration ( being able to 
distribute different clients onto different machines ), and 
reporting/analysis usage that was much simpler with a per-database 
option.  there were a few other things I can't remember.


it was still f*** pain, and we ran into performance issues as we 
couldn't recycle database connections as aggressively as i wanted.  we 
sometimes had legacy projects that could tie up db connections for 
newer projects that were more popular.


Given the chance, I would never touch something like that again.

I just want to bring this up, because database connections do end up 
being an issue.  if you've got a single db connection string, you can 
really be aggressive with your connections.  If you have multiple db 
connection strings, you have to think about planning for database 
connectivity.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] database design question

2014-04-08 Thread Richard Gerd Kuesters

perhaps this would help?

http://techspot.zzzeek.org/2012/01/11/django-style-database-routers-in-sqlalchemy/

i'm willing to use different schemas to my question. if anyone have a 
better idea, let me know :)


best regards,
richard.


On 04/04/2014 01:58 PM, Richard Gerd Kuesters wrote:

hi all!

i have a question about sqlalchemy and database design.

i'm developing an app, where each client may receive an alert about 
the total space usage of their data (files and database), so, using 
postgresql, i can get them (data usage size) using a different 
tablespace, database or schema, if i'm not wrong. given these 
premises, which is the best way to design my database using 
sqlalchemy, having in mind that I need also to integrate the client 
databases to the core database?


my best regards,
richard.
--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] database design question

2014-04-08 Thread Richard Gerd Kuesters
thanks mike. i know it's a vague question, but that just the point: i 
don't know the answer because it can be both :)


let me clarify: assuming the application can be self hosted (in our 
ift), hence also multi-tenancy can be used for multiple clients. if not, 
the same codebase would run in the client's server space, in which some 
rules will does not comply - as a core client database will not be 
available, as an example.


assuming that i have a lot of clients in our self hosted platform, i 
could enable multi-tenancy, but can i query or join between different 
databases?


fyi, the server is postgres 9.x


thanks a lot,
richard.


On 04/08/2014 10:57 AM, Michael Bayer wrote:
this is a vague and open ended question, is this a multi-tenancy 
application?   does each client have their own database?  or is that 
the question?if its multi tenancy, Id probably give each client a 
different database, why not?




On Apr 4, 2014, at 12:58 PM, Richard Gerd Kuesters 
rich...@humantech.com.br mailto:rich...@humantech.com.br wrote:



hi all!

i have a question about sqlalchemy and database design.

i'm developing an app, where each client may receive an alert about 
the total space usage of their data (files and database), so, using 
postgresql, i can get them (data usage size) using a different 
tablespace, database or schema, if i'm not wrong. given these 
premises, which is the best way to design my database using 
sqlalchemy, having in mind that I need also to integrate the client 
databases to the core database?


my best regards,
richard.

--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] database design question

2014-04-08 Thread Richard Gerd Kuesters
thanks again mike. well, most of our software is already message driven, 
but we still need to group information if we want to; ex: search from 
all our clients databases for some value in a model that's shared 
between them.


thanks a lot,
richard.

On 04/08/2014 12:07 PM, Michael Bayer wrote:


On Apr 8, 2014, at 11:01 AM, Richard Gerd Kuesters 
rich...@humantech.com.br mailto:rich...@humantech.com.br wrote:


thanks mike. i know it's a vague question, but that just the point: i 
don't know the answer because it can be both :)


let me clarify: assuming the application can be self hosted (in our 
ift), hence also multi-tenancy can be used for multiple clients. if 
not, the same codebase would run in the client's server space, in 
which some rules will does not comply - as a core client database 
will not be available, as an example.


assuming that i have a lot of clients in our self hosted platform, i 
could enable multi-tenancy, but can i query or join between different 
databases?


there might be some way that PG can refer to different databases like 
schemas, but if you need to join between different databases, that 
means the app isn't multi-tenancy, its one big app with shared data.


I suspect that this join between different databases use case is 
more like, customers can access system A that has a set of common 
tables for everyone, or system B that is their database.A and B 
alone might be organized as separate databases to start with, so you 
don't need to join between different databases.   I'd prefer to 
approach this in as much of a service oriented way as possible.   
System A and B would share data strictly at the level of two services 
sending messages to each other.





fyi, the server is postgres 9.x


thanks a lot,
richard.


On 04/08/2014 10:57 AM, Michael Bayer wrote:
this is a vague and open ended question, is this a multi-tenancy 
application?   does each client have their own database?  or is that 
the question?if its multi tenancy, Id probably give each client 
a different database, why not?




On Apr 4, 2014, at 12:58 PM, Richard Gerd Kuesters 
rich...@humantech.com.br mailto:rich...@humantech.com.br wrote:



hi all!

i have a question about sqlalchemy and database design.

i'm developing an app, where each client may receive an alert about 
the total space usage of their data (files and database), so, using 
postgresql, i can get them (data usage size) using a different 
tablespace, database or schema, if i'm not wrong. given these 
premises, which is the best way to design my database using 
sqlalchemy, having in mind that I need also to integrate the client 
databases to the core database?


my best regards,
richard.

--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.



--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit

[sqlalchemy] create relationship after mapping

2014-04-08 Thread Richard Gerd Kuesters

hi all!

another question: i'm mapping some classes dinamically, using the 
mapper() function. i would like to create relationships, but not in the 
properties kwarg of mapper, but after:


*mapper(cls, my_select)**
**...**
**# detects any relationship**
**...**
**setattr(cls, 'my_attr'**, relationship(othercls, ...))*

is that possible?

best regards,
richard.

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] create relationship after mapping

2014-04-08 Thread Richard Gerd Kuesters

stupid me.


*mp = **mapper(cls, my_select)**
**...**
**# detects any relationship**
**...
mp.add_property(my_attr, relationship(othercls, ...))
***

sorry for thinking out loud (into the group) ...


best regards,
richard.

On 04/08/2014 04:31 PM, Richard Gerd Kuesters wrote:

hi all!

another question: i'm mapping some classes dinamically, using the 
mapper() function. i would like to create relationships, but not in 
the properties kwarg of mapper, but after:


*mapper(cls, my_select)**
**...**
**# detects any relationship**
**...**
**setattr(cls, 'my_attr'**, relationship(othercls, ...))*

is that possible?

best regards,
richard. --
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] database design question

2014-04-04 Thread Richard Gerd Kuesters

hi all!

i have a question about sqlalchemy and database design.

i'm developing an app, where each client may receive an alert about the 
total space usage of their data (files and database), so, using 
postgresql, i can get them (data usage size) using a different 
tablespace, database or schema, if i'm not wrong. given these premises, 
which is the best way to design my database using sqlalchemy, having in 
mind that I need also to integrate the client databases to the core 
database?


my best regards,
richard.

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


  1   2   >