[sqlalchemy] Re: sqlalchemy object serialization / deserialization

2007-12-21 Thread Lele Gaifax

On Thu, 20 Dec 2007 20:45:46 -0500
Rick Morrison [EMAIL PROTECTED] wrote:

 Re-implementing pickle with a JSON storage format is going to be a
 huge job, and really won't give you anything that you don't already
 get from pickle

That's surely right: consider that Pickle is not simply a format,
but really a (little) specialized language able to reconstruct a
Python object, maintaining its relations with other objects in the
stream.

See this blog:

  http://peadrop.com/blog/2007/06/18/pickle-an-interesting-stack-language/

ciao, lele.
-- 
nickname: Lele Gaifax| Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas| comincerò ad aver paura di chi mi copia.
[EMAIL PROTECTED] | -- Fortunato Depero, 1929.

--~--~-~--~~~---~--~~
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] Readonly objects/protecting objects from modifications

2007-12-21 Thread Andreas Jung

Is there a way to protect objects from modifications? I have a complex
self-referential data structure that is passed to some other modules 
written by co-workers. I need to avoid that the data structure is changed 
(because

of programming errors). Is there an easy way to accomplish this (other than
by using a dedicated read-only DB connection where the user has only
select grants)?

Andreas

pgpyUaTts2Z4U.pgp
Description: PGP signature


[sqlalchemy] Re: Default data and table related database objects

2007-12-21 Thread Michael Bayer



On Dec 21, 9:48 am, simpsomboy [EMAIL PROTECTED] wrote:

 I need to create some database objects(like a trigger) and insert some
 initial data into table after creation, so I need to know if have some
 way to do it transparent on sqlalchemy

database trigger syntax is pretty database specific so we dont have a
generic DDL construct for that right now.  you can issue the DDL using
a textual execute like engine.execute(CREATE TRIGGER ...).  for
inserting of data you usually would use a table.insert() construct.

 like putting a method on
 mapped class or provide a function to mapper.

you've lost me here.  I don't see the connection between a trigger in
your database and a method on one of your mapped classes.

 if have no way to do this, I need to get a list with all mapped
 classes, than I will create my own process to create these objects and
 insert the default data walking over each class.

you'd have to show me what you mean, I don't understand why you need
to scroll through all your classes just to set up triggers in your
schema.  The schema exists independently of any ORM configuration
which uses that schema.

--~--~-~--~~~---~--~~
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] Default data and table related database objects

2007-12-21 Thread simpsomboy

Hello all,

I've done some finds over list, but not found the answer to solve my
problem.

I need to create some database objects(like a trigger) and insert some
initial data into table after creation, so I need to know if have some
way to do it transparent on sqlalchemy, like putting a method on
mapped class or provide a function to mapper.
Have any way to execute some sql statements at table creation or is
possible only execute the CREATE TABLES?

if have no way to do this, I need to get a list with all mapped
classes, than I will create my own process to create these objects and
insert the default data walking over each class.

thank's for any help


Alexandre

--~--~-~--~~~---~--~~
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] count() does not seem to work correctly with relationships

2007-12-21 Thread Justin

DB = sqlite

I don't now if this is a bug or an issue with my mapper config, but
the count() method does not work correctly through relationships.
Given this mapper:

mapper(Branch, branches, properties={
'reports':dynamic_loader(Report, backref='branch')
})

b = sess.query(Branch).first()

print len(b.reports.all()) # returns the correct number or reports for
this branch.
print b.reports.count() # ignores the relationship returns the total
number of reports in the database.

Thanks,

- Justin Driscoll

--~--~-~--~~~---~--~~
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: Default data and table related database objects

2007-12-21 Thread Michael Bayer


On Dec 21, 2007, at 11:09 AM, Alexandre da Silva wrote:

 it would be just a Method like after_create_execute(SOME DATABASE
 SPECIFIC SQL), and this method should be called after creation of
 table, but just on creation... would be usefull have an
 before_drop_execute(SOME STATEMENT) to make users able to drop these
 related object in case of automatic database recreation

we have a ticket in the works for this:  
http://www.sqlalchemy.org/trac/ticket/903

 if the feature above is not ready, I will put a staticmethod on each
 mapped class to define my default data and related objects, and will
 call it for each mapped class.

 the methods can contain something like this:

 def get_trigger_metadata():
   return CREATE OR REPLACE TRIGGER

 def initialize_table():
   return INSERT INTO TABLE_NAME VALUES (1,Lorem Ipsun,foo,bar)


