[sqlalchemy] Re: Elixir 0.6.1 released!

2008-08-19 Thread Jorge Vargas

On Mon, Aug 18, 2008 at 11:37 PM, Jose Galvez [EMAIL PROTECTED] wrote:

 I'm not trying to be an ass, but what are the advantages to using Elixer

well you did sound like one :)

the first thing is that declarative is very new to SA (0.4.something,
and only mainstream in 0.5), while elixir has been around since
SA0.2(?)
next elixir is more featurefull than declarative, for instance it
provides you the ability to build custom relationships [1] there was a
really nice example somewhere but I can't find it, maybe it's on the
video.
the other nice feature is giving you a more OOP-ish api, with elixir
you can almost forget you are storing to tables.
last but not least, you have some nice magic that will take care of your tables
Also I believe there is some subclassing/inheritance goodies

That said I'm not the best person to answer this because I'm not a
heavy elixir user, I just wanted to point out it has a purpose, and if
it seems to overlap with SA is because something new was develop and
not the other way around. In fact declarative is an extension
distributed with SA, not a core feature and it was added so people
(including me) stop complaining about how verbose simple projects
where [2], on the other hand elixir is an implementation of Active
Record and beyond.

[1] http://elixir.ematia.de/apidocs/elixir.relationships.html
[2] 
http://groups.google.com/group/sqlalchemy/browse_thread/thread/817097f376fc808b/2e9ac8e83df54090


 Gaetan de Menten wrote:
 I am very pleased to announce that version 0.6.1 of Elixir
 (http://elixir.ematia.de) is now available. As always, feedback is
 very welcome, preferably on Elixir mailing list.

 This is a minor release featuring some bug fixes (one of them to
 handle a late rename in SQLAlchemy's 0.5 beta cycle), a new, slighty
 nicer, syntax for providing custom arguments to the column(s) needed
 for ManyToOne relationships and some exception messages improvements.

 The full list of changes can be seen at:
 http://elixir.ematia.de/trac/browser/elixir/tags/0.6.1/CHANGES

 What is Elixir?
 -

 Elixir is a declarative layer on top of the SQLAlchemy library. It is
 a fairly thin wrapper, which provides the ability to create simple
 Python classes that map directly to relational database tables (this
 pattern is often referred to as the Active Record design pattern),
 providing many of the benefits of traditional databases without losing
 the convenience of Python objects.

 Elixir is intended to replace the ActiveMapper SQLAlchemy extension,
 and the TurboEntity project but does not intend to replace
 SQLAlchemy's core features, and instead focuses on providing a simpler
 syntax for defining model objects when you do not need the full
 expressiveness of SQLAlchemy's manual mapper definitions.

 Mailing list
 

 http://groups.google.com/group/sqlelixir/about



 


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



[sqlalchemy] Re: Multiple Foreign Keys

2008-08-19 Thread Ally

Yep, that was exactly what I needed! I've just ordered the book so
hopefully I won't  end up struggling on the little things like this
again! Thanks for your help, much appreciated!

Ally


On Aug 18, 11:30 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 On Aug 18, 12:30 pm, Ally [EMAIL PROTECTED] wrote:



  Hi all,

  I’m fairly new to DBs and SQA and I’m having a few issues with
  multiple foreign keys. Essentially, I have a “Character” table with
  Character IDs and their associated name, and a Stats table, with
  containing data about various events, with two separate columns both
  with FKs to the Character ID table.

  These tables are stored in on my HDD relected at runtime, using the
  Table('Character', meta, autoload=True) format. My problems arise
  whenever I try and join these tables, I keep getting an error similar
  to this:

  “Can't determine join between Stats and 'Character'; tables have more
  than one foreign key constraint relationship between them. Please
  specify the 'onclause' of this join explicitly.”

  Fair enough, but when I try to do this, along the lines of:

  s =
  join(Stats,Character,DeathKill.c.OBj1_uid==Character.c.character_uid)

  I get:

  “sqlalchemy.exc.ArgumentError: Not an executable clause: [DeathKill]
  JOIN [Character] ON [DeathKill].killer_uid =
  [Character].character_uid”

  Any suggestions or pointers would be greatly appreciated! Sorry I
  can’t post more code just now as I not near my work PC!

 There's some context missing here that would help with an answer.   If
 you are just taking s and saying something along the lines of
 s.execute(), you'd need to first convert s into a select()
 construct using something like select([stats_table]).select_from(s).
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Self-referential mapping with Root ids/access

2008-08-19 Thread Michael Bayer


On Aug 18, 2008, at 8:41 PM, Tom wrote:


 I am trying to build a self-referential mapper like the basic_tree
 example, but would like to be able to access the root of any given
 TreeNode, much like the now depreciated and tricky byroot_tree.py.
 Before you tell me just to use the byroot_tree, zzzeek has already
 told me to work with eager loading and the byroot_tree has some issues
 loading currently.

 http://svn.sqlalchemy.org/sqlalchemy/tags/rel_0_5beta3/examples/adjacencytree/basic_tree.py
 http://svn.sqlalchemy.org/sqlalchemy/tags/rel_0_5beta3/examples/adjacencytree/byroot_tree.py

 So here is my issue: whenever I try to modify basic_tree to keep track
 of root_id's and map the root property I run into the following
 problem:

   ArgumentError: Could not determine join condition between parent/
 child tables on relation Node.children.
   Specify a 'primaryjoin' expression.  If this is a many-to-many
 relation, 'secondaryjoin' is needed as well.

 Note, this is even when I use a primaryjoin similar to the byroot
 example:

root=relation(Node, primaryjoin=trees.c.root_id==trees.c.id,
  remote_side=trees.c.id, lazy=None)

 Can anyone help me convert the eager loading example to allow root
 access? This is particularly important because every time I load a
 TreeNode, I want to be able to access the root, and I also want to be
 able to retrieve all the TreeNodes for a given root_id.


its just like the byroot_tree

mapper(TreeNode, trees, properties={
 'children': relation(TreeNode, cascade=all,
  backref=backref(parent,  
remote_side=[trees.c.id]),
   
collection_class=attribute_mapped_collection('name'),
  lazy=False, join_depth=3,
  primaryjoin=trees.c.parent_id==trees.c.id
  ),
 'root':relation(TreeNode,  
primaryjoin=trees.c.root_id==trees.c.id, remote_side=trees.c.id)

  })

You'd have to use part of byroot_tree's MapperExtension to have  
root_id populated upon flush().  And as I've said, the append_result  
part would work more nicely if you only used it on a per-query basis  
using query.options(extension(MyExt()), so that it doesnt get in the  
way for queries which don't want specialized append_result() behavior.





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



[sqlalchemy] DateTime Column as Python time tuple.

2008-08-19 Thread Heston James - Cold Beans
Hello Guys,

 

I'm looking to send an object from SQLAlchemy across a ZSI web service as a
complex type. To do this ZSI requires that datetime's in the objects be in
Python Time Tuples as documented in the 'time' module.

 

It looks as if by default SQLAlchemy uses datetime.datetime objects for
columns defined like: 

 

created = Column(DateTime, default=func.now())

 

Is there any way in which I can configure SQLAlchemy to return me time
tuples instead? Or perhaps a cheeky way I can convert from datetime.datetime
to time.time?

 

Cheers all,

 

Heston


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



[sqlalchemy] Re: Elixir 0.6.1 released!

2008-08-19 Thread Jose Galvez
Thanks for the info, I guess I didn't realize declarative was added so 
recently, its been a while since I actually looked at the SA docs (which 
is where I found it).  But you do make some good points about Elixer, 
I'll have to give it another look, because I do find the way that SA 
defines relationships to be difficult at times
Jose

Jorge Vargas wrote:
 On Mon, Aug 18, 2008 at 11:37 PM, Jose Galvez [EMAIL PROTECTED] wrote:
   
 I'm not trying to be an ass, but what are the advantages to using Elixer
 

 well you did sound like one :)

 the first thing is that declarative is very new to SA (0.4.something,
 and only mainstream in 0.5), while elixir has been around since
 SA0.2(?)
 next elixir is more featurefull than declarative, for instance it
 provides you the ability to build custom relationships [1] there was a
 really nice example somewhere but I can't find it, maybe it's on the
 video.
 the other nice feature is giving you a more OOP-ish api, with elixir
 you can almost forget you are storing to tables.
 last but not least, you have some nice magic that will take care of your 
 tables
 Also I believe there is some subclassing/inheritance goodies

 That said I'm not the best person to answer this because I'm not a
 heavy elixir user, I just wanted to point out it has a purpose, and if
 it seems to overlap with SA is because something new was develop and
 not the other way around. In fact declarative is an extension
 distributed with SA, not a core feature and it was added so people
 (including me) stop complaining about how verbose simple projects
 where [2], on the other hand elixir is an implementation of Active
 Record and beyond.

 [1] http://elixir.ematia.de/apidocs/elixir.relationships.html
 [2] 
 http://groups.google.com/group/sqlalchemy/browse_thread/thread/817097f376fc808b/2e9ac8e83df54090

   
 Gaetan de Menten wrote:
 
 I am very pleased to announce that version 0.6.1 of Elixir
 (http://elixir.ematia.de) is now available. As always, feedback is
 very welcome, preferably on Elixir mailing list.

 This is a minor release featuring some bug fixes (one of them to
 handle a late rename in SQLAlchemy's 0.5 beta cycle), a new, slighty
 nicer, syntax for providing custom arguments to the column(s) needed
 for ManyToOne relationships and some exception messages improvements.

 The full list of changes can be seen at:
 http://elixir.ematia.de/trac/browser/elixir/tags/0.6.1/CHANGES

 What is Elixir?
 -

 Elixir is a declarative layer on top of the SQLAlchemy library. It is
 a fairly thin wrapper, which provides the ability to create simple
 Python classes that map directly to relational database tables (this
 pattern is often referred to as the Active Record design pattern),
 providing many of the benefits of traditional databases without losing
 the convenience of Python objects.

 Elixir is intended to replace the ActiveMapper SQLAlchemy extension,
 and the TurboEntity project but does not intend to replace
 SQLAlchemy's core features, and instead focuses on providing a simpler
 syntax for defining model objects when you do not need the full
 expressiveness of SQLAlchemy's manual mapper definitions.

 Mailing list
 

 http://groups.google.com/group/sqlelixir/about


   

 

   

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



[sqlalchemy] Creating Oracle Triggers on Table Create

2008-08-19 Thread Gerrat

We have an oracle database, and all of our tables have auto-generating
id's on the primary key via a trigger that looks like :
-
CREATE OR REPLACE TRIGGER SCHEMA.some_table_rid
BEFORE INSERT OR UPDATE OF rid ON some_table
FOR EACH ROW
BEGIN
  IF UPDATING
  THEN
:new.rid := :old.rid;
  END IF;
  IF INSERTING
  THEN
IF :new.rid = 0
  THEN
  SELECT some_table_rid.NEXTVAL INTO :new.rid FROM dual;
ELSE
  DECLARE
num1 number(12);
  BEGIN
SELECT last_number INTO num1 FROM USER_SEQUENCES WHERE
SEQUENCE_NAME = 'SOME_TABLE_RID';
IF num1 = :new.rid
THEN
  LOOP
SELECT some_table_rid.NEXTVAL INTO num1 FROM dual;
EXIT WHEN num1 = :new.rid;
  END LOOP;
END IF;
  END;
END IF;
  END IF;
END;
-
This allows any external tool (like SQL Alchemy) to control primary
key generation via the sequence, but still allows the next id to be
inserted automatically by just inserting a 0 into the table for the
primary key

I'd like a similiar trigger created on every table create that
included a Sequence as part of a primary_key col.

Is there a way to easily hook into the table creation mechanism so
that whenever a Sequence was specified as part of a Column definition,
a similiar trigger could be inserted (substituting some names
obviously)?  I know I can manually issue the DDL after-the-fact for
each table create, but would prefer it be more implicit.

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



[sqlalchemy] Re: Creating Oracle Triggers on Table Create

2008-08-19 Thread Michael Bayer


On Aug 19, 2008, at 1:59 PM, Gerrat wrote:


 Is there a way to easily hook into the table creation mechanism so
 that whenever a Sequence was specified as part of a Column definition,
 a similiar trigger could be inserted (substituting some names
 obviously)?  I know I can manually issue the DDL after-the-fact for
 each table create, but would prefer it be more implicit.


I'm assuming that you mean you're already familiar with the DDL()  
construct, which is documented at:

http://www.sqlalchemy.org/docs/05/sqlalchemy_schema.html#docstrings_sqlalchemy.schema_DDL

So the next step is to create your own Table function along the lines  
of:

from sqlalchemy.schema import Table as _Table, Sequence, DDL

def Table(name, meta, *args, **kw):
t = _Table(name, meta, *args, **kw)
for c in t.c:
if c.default and isinstance(c.default, Sequence):
DDL(your per-sequence DDL 
here).execute_at('after-create', t)
return t




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



[sqlalchemy] Re: Creating Oracle Triggers on Table Create

2008-08-19 Thread Gerrat



On Aug 19, 2:11 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 On Aug 19, 2008, at 1:59 PM, Gerrat wrote:



  Is there a way to easily hook into the table creation mechanism so
  that whenever a Sequence was specified as part of a Column definition,
  a similiar trigger could be inserted (substituting some names
  obviously)?  I know I can manually issue the DDL after-the-fact for
  each table create, but would prefer it be more implicit.

 I'm assuming that you mean you're already familiar with the DDL()  
 construct, which is documented at:

 http://www.sqlalchemy.org/docs/05/sqlalchemy_schema.html#docstrings_s...

 So the next step is to create your own Table function along the lines  
 of:

 from sqlalchemy.schema import Table as _Table, Sequence, DDL

 def Table(name, meta, *args, **kw):
         t = _Table(name, meta, *args, **kw)
         for c in t.c:
                 if c.default and isinstance(c.default, Sequence):
                         DDL(your per-sequence DDL 
 here).execute_at('after-create', t)
         return t


Thanks for the super-quick response, Michael.
That's exactly what I was looking for!

...not sure where my head was at...didn't think of just browsing the
sources to look at the Table class.  Pretty straight forward - thanks
again!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] declarative

2008-08-19 Thread Jose Galvez

What is the proposed stability of declarative functions which I guess 
are pretty new.  From what I've read so far I really like it and was 
thinking of using it, but was just wondering what the long turn outlook 
for it looked like?  After doing some reading on the new release of 
Elixir, Elixir looks like a mich simplier and more feature complete then 
declarative, but It does not look like Elixir works with a legacy 
databse (but I'm still looking into that) so I was wondering about 
declarative's long term stability. 

Thanks Jose

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



[sqlalchemy] Re: declarative

2008-08-19 Thread Jose Galvez

I take it back about Elixir and legacy databases, it seems to work with 
them just as easy as sqlalchemy does.  I'll have to look much closer at 
Elixir
Jose

Jose Galvez wrote:
 What is the proposed stability of declarative functions which I guess 
 are pretty new.  From what I've read so far I really like it and was 
 thinking of using it, but was just wondering what the long turn outlook 
 for it looked like?  After doing some reading on the new release of 
 Elixir, Elixir looks like a mich simplier and more feature complete then 
 declarative, but It does not look like Elixir works with a legacy 
 databse (but I'm still looking into that) so I was wondering about 
 declarative's long term stability. 

 Thanks Jose

 

   

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



[sqlalchemy] Re: declarative

2008-08-19 Thread Michael Bayer


On Aug 19, 2008, at 2:43 PM, Jose Galvez wrote:


 What is the proposed stability of declarative functions which I guess
 are pretty new.  From what I've read so far I really like it and was
 thinking of using it, but was just wondering what the long turn  
 outlook
 for it looked like?  After doing some reading on the new release of
 Elixir, Elixir looks like a mich simplier and more feature complete  
 then
 declarative, but It does not look like Elixir works with a legacy
 databse (but I'm still looking into that) so I was wondering about
 declarative's long term stability.

declarative is intended to be a lot simpler than Elixir, so thats  
funny you see it the other way around.   I'm using it (declarative) on  
a production project and so are many others, and forms the basis of  
the object-relational plugin for Grok.  Its fully stable since it is  
using the same SQLAlchemy constructs that regular mapper() and Table  
calls do.


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



[sqlalchemy] error while accessing row in create_instance

2008-08-19 Thread naktinis

In MapperExtension's method create_instance(self, mapper,
selectcontext, row, class_) I try to call row.has_key('some_key') but
I get:

AttributeError: 'str' object has no attribute 'proxy_set'

This is in version 0.4.6. It worked fine in 0.4.2p3.

What could be the problem?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Creating Oracle Triggers on Table Create

2008-08-19 Thread Michael Bayer


On Aug 19, 2008, at 5:08 PM, Gerrat wrote:


 This doesn't quite work:

 the DDL class (well, the method '_TextClause' in the module
 'expression' actually) parses out any sql containing a ':' (colon) as
 if it were a bind variable.
 Althouth the documentation says: SQL bind parameters are not
 available in DDL statements, it still looks for anything that
 resembles a bind variable, then binds these variables to the None
 value.  Sqlalchemy then sends these invalid bind variables off to the
 database with the sql.

 I get an error back from the database with my trigger sql text,
 followed by {'new':None, 'old':None}.
 The special keywords in Oracle ':new', and ':old', aren't actually
 bind variables when used in PL/SQL.

 Any ideas for a workaround?
 I'm using version 0.5.0beta3-py2.5

the colon can be escaped using a backslash, i.e. \: .

Maybe it would be a good idea for DDL() to construct _Text() with a  
flag to disable bind parameter matching.


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