[sqlalchemy] Re: Materialized Path for SQLAlchemy Declarative Base

2009-08-13 Thread allen.fowler
On Aug 13, 2:37 pm, Anton Gritsay gene...@angri.ru wrote: Hi, Allen! You can use something like this (yeah, I know that it isn't declarative in any way):     class Node(Base):         __tablename__ = 'node'         id = Column(Integer, primary_key=True)         parent_id =

[sqlalchemy] Re: VIEW alternative in SQLAlchemy

2009-08-09 Thread allen.fowler
On Aug 7, 11:45 am, Michael Bayer mike...@zzzcomputing.com wrote: AF wrote: Hello, I have a table of records in the database that I want to run read queries against, but I do want to include all of them in the search. (There are a couple of filtering parameters to exclude records

[sqlalchemy] Re: Materialized Path for SQLAlchemy Declarative Base

2009-08-09 Thread allen.fowler
Werner, On Aug 7, 12:36 pm, werner wbru...@free.fr wrote: Allen, allen.fowler wrote: On Aug 6, 6:54 pm, AF allen.fow...@yahoo.com wrote: Hello all, Has anyone here used the sqlamp: Materialized Path for SQLAlchemy library? I am wondering: 1) Does it seem to work well? 2

[sqlalchemy] Re: VIEW alternative in SQLAlchemy

2009-08-09 Thread allen.fowler
On Aug 9, 1:42 pm, Michael Bayer mike...@zzzcomputing.com wrote: On Aug 9, 2009, at 1:24 PM, allen.fowler wrote: So, just to clarify: At this point in time, can SQLAlchemy be used to define and query simple VIEWs in a database agnostic manner? And if not, is this a feature

[sqlalchemy] Re: Materialized Path for SQLAlchemy Declarative Base

2009-08-07 Thread allen.fowler
On Aug 6, 6:54 pm, AF allen.fow...@yahoo.com wrote: Hello all, Has anyone here used the sqlamp: Materialized Path for SQLAlchemy library? I am wondering: 1) Does it seem to work well? 2) Did you use it with Declarative Base, and if so, how did you configure it? Anybody?

[sqlalchemy] Re: VIEW alternative in SQLAlchemy

2009-08-07 Thread allen.fowler
On Aug 7, 11:45 am, Michael Bayer mike...@zzzcomputing.com wrote: AF wrote: Hello, I have a table of records in the database that I want to run read queries against, but I do want to include all of them in the search. (There are a couple of filtering parameters to exclude records

[sqlalchemy] Re: VIEW alternative in SQLAlchemy

2009-08-07 Thread allen.fowler
... To clarify: I am using SQLAlchemy's Declarative Base to fully define and create my database. For instance, there is a simple class/table Records, and I would like to define a class CurrentRecords that is implemented in the database as a view on Records. In this way, I can

[sqlalchemy] Re: Relation w/ declarative

2009-08-06 Thread allen.fowler
On Aug 6, 3:30 am, werner wbru...@free.fr wrote: I never do this, i.e. I assign like this add = Address() add.email_address = 'an email address' In what way is the Address object expected to be instantiated such that it receives the correct user id? You just do this and SA will take

[sqlalchemy] Re: Relation w/ declarative

2009-08-06 Thread allen.fowler
On Aug 6, 4:59 am, Wichert Akkerman wich...@wiggy.net wrote: On 8/6/09 09:30 , werner wrote: IIRC correctly the __init__ section is only needed if you want to do: add = Address('an email address') I never do this, i.e. I assign like this add = Address() add.email_address = 'an

[sqlalchemy] Re: Suggestions for db connect string configuration?

2009-08-06 Thread allen.fowler
On Aug 5, 6:29 pm, AF allen.fow...@yahoo.com wrote: Hello, Where do you folks recommend storing the database connection string in my application.  Clearly not in the same file with my declaratively defined model objects. And more generally, how do you recommend laying out an SQLAlchemy

[sqlalchemy] Re: Declarative Base: remote_side single_parent

2009-08-06 Thread allen.fowler
On Aug 6, 4:05 pm, Michael Bayer mike...@zzzcomputing.com wrote: allen.fowler wrote: I tried: children = relation(Node, backref=backref(parent, remote_side=nodes.id)) got it to work with: remote_side=[id] But: 1) Why is remote_side a list? in this case you could just say

[sqlalchemy] Re: Hierarchical data: Get all (sub-) children? Parents?

2009-08-05 Thread allen.fowler
On Jul 28, 12:17 pm, David Gardner dgard...@creatureshop.com wrote: Just thought I would toss in my 2-cents here, since I have lots of hierarchical data and have at one time or another used most of the below methods. Choice #1 is the option that I have found that works the best. I Use a

[sqlalchemy] Re: SQLAlchemy as a FIFO buffer?

2009-06-30 Thread allen.fowler
On Jun 30, 11:25 am, Didip Kerabat did...@gmail.com wrote: If you are open to non RDBMS solution, sounds like what you need is message queue system. At work, we use RabbitMQ (memory-only) and have been quite happy with it. SecondLife posted their discovery about MQ

[sqlalchemy] Re: SQLAlchemy as a FIFO buffer?

2009-06-30 Thread allen.fowler
I've attached a proof of concept for how I've approached the homegrown version of this in the past.   a jobs table has two update passes - one to atomically mark jobs as in progress by a certain procid, then the transaction is released so that other processes can theoretically work on other

[sqlalchemy] Re: SQLAlchemy as a FIFO buffer?

2009-06-29 Thread allen.fowler
I have several CGI and cron scripts and that I would like coordinate via a First In / First Out style buffer.    That is, some processes are adding work units, and some take the oldest and start work on them. Since I need the queue to both survive system crashes and provide an audit

[sqlalchemy] Re: Validators: Define at table / mapper level ?

2009-06-23 Thread allen.fowler
If you have mapper definitions separate from classes, theres nothing stopping you from adding attributes to the class over there, i.e. mapper(MyClass, mytable) MyClass.foo = some_validation_decorator(MyClass.foo) Personally I wouldn't bother (then again I use declarative for everything

[sqlalchemy] Re: filtered or computed version of an existing relation?

2009-06-21 Thread allen.fowler
Thank you, Michael. On Jun 18, 9:41 am, Michael Bayer mike...@zzzcomputing.com wrote: On Jun 18, 2009, at 2:27 AM, AF wrote: OK, next question. Well... two related questions.  :) 1)  In general, inside an object's method def, where I am doing arbitrary calculations, how can I get

[sqlalchemy] Re: Random value for field by default?

2009-06-21 Thread allen.fowler
OK, never mind... I solved it. The default = random.randrange(1000,1) code was happily taking the static return value. Duh. I changed it to: default = lambda: random.Random().randrange(2000,8000) I dunno if the extra Random() is needed, but it can't hurt, right? On Jun 21, 4:32 pm,

[sqlalchemy] Re: Random value for field by default?

2009-06-21 Thread allen.fowler
default = lambda: random.randrange(1000,1) Seems we crossed in the interwebs.. :) Is it safe to do this, or do you need to do default = lambda: random.Random()randrange(1000,1) ? I ask since I have several tables that this needs to be applied to. Thank you

[sqlalchemy] Re: relation error?

2009-06-17 Thread allen.fowler
3) Can this relation's objects be made read-only?  That is: u.room = new_room would work, but this would not:  u.room.name = 'kitchen' To clarify the question: Can this objects seen via this relation be made read-only? That is: u.room = a_room u.room = a_new_room ...would work fine. And

[sqlalchemy] Re: relation error?

2009-06-17 Thread allen.fowler
you can, you can use a validator that rejects all changes, or if you're brave you can create a custom __setattribute__ method that brokers all attribute setter access.   the former is in the SQLA mapping docs the latter is part of Python. Thank you. Interesting seems a bit of a round

[sqlalchemy] Re: Can I coerce strings into Unicode?

2009-06-12 Thread allen.fowler
Anybody? On Jun 4, 1:13 am, AF allen.fow...@yahoo.com wrote: Hello, I'm using sqlite and convert_unicode = True on the engine. How can I force coerce string based object attributes in to unicode? (I had thought convert_unicode = True would do this) Here is what I am seeing... Setup

[sqlalchemy] Re: Can I coerce strings into Unicode?

2009-06-12 Thread allen.fowler
On Jun 12, 6:00 am, Gunnlaugur Briem gunnlau...@gmail.com wrote: The engine's conversion to unicode doesn't happen when you assign the property, it happens when the underlying database operation is committed, and arrives in the python object's property only after roundtripping through the