note that this feature applies to Table objects, not ORM mapped  
classes.  A central tenet of SQLAlchemy is that the object relational  
mapper is an optional package which is completely decoupled from  
database schema definition.  If you're looking to define mapped  
classes and schema declaration together theres a tool called Elixir  
that does that.


--~--~-~--~~~---~--~~
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: Default data and table related database objects

2007-12-21 Thread Alexandre da Silva

 database trigger syntax is pretty database specific so we dont have a
 generic DDL construct for that right now.  you can issue the DDL using
 a textual execute like engine.execute(CREATE TRIGGER ...).  for
 inserting of data you usually would use a table.insert() construct.

ok, it helps if I have an after_create event on mapper or mapped
class, than I will able to create all additional objects related with 
table at moment I call metadata.create_all()

 you've lost me here.  I don't see the connection between a trigger in
 your database and a method on one of your mapped classes.

it would be just a Method like after_create_execute(SOME DATABASE
SPECIFIC SQL), and this method should be called after creation of
table, but just on creation... would be usefull have an
before_drop_execute(SOME STATEMENT) to make users able to drop these
related object in case of automatic database recreation

in the same method after_create_execute() users can put insert
statements to insert default data to tables, it can be very usefull in
some cases.

 you'd have to show me what you mean, I don't understand why you need
 to scroll through all your classes just to set up triggers in your
 schema.  The schema exists independently of any ORM configuration
 which uses that schema.

if the feature above is not ready, I will put a staticmethod on each
mapped class to define my default data and related objects, and will
call it for each mapped class.

the methods can contain something like this:

def get_trigger_metadata():
return CREATE OR REPLACE TRIGGER

def initialize_table():
return INSERT INTO TABLE_NAME VALUES (1,Lorem Ipsun,foo,bar)


All this to setup initial additional objects to database i.e. on
application setup
  


--~--~-~--~~~---~--~~
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: Default data and table related database objects

2007-12-21 Thread Alexandre da Silva

 we have a ticket in the works for this:  
 http://www.sqlalchemy.org/trac/ticket/903
ok, I will look at this ticket.

 note that this feature applies to Table objects, not ORM mapped  
 classes.  A central tenet of SQLAlchemy is that the object relational  
 mapper is an optional package which is completely decoupled from  
 database schema definition.  If you're looking to define mapped  
 classes and schema declaration together theres a tool called Elixir  
 that does that.
Yes, I know Elixir, but I prefer to use sqlalchemy directly to get more
flexibility.

Thank you for reply.

Alexandre


--~--~-~--~~~---~--~~
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] SchemaGenerator.get_column_default_string

2007-12-21 Thread Christophe de VIENNE

Hi all,

In the HEAD version, the table creation does not set the default
values on the columns (tested on mysql and mssql)
It seems that the function SchemaGenerator.get_column_default_string
(in compiler.py) always returns None, even if a default value is
specified.

 801 def get_column_default_string(self, column):
 802 if isinstance(column.default, schema.PassiveDefault):
 803 if isinstance(column.default.arg, basestring):
 804 return '%s' % column.default.arg
 805 else:
 806 return unicode(self._compile(column.default.arg, None))
 807 else:
 808 return None

On line 803, the test is always false because column.default is always
a ColumnDefault.

I'm not sure how this should be fixed, any help is very welcome.

Regards,

Christophe

--~--~-~--~~~---~--~~
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: SchemaGenerator.get_column_default_string

2007-12-21 Thread Michael Bayer


On Dec 21, 2007, at 11:57 AM, Christophe de VIENNE wrote:


 Hi all,

 In the HEAD version, the table creation does not set the default
 values on the columns (tested on mysql and mssql)
 It seems that the function SchemaGenerator.get_column_default_string
 (in compiler.py) always returns None, even if a default value is
 specified.

 801 def get_column_default_string(self, column):
 802 if isinstance(column.default, schema.PassiveDefault):
 803 if isinstance(column.default.arg, basestring):
 804 return '%s' % column.default.arg
 805 else:
 806 return unicode(self._compile(column.default.arg,  
 None))
 807 else:
 808 return None


ColumnDefaults are in-python default generators, they dont get  
rendered into DDL.  PassiveDefault is used to produce a DDL-rendered  
default:

http://www.sqlalchemy.org/docs/04/metadata.html#metadata_defaults_passive



--~--~-~--~~~---~--~~
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] compoundprimary key

2007-12-21 Thread Lukasz Szybalski

Hello,
What is the code for setting up a compound key?

For normal key I would do:
Column('id', Integer, primary_key=True, autoincrement),

For compound key I do?
Column('id', Integer, primary_key=True),
Column('idupdate', Integer, primary_key=True, autoincrement),

In sql form that would be something similar to:
CREATE TABLE search
(
Category VARCHAR(100) NOT NULL,
Page VARCHAR(20) NOT NULL,
Directory VARCHAR(255) NOT NULL,
LinkName VARCHAR(255) NOT NULL,
Keywords MEDIUMTEXT NOT NULL,
Desription VARCHAR(255) NOT NULL,
PRIMARY KEY(Page, Directory)
);


I couldn't find this in documentation. Ideas?

Thanks,
Lucas

--~--~-~--~~~---~--~~
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: SchemaGenerator.get_column_default_string

2007-12-21 Thread Christophe de VIENNE

2007/12/21, Michael Bayer [EMAIL PROTECTED]:
  In the HEAD version, the table creation does not set the default
  values on the columns (tested on mysql and mssql)
  It seems that the function SchemaGenerator.get_column_default_string
  (in compiler.py) always returns None, even if a default value is
  specified.
 
  801 def get_column_default_string(self, column):
  802 if isinstance(column.default, schema.PassiveDefault):
  803 if isinstance(column.default.arg, basestring):
  804 return '%s' % column.default.arg
  805 else:
  806 return unicode(self._compile(column.default.arg,
  None))
  807 else:
  808 return None
 

 ColumnDefaults are in-python default generators, they dont get
 rendered into DDL.  PassiveDefault is used to produce a DDL-rendered
 default:

 http://www.sqlalchemy.org/docs/04/metadata.html#metadata_defaults_passive


What is really disturbing is that Column(..., PassiveDefault(u'N'))
and Column(..., default=PassiveDefault(u'N')) don't have the same
behavior.
Anyway, now I understand what was my mistake.

Thank you !

Christophe

--~--~-~--~~~---~--~~
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: Readonly objects/protecting objects from modifications

2007-12-21 Thread Rick Morrison
Something like this is available on a roll-your-own basis via Python
properties along with some mapper tricks:


http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_mapper_overriding

I would be +1 for such a feature implemented on mapped instances, could be
useful for detecting those hard-to-find bugs, but I can't think of a nice
and simple API for it. For mapped instances via Query(), it  could be an
.option(), but I can't see a good way for its use on relation()s. Also not
sure if such a feature would throw an exception on attribute setting, or
whether it ought to simply be ingored during a flush (OIOW, have it's
dirty flag locked down to False)

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

2007-12-21 Thread Anton V. Belyaev

 I rearranged instance-level deferred loaders to be serializable
 instances in r3968.  you can now pickle an instance + its _state and
 restore, and all deferred/lazy loaders will be restored as well.  I
 didnt yet test it specifically with merge() but give it a try, you
 shoudnt be getting that error anymore...the pickling issue from ticket
 #870 is also no longer present.

Unfortunately it does not work (I am now at r3973).

1) I created an object with deferred property (not None).
2) Reloaded it in a new session (to erase deferred property)
3) Pickled/Unpickled
4) Removed everything but properties and _state.
5) obj = s.merge(obj, dont_load=True)  (with a fresh session s)
6) obj.deferred_ppty = None

merge worked without an exception this time.

Thanks.

PS. Special thanks for #871 (overheads in backref). It was blocking
the full-featured use of SqlAlchemy while staying as efficient as raw
SQL for me :)
--~--~-~--~~~---~--~~
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: Readonly objects/protecting objects from modifications

2007-12-21 Thread sdobrev

i have such thing implemented externaly but it is definitely not nice (read: 
tricky and underground) - replacing the __dict__ with something handmade 
that does what i say as i say if i say. that's dbcook's reflector for my 
static_type structures; look in dbcook/usage/static_type if interested. and 
it is now broken with the latest instance_state handling mechanism.

another, similar or not, feature i needed while doing dbcook, was a 
readonly/loadonly mapper; i.e. a mapper for a sort-of intermediate 
base-class which should not have its own instances; only subclasses may have 
instances/DB-footprint. That i made via MapperExt, throwing at 
before_insert/update/delete.

Rick Morrison wrote:
 Something like this is available on a roll-your-own basis via Python
 properties along with some mapper tricks:
 
 
 http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_mapper_overriding
 
 I would be +1 for such a feature implemented on mapped instances, could be
 useful for detecting those hard-to-find bugs, but I can't think of a nice
 and simple API for it. For mapped instances via Query(), it  could be an
 .option(), but I can't see a good way for its use on relation()s. Also not
 sure if such a feature would throw an exception on attribute setting, or
 whether it ought to simply be ingored during a flush (OIOW, have it's
 dirty flag locked down to False)


--~--~-~--~~~---~--~~
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: sqlalchemy_types names consistency

2007-12-21 Thread Michael Bayer


On Dec 21, 2007, at 2:20 PM, Lukasz Szybalski wrote:


 http://www.sqlalchemy.org/docs/04/sqlalchemy_types.html

 Is there a reason why I can define my column with
 Integer or INTEGER
 but not
 Decimal,Text,Blob etc.

 Shouldn't there be some kind of consistency? Either Capitalized
 letters or ALLCAPS, or Both on all types.
 Unless there is a reason why this is made like this.

captialized refers to a SQL standard type, whereas non-capitalized is  
a generic type that may resolve differently on different database  
backends.  so for Decimal we have Numeric, for Blob we have Binary.

we should have Text and not TEXT in the base since TEXT does not  
compile to TEXT on all platforms...added ticket #912 for that.




--~--~-~--~~~---~--~~
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: Readonly objects/protecting objects from modifications

2007-12-21 Thread Michael Bayer

On Dec 21, 2007, at 3:13 PM, Rick Morrison wrote:

 Something like this is available on a roll-your-own basis via Python  
 properties along with some mapper tricks:


 http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_mapper_overriding

 I would be +1 for such a feature implemented on mapped instances,  
 could be useful for detecting those hard-to-find bugs, but I can't  
 think of a nice and simple API for it. For mapped instances via  
 Query(), it  could be an .option(), but I can't see a good way for  
 its use on relation()s. Also not sure if such a feature would throw  
 an exception on attribute setting, or whether it ought to simply be  
 ingored during a flush (OIOW, have it's dirty flag locked down to  
 False)



I think the only way something like this should be done is as a test  
fixture which decorates classes during unit tests.It would be  
fairly clumsy to have in production code.

If you have coworkers who write broken code, the way you solve that is  
by having unit tests which will fail when the coworkers in question do  
something theyre not supposed to.   If other people are writing code  
that sets attrbutes its not supposed to and breaks things, you need  
more tests to catch those conditions.  If youre putting code into  
production that hasnt been tested, then you need a build process,  
automated testing, etc.There is definitely a best practice here  
and test driven development is it.
--~--~-~--~~~---~--~~
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: SchemaGenerator.get_column_default_string

2007-12-21 Thread Michael Bayer


On Dec 21, 2007, at 2:10 PM, Christophe de VIENNE wrote:


 2007/12/21, Michael Bayer [EMAIL PROTECTED]:
 In the HEAD version, the table creation does not set the default
 values on the columns (tested on mysql and mssql)
 It seems that the function SchemaGenerator.get_column_default_string
 (in compiler.py) always returns None, even if a default value is
 specified.

 801 def get_column_default_string(self, column):
 802 if isinstance(column.default, schema.PassiveDefault):
 803 if isinstance(column.default.arg, basestring):
 804 return '%s' % column.default.arg
 805 else:
 806 return unicode(self._compile(column.default.arg,
 None))
 807 else:
 808 return None


 ColumnDefaults are in-python default generators, they dont get
 rendered into DDL.  PassiveDefault is used to produce a DDL-rendered
 default:

 http://www.sqlalchemy.org/docs/04/metadata.html#metadata_defaults_passive


 What is really disturbing is that Column(..., PassiveDefault(u'N'))
 and Column(..., default=PassiveDefault(u'N')) don't have the same
 behavior.

default=SomeDefaultGenerator should really be fixed to do something  
meaningful, I know.  we'll fix that.



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

2007-12-21 Thread Michael Bayer

On Dec 21, 2007, at 3:54 PM, Anton V. Belyaev wrote:

 1) I created an object with deferred property (not None).
 2) Reloaded it in a new session (to erase deferred property)
 3) Pickled/Unpickled
 4) Removed everything but properties and _state.

what did you remove exactly ?  there are some attributes on the  
instance, such as _instance_key and _entity_name, which should not be  
erased. also any attribute which doesnt have a deferred or expired  
flag on it shouldnt be erased either.  if you want to remove  
attributes, use session.expire(instance, ['key1', 'key2', ...]).  a  
test script illustrating pickling/unpickling, which uses update(), is  
attached.


 5) obj = s.merge(obj, dont_load=True)  (with a fresh session s)

merge is still not working, it raises an exception in this case.  will  
have a fix soon.



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

from sqlalchemy import *
from sqlalchemy.orm import *

import pickle

engine = create_engine('sqlite://', echo=True)
metadata = MetaData(engine)

users = Table('users', metadata,
Column('id', Integer, primary_key=True),
Column('name', String(30), nullable=False))
users.create()

class User(object):
pass

mapper(User, users, properties={
'name':deferred(users.c.name)
})

u1 = User()
u1.name = 'ed'

sess = create_session()
sess.save(u1)
sess.flush()

sess.clear()

u2 = sess.query(User).get(u1.id)
assert 'name' not in u2.__dict__

u3 = pickle.loads(pickle.dumps(u2))

sess2 = create_session()

sess2.update(u3)

# not working yet
#u3 = sess2.merge(u3, dont_load=True)

assert 'name' not in u3.__dict__

assert u3.name == 'ed'




[sqlalchemy] Re: Caching

2007-12-21 Thread Michael Bayer

On Dec 21, 2007, at 3:54 PM, Anton V. Belyaev wrote:


 merge worked without an exception this time.

merge is working rudimentally for objects with unloaded scalar/ 
instance/collection attributes in r3974.  whats not yet happening is  
the merging of the various query.options() that may be present on the  
original deferred loader, which means the merged instance wont  
necessarily maintain the exact eager/lazy/deferred loading of the  
original, but this is not especially critical for the basic idea to  
work.

example script using merge attached.


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

from sqlalchemy import *
from sqlalchemy.orm import *

import pickle

engine = create_engine('sqlite://', echo=True)
metadata = MetaData(engine)

users = Table('users', metadata,
Column('id', Integer, primary_key=True),
Column('name', String(30), nullable=False))
users.create()

class User(object):
pass

mapper(User, users, properties={
'name':deferred(users.c.name)
})

u1 = User()
u1.name = 'ed'

sess = create_session()
sess.save(u1)
sess.flush()

sess.clear()

u2 = sess.query(User).get(u1.id)
assert 'name' not in u2.__dict__

u3 = pickle.loads(pickle.dumps(u2))

sess2 = create_session()

u3 = sess2.merge(u3, dont_load=True)

assert 'name' not in u3.__dict__

assert u3.name == 'ed'




[sqlalchemy] get mapped class

2007-12-21 Thread Alexandre da Silva

Hello Again,

I am already trying go get the list of mapped tables. I currently got a
list from sqlalchemy.org.mapper from the weakref mapper_registry, but
I don't know if that values are useful for my context.

I also have another question, I have some way to access the mapped class
from the table object?

something like:

user_table = Table(...)

class User(object)
pass

mapper(User, user_table)

I have some method like user_table.getclass? or another way to get it
from orm?

thank's for help


-- 
Alexandre da Silva
Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007)

gedit-todo
http://alexandredasilva.wordpress.com/gedit-todo-list-plugin/
MicroDB
http://www.assembla.com/space/microdb
Open Sales Force System
http://www.assembla.com/space/osfs
opencomanche ([stopped] mail-me to get the latest source code)
http://sourceforge.net/projects/opencomanche/



--~--~-~--~~~---~--~~
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] Mapper properties and a callback

2007-12-21 Thread Dave Harrison

Hi all,

I have a situation where I want to declare a relation between two
tables, but I want to be able to run a callback whenever I append to
that relation.  Here's an example

class Kennel:
def callback(self, o):
print callback, o

mapper = Mapper(
Kennel,
kennelTable,
properties = {
dogs : relation(
Dog, cascade=all, delete-orphan
),
}
)

So whenever I use mykennel.dogs.append(fred) I want to be able to tell
the relation to call callback() so that I can do some checking on the
object that is being appended.

Is this possible ??

Cheers
Dave

--~--~-~--~~~---~--~~
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] SQLALchemy used at gcollab

2007-12-21 Thread Sanjay

Hi All,

We have just released www.gcollab.com, a site hosting global
collaborative services such as tmail.

SQLAlchemy is being used as the database component/ORM of gcollab. My
experience with SQLAlchemy has been rewarding and smooth. The
documentation is great. The support and response in this forum has
been really excellant. I remember in one or two occasions I faced some
issues, which Michael responded to and resolved instantly.

Grabbing this opportunity to sincerely appreciate and thank Michael
and all the people behind SQLAlchemy, for such a great framework, with
excellant response and support.

Sanjay

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