Re: [sqlalchemy] bug in sqllite dialect?

2010-03-05 Thread Chris Withers

Michael Bayer wrote:

Has anyone (hi, list, talking to you too!) already done a custom type
for this specific problem?


people do custom types for all sorts of things.  In the case of the
Decimal here I'd likely subclass sqlalchemy.databases.sqlite.SLNumeric
which should ensure that your own bind_processor() and result_processor()
methods can be called. 


Okay, but how do I make sure this is only used when sqlite this the engine?

Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
- http://www.simplistix.co.uk

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] case sensitive Unicode and String columns

2010-03-05 Thread Chris Withers

Michael Bayer wrote:

How do I do this?

I think all databases that SQLAlchemy supports (in fact, likely all
databases in use today) support case-sensitive strings by default, so
I don't know if this something you'll need to worry about in your
code. Maybe I am misunderstanding what you are trying to do?


hes likely referring to case-sensitive collation support.

Build a TypeDecorator and intercept the dialect in the
process_bind_param() method.


This sounds pretty heavyweight unless I'm misunderstanding...

I was hoping for something like:

class MyModel(Base):
  __tablename__ = 'foo'
  ...
  myfield = Column(String(50,case_sensitive=True))

I know this doesn't exist, but I was hoping either it was easy to 
implement or a field type could be created that did the right thing no 
matter what the back end was...


Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
- http://www.simplistix.co.uk

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Re: [PROPOSE] Integrate migration support in SQLAlchemy

2010-03-05 Thread Manlio Perillo
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Lele Gaifax ha scritto:
 Manlio Perillo manlio.peri...@gmail.com writes:
 
 Michael Bayer ha scritto:
 Similarly, the concept of a version as an integer number is not really
 flexible enough - 
 The idea was to keep it simple.
 
 IMHE, there's no such a beast!
 
 I would like to investigate the creation of migration
 scripts between branches as well.
 The version can then be a string, but it needs to sortable (see
 setuptool as an example).

 The mechanism of schema versioning is
 not at all something that belongs in SQLAlchemy core.
 
 I'm all with Michael here. Sure, for *very* simple projects, it'd be
 nice to have a mechanism that spits out the needed statements, but at
 least in my experience (going from very little to moderately big and
 complex schemas), maintaining an upgradable path is something better
 done at another level. Some steps needs an hand-crafted solution, that
 maybe involve dropping/recreating dependencies, temporary data-space to
 upgrade existing contents and so on.
 

I think you have misunderstod my propose.
The propose was not to to spits out the needed statements, but to call
user defined functions for a migration path from version x to version y.

That's why it should be kept simple: different users need different
features, and this is up to high level applications that are built on
top of the base support to migration.

You can have very simple upgrade functions that use SQLAlchemy builtin
DDL, or you can have complex scripts with hand written SQL.

I'm interested in a reusable core.
The more is simple, the more is reusable (unless it is too simple, and
thus useless)


 [...]


Regards  Manlio
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkuQ/UMACgkQscQJ24LbaUSxxwCePPm9N6e+oZAqf/Zwo/kt5f9M
cOsAn2UzpxfSmg3W+lOWuWADds60D/Xs
=B6HL
-END PGP SIGNATURE-

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: Getting access to the object being updated inside a default callable?

2010-03-05 Thread Oliver Beattie
Sorry to bug… I imagine there is no way of doing this, but would be
good to know for sure. If not, this would be really useful
functionality. For instance, I might want to populate one column based
on the contents of one of more other columns.

On 12 Jan, 11:21, Oliver Beattie oli...@obeattie.com wrote:
 Hi there,

 I feel like I'm perhaps missing something, but I wonder if there's any
 way to access the object being updated inside a ColumnDefault? More
 specifically, if I have a… let's call it DBObject (using declarative)
 which has a callable as its default, is there any way to access that
 DBObject instance inside the default function? I see it gets passed an
 ExecutionContext instance, but I don't see a way to get the object
 from there :\

 If there's a way to do this, it would help me a lot :)

 Thanks,
 Oliver

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] three primary keys on association object

2010-03-05 Thread Sebastian Elsner

Hello,

I have an association object declaratively with three primary keys, but on  
insert, the first (id) is not autoincremented. Please see test the code  
below





from sqlalchemy import create_engine, Column,Integer, String, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker,relation, backref

engine = create_engine(sqlite:///:memory:,echo=False)
Base=declarative_base()


class Child(Base):

__tablename__=Child

id=Column(Integer,primary_key=True)

class Association(Base):

__tablename__=Association

id=Column(Integer,primary_key=True)

parent_id=Column(Integer,ForeignKey(Parent.id),primary_key=True)
child_id=Column(Integer,ForeignKey(Child.id),primary_key=True)

child=relation(Child,backref=parents)

data=Column(String(32))

def __init__(self):
self.data=some text

class Parent(Base):
__tablename__=Parent

id=Column(Integer, primary_key=True)

children=relation(Association,backref=backref(parent))

Base.metadata.create_all(engine)
Session=sessionmaker(bind=engine)
session = Session()

p=Parent()
a=Association()
a.child=Child()
p.children.append(a)

session.add(p)
session.query(Parent).all()


I need the id for another 1:n realtion with the association object. What  
am I missing here?



Thanks

Sebastian

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] bug in sqllite dialect?

2010-03-05 Thread Michael Bayer
Chris Withers wrote:
 Michael Bayer wrote:
 Has anyone (hi, list, talking to you too!) already done a custom type
 for this specific problem?

 people do custom types for all sorts of things.  In the case of the
 Decimal here I'd likely subclass sqlalchemy.databases.sqlite.SLNumeric
 which should ensure that your own bind_processor() and
 result_processor()
 methods can be called.

 Okay, but how do I make sure this is only used when sqlite this the
 engine?

You can use a TypeDecorator to switch between implementations.  I had a
plan to add a pre-fab type for this to core that allows easy switching of
implementations.



 Chris

 --
 Simplistix - Content Management, Batch Processing  Python Consulting
  - http://www.simplistix.co.uk

 --
 You received this message because you are subscribed to the Google Groups
 sqlalchemy group.
 To post to this group, send email to sqlalch...@googlegroups.com.
 To unsubscribe from this group, send email to
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] case sensitive Unicode and String columns

2010-03-05 Thread Michael Bayer
Chris Withers wrote:
 Michael Bayer wrote:
 How do I do this?
 I think all databases that SQLAlchemy supports (in fact, likely all
 databases in use today) support case-sensitive strings by default, so
 I don't know if this something you'll need to worry about in your
 code. Maybe I am misunderstanding what you are trying to do?

 hes likely referring to case-sensitive collation support.

 Build a TypeDecorator and intercept the dialect in the
 process_bind_param() method.

 This sounds pretty heavyweight unless I'm misunderstanding...

 I was hoping for something like:

 class MyModel(Base):
__tablename__ = 'foo'
...
myfield = Column(String(50,case_sensitive=True))

 I know this doesn't exist, but I was hoping either it was easy to
 implement or a field type could be created that did the right thing no
 matter what the back end was...

the MySQL string types support MySQL's collation flags so you can get
close to it for at least that platform.  But then you aren't platform
independent.

Not sure why you're so averse to creating types.   The interface could not
be simpler.   When i used Hibernate, there was no option - you had to make
types for pretty much anything non-trivial (like oracle BLOBs and such).




 Chris

 --
 Simplistix - Content Management, Batch Processing  Python Consulting
  - http://www.simplistix.co.uk

 --
 You received this message because you are subscribed to the Google Groups
 sqlalchemy group.
 To post to this group, send email to sqlalch...@googlegroups.com.
 To unsubscribe from this group, send email to
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Re: Getting access to the object being updated inside a default callable?

2010-03-05 Thread Michael Bayer
Oliver Beattie wrote:
 Sorry to bug… I imagine there is no way of doing this, but would be
 good to know for sure. If not, this would be really useful
 functionality. For instance, I might want to populate one column based
 on the contents of one of more other columns.

 On 12 Jan, 11:21, Oliver Beattie oli...@obeattie.com wrote:
 Hi there,

 I feel like I'm perhaps missing something, but I wonder if there's any
 way to access the object being updated inside a ColumnDefault? More
 specifically, if I have a… let's call it DBObject (using declarative)
 which has a callable as its default, is there any way to access that
 DBObject instance inside the default function? I see it gets passed an
 ExecutionContext instance, but I don't see a way to get the object
 from there :\

 If there's a way to do this, it would help me a lot :)

The executioncontext has all the parameters for the whole statement, you
can use those.  But the ORM object is not available at that level.   You
might want to use MapperExtension.before_insert() if you need ORM-level
awareness.




 Thanks,
 Oliver

 --
 You received this message because you are subscribed to the Google Groups
 sqlalchemy group.
 To post to this group, send email to sqlalch...@googlegroups.com.
 To unsubscribe from this group, send email to
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] three primary keys on association object

2010-03-05 Thread Michael Bayer
Sebastian Elsner wrote:
 Hello,

 I have an association object declaratively with three primary keys, but on
 insert, the first (id) is not autoincremented. Please see test the code
 below

known sqlite limitation, described at

http://www.sqlalchemy.org/docs/reference/dialects/sqlite.html?highlight=sqlite#auto-incrementing-beahvior





  from sqlalchemy import create_engine, Column,Integer, String, ForeignKey
  from sqlalchemy.ext.declarative import declarative_base
  from sqlalchemy.orm import sessionmaker,relation, backref

 engine = create_engine(sqlite:///:memory:,echo=False)
 Base=declarative_base()


 class Child(Base):

  __tablename__=Child

  id=Column(Integer,primary_key=True)

 class Association(Base):

  __tablename__=Association

  id=Column(Integer,primary_key=True)

  parent_id=Column(Integer,ForeignKey(Parent.id),primary_key=True)
  child_id=Column(Integer,ForeignKey(Child.id),primary_key=True)

  child=relation(Child,backref=parents)

  data=Column(String(32))

  def __init__(self):
  self.data=some text

 class Parent(Base):
  __tablename__=Parent

  id=Column(Integer, primary_key=True)

  children=relation(Association,backref=backref(parent))

 Base.metadata.create_all(engine)
 Session=sessionmaker(bind=engine)
 session = Session()

 p=Parent()
 a=Association()
 a.child=Child()
 p.children.append(a)

 session.add(p)
 session.query(Parent).all()


 I need the id for another 1:n realtion with the association object. What
 am I missing here?


 Thanks

 Sebastian

 --
 You received this message because you are subscribed to the Google Groups
 sqlalchemy group.
 To post to this group, send email to sqlalch...@googlegroups.com.
 To unsubscribe from this group, send email to
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] three primary keys on association object

2010-03-05 Thread Michael Bayer
Michael Bayer wrote:
 Sebastian Elsner wrote:
 Hello,

 I have an association object declaratively with three primary keys, but
 on
 insert, the first (id) is not autoincremented. Please see test the code
 below

 known sqlite limitation, described at

 http://www.sqlalchemy.org/docs/reference/dialects/sqlite.html?highlight=sqlite#auto-incrementing-beahvior

spelling correction:

http://www.sqlalchemy.org/docs/reference/dialects/sqlite.html?highlight=sqlite#auto-incrementing-behavior








  from sqlalchemy import create_engine, Column,Integer, String,
 ForeignKey
  from sqlalchemy.ext.declarative import declarative_base
  from sqlalchemy.orm import sessionmaker,relation, backref

 engine = create_engine(sqlite:///:memory:,echo=False)
 Base=declarative_base()


 class Child(Base):

  __tablename__=Child

  id=Column(Integer,primary_key=True)

 class Association(Base):

  __tablename__=Association

  id=Column(Integer,primary_key=True)

  parent_id=Column(Integer,ForeignKey(Parent.id),primary_key=True)
  child_id=Column(Integer,ForeignKey(Child.id),primary_key=True)

  child=relation(Child,backref=parents)

  data=Column(String(32))

  def __init__(self):
  self.data=some text

 class Parent(Base):
  __tablename__=Parent

  id=Column(Integer, primary_key=True)

  children=relation(Association,backref=backref(parent))

 Base.metadata.create_all(engine)
 Session=sessionmaker(bind=engine)
 session = Session()

 p=Parent()
 a=Association()
 a.child=Child()
 p.children.append(a)

 session.add(p)
 session.query(Parent).all()


 I need the id for another 1:n realtion with the association object. What
 am I missing here?


 Thanks

 Sebastian

 --
 You received this message because you are subscribed to the Google
 Groups
 sqlalchemy group.
 To post to this group, send email to sqlalch...@googlegroups.com.
 To unsubscribe from this group, send email to
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.



 --
 You received this message because you are subscribed to the Google Groups
 sqlalchemy group.
 To post to this group, send email to sqlalch...@googlegroups.com.
 To unsubscribe from this group, send email to
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] three primary keys on association object

2010-03-05 Thread Sebastian Elsner
Oh, thanks for the pointer. There's so much to read and learn being new to  
SQLAlchemy... Sorry for bugging.



On Fri, 05 Mar 2010 15:49:03 +0100, Michael Bayer  
mike...@zzzcomputing.com wrote:



Sebastian Elsner wrote:

Hello,

I have an association object declaratively with three primary keys, but  
on

insert, the first (id) is not autoincremented. Please see test the code
below


known sqlite limitation, described at

http://www.sqlalchemy.org/docs/reference/dialects/sqlite.html?highlight=sqlite#auto-incrementing-beahvior






 from sqlalchemy import create_engine, Column,Integer, String,  
ForeignKey

 from sqlalchemy.ext.declarative import declarative_base
 from sqlalchemy.orm import sessionmaker,relation, backref

engine = create_engine(sqlite:///:memory:,echo=False)
Base=declarative_base()


class Child(Base):

 __tablename__=Child

 id=Column(Integer,primary_key=True)

class Association(Base):

 __tablename__=Association

 id=Column(Integer,primary_key=True)

 parent_id=Column(Integer,ForeignKey(Parent.id),primary_key=True)
 child_id=Column(Integer,ForeignKey(Child.id),primary_key=True)

 child=relation(Child,backref=parents)

 data=Column(String(32))

 def __init__(self):
 self.data=some text

class Parent(Base):
 __tablename__=Parent

 id=Column(Integer, primary_key=True)

 children=relation(Association,backref=backref(parent))

Base.metadata.create_all(engine)
Session=sessionmaker(bind=engine)
session = Session()

p=Parent()
a=Association()
a.child=Child()
p.children.append(a)

session.add(p)
session.query(Parent).all()


I need the id for another 1:n realtion with the association object. What
am I missing here?


Thanks

Sebastian

--
You received this message because you are subscribed to the Google  
Groups

sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.







--
Sebastian Elsner-pipeline td   -   r i s e |  fx

t:  +49 30 20180300 sebast...@risefx.com
c:  +49 175 3365739   www.risefx.com

r i s e |  fx  GmbH
Schlesische Strasse 28 Aufgang B, 10997 Berlin
Geschäftsführer: Sven Pannicke, Robert Pinnow

Handelsregister Berlin HRB 106667 B

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: Getting access to the object being updated inside a default callable?

2010-03-05 Thread Oliver Beattie
Thanks for clarifying that. The MapperExtension is what I've been
using so far for this, just wondered if there was a way to do this
with column-level defaults. Now that I think about it though, the
current way probably does make more sense, since if the values are
dependent on outside influences, they cease to be column-level
defaults.

On Mar 5, 2:48 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 Oliver Beattie wrote:
  Sorry to bug I imagine there is no way of doing this, but would be
  good to know for sure. If not, this would be really useful
  functionality. For instance, I might want to populate one column based
  on the contents of one of more other columns.

  On 12 Jan, 11:21, Oliver Beattie oli...@obeattie.com wrote:
  Hi there,

  I feel like I'm perhaps missing something, but I wonder if there's any
  way to access the object being updated inside a ColumnDefault? More
  specifically, if I have a let's call it DBObject (using declarative)
  which has a callable as its default, is there any way to access that
  DBObject instance inside the default function? I see it gets passed an
  ExecutionContext instance, but I don't see a way to get the object
  from there :\

  If there's a way to do this, it would help me a lot :)

 The executioncontext has all the parameters for the whole statement, you
 can use those.  But the ORM object is not available at that level.   You
 might want to use MapperExtension.before_insert() if you need ORM-level
 awareness.





  Thanks,
  Oliver

  --
  You received this message because you are subscribed to the Google Groups
  sqlalchemy group.
  To post to this group, send email to sqlalch...@googlegroups.com.
  To unsubscribe from this group, send email to
  sqlalchemy+unsubscr...@googlegroups.com.
  For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] graph data structure with many edge types

2010-03-05 Thread JanW
I am trying to model graph data structure where nodes can be connected
by different types of edges.
For example, we could have 2 nodes represnting persons: Alice and
Bob and we could have 3 nodes representing projects: projectA,
projectB, projectC.
Alice is working on projectA and projectC.
Bob is working on projectB and projectC.
Alice is manager of projectA.
Bob is manager of projectB.

I would like to encode all this in 2 database tables:

Node table:
id  name
1   Alice
2   Bob
3   projectA
4   projectB
5   projectC

Edge table:
n1_id   n2_id   edge_type
1   3   working_on
1   5   working_on
2   4   working_on
2   5   working_on
1   3   manager_of
2   4   manager_of

(it would even by better to replace the edge_type by an edge_type_id
and move them to a separate table, but I would already be very happy
to get it to work like this)

and I would like to be able to access all this as a dictionary of
lists (or sets):
 alice = session.query(Node).filter_by(name=Alice).first()
 bob = session.query(Node).filter_by(name=Bob).first()

 alice.related['working_on']
[Node: 'projectA', Node: 'projectC', ]

 bob.related['working_on']
[Node: 'projectB', Node: 'projectC', ]

 alice.related['manager_of']
[Node: 'projectA', ]

 bob.related['manager_of']
[Node: 'projectB', ]

and adding stuff:
 alice.related['working_on'].append(Node(projectD))
 alice.related['working_on']
[Node: 'projectA', Node: 'projectC', Node: 'projectD', ]

I think this must be doable using the association_proxy in some way
(it's vaguely familiar to the Broker/Stock/Holding example in the
documentation, but now the extra value in the linking table (shares)
should be used as key in the dictionary) but I can't get it to work.
Could somebody give me an idea if this is at all possible and maybe a
push in the right direction?

Many thanks,

Jan.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] graph data structure with many edge types

2010-03-05 Thread Michael Bayer
JanW wrote:
 I am trying to model graph data structure where nodes can be connected
 by different types of edges.
 I would like to encode all this in 2 database tables:

 Node table:

 Edge table:


 I think this must be doable using the association_proxy in some way
 (it's vaguely familiar to the Broker/Stock/Holding example in the
 documentation, but now the extra value in the linking table (shares)
 should be used as key in the dictionary) but I can't get it to work.
 Could somebody give me an idea if this is at all possible and maybe a
 push in the right direction?

We have a similar example, minus the type part, at
http://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/examples/graphs/directed_graph.py
.

So here you'd additionally use
collection_class=sqlalchemy.orm.collections.attribute_mapped_collection('edge_type')
for the node-edge collections.   The association proxy can then eliminate
the edge traversal between node-node.





 Many thanks,

 Jan.

 --
 You received this message because you are subscribed to the Google Groups
 sqlalchemy group.
 To post to this group, send email to sqlalch...@googlegroups.com.
 To unsubscribe from this group, send email to
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: insert defaults

2010-03-05 Thread patrick
Well it's something between the two.  The instance variable
compressed will always be NULL when adding or updating an instance,
but I want it to infer a value from another instance variable.  When
inserting... the value of 'compressed' in the sql statement needs to
be the raw SQL string COMPRESS('%s') % instance.text.  It isn't
simply running it through a function... it's dynamically creating the
column value from the object's instance variables upon insert or
update.  MySQL has some funky compression function so the insert value
for the column has to be raw sql.

On Mar 4, 3:30 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 patrick wrote:
  Hey,
    I'm trying to create dynamic defaults for columns ala http://
 www.sqlalchemy.org/docs/metadata.html#context-sensitive-default-funct
  MySQL has COMPRESS and UNCOMPRESS functions that I'm trying to
  leverage.  I don't want to compress with python's zlib because I have
  legacy tables that were compressed using MySQL (which has a weird non-
  standard zip header and body), and I need to interface with them.
  Anyway, during an insert or update, I want to grab the 'text' variable
  from the instance object and insert it into the database like:
  COMPRESS(the text value).  Obviously context.current_parameters is
  not the appropriate object, but I can't figure out if it's possible to
  access the instance being inserted/updated.

 are you trying to create a *default* value for an INSERT/UPDATE when NULL
 would otherwise be passed, or are you trying to run all incoming/outgoing
 data through a SQL function ?  those are two completely separate topics.



  def compress_text(context):
      return COMPRESS('%s') % context.current_parameters['text']

  class Tree(BaseStruct, Base):
      __tablename__ = 'tree'
      __table_args__ = (
              {'autoload':True}
              )

      compressed =
  deferred(Column(Binary(),default=compress_text,default=compress_text,onupdate=compress_text))
      text =
  column_property(select([UNCOMPRESS(compressed)]),deferred=True)

  Is this possible with 0.5.7?

  --
  You received this message because you are subscribed to the Google Groups
  sqlalchemy group.
  To post to this group, send email to sqlalch...@googlegroups.com.
  To unsubscribe from this group, send email to
  sqlalchemy+unsubscr...@googlegroups.com.
  For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Re: insert defaults

2010-03-05 Thread Michael Bayer

On Mar 5, 2010, at 6:44 PM, patrick wrote:

 Well it's something between the two.  The instance variable
 compressed will always be NULL when adding or updating an instance,
 but I want it to infer a value from another instance variable.  When
 inserting... the value of 'compressed' in the sql statement needs to
 be the raw SQL string COMPRESS('%s') % instance.text.  It isn't
 simply running it through a function... it's dynamically creating the
 column value from the object's instance variables upon insert or
 update.  MySQL has some funky compression function so the insert value
 for the column has to be raw sql.


so do a before_insert() mapper extension and set the attribute as needed to 
func.compressed(instance.text).  Or do the same at the object level, i.e user 
sets myobject.foo, foo is a descriptor-enabled method which then sets 
myobject.bar = func.compressed(foo) or whatever.

the technique here is 
http://www.sqlalchemy.org/docs/session.html#embedding-sql-insert-update-expressions-into-a-flush
 .



 
 On Mar 4, 3:30 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 patrick wrote:
 Hey,
   I'm trying to create dynamic defaults for columns ala http://
 www.sqlalchemy.org/docs/metadata.html#context-sensitive-default-funct
 MySQL has COMPRESS and UNCOMPRESS functions that I'm trying to
 leverage.  I don't want to compress with python's zlib because I have
 legacy tables that were compressed using MySQL (which has a weird non-
 standard zip header and body), and I need to interface with them.
 Anyway, during an insert or update, I want to grab the 'text' variable
 from the instance object and insert it into the database like:
 COMPRESS(the text value).  Obviously context.current_parameters is
 not the appropriate object, but I can't figure out if it's possible to
 access the instance being inserted/updated.
 
 are you trying to create a *default* value for an INSERT/UPDATE when NULL
 would otherwise be passed, or are you trying to run all incoming/outgoing
 data through a SQL function ?  those are two completely separate topics.
 
 
 
 def compress_text(context):
 return COMPRESS('%s') % context.current_parameters['text']
 
 class Tree(BaseStruct, Base):
 __tablename__ = 'tree'
 __table_args__ = (
 {'autoload':True}
 )
 
 compressed =
 deferred(Column(Binary(),default=compress_text,default=compress_text,onupdate=compress_text))
 text =
 column_property(select([UNCOMPRESS(compressed)]),deferred=True)
 
 Is this possible with 0.5.7?
 
 --
 You received this message because you are subscribed to the Google Groups
 sqlalchemy group.
 To post to this group, send email to sqlalch...@googlegroups.com.
 To unsubscribe from this group, send email to
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To post to this group, send email to sqlalch...@googlegroups.com.
 To unsubscribe from this group, send email to 
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/sqlalchemy?hl=en.
 

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.