[sqlalchemy] Class.query vs DBSession.query(Class)

2009-02-26 Thread Sanjay

Hi,

There are two styles of writing code for querying: the assignmapper
style, i.e. Class.query vs. the standard style as documented in
SQLAlchemy tutorial, i.e. DBSession.query(Class).

The assignmapper style seems simpler and intuitive. Curious to know
why it is not the standard way. Are there any disadvantages?

Also refer 
http://groups.google.co.in/group/turbogears/browse_thread/thread/8f3b4c4da33d69c8

thanks,
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] High resolution SQLAlchemy logo

2008-05-02 Thread Sanjay

Hi,

I think to print SQLAlchemy logo on our company brochure. I think it
is permissible. Is not so? Is there a high resolution logo somewhere?

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



[sqlalchemy] Getting error while using MapperExtension

2008-04-08 Thread Sanjay

Hi,

In a project, I am using MapperExtension this way:

class TaskExtension(MapperExtension):
def populate_instance(self, mapper, selectcontext, row, instance,
**flags):
 mapper.populate_instance(selectcontext, row, instance,
**flags)
 instance.on_load() # does some custom initialization

It gives me the following exception:

TypeError: ('Task' object is unsubscriptable...

Needing help.

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



[sqlalchemy] Re: Getting error while using MapperExtension

2008-04-08 Thread Sanjay

 For your call to mapper.populate_instance, you have the arguments for 'row'
 and 'instance' reversed.

Yes! reversing it works perfectly. I had guessed the argument sequence
from the MapperExtension.populate_instance, which happens to be
reverse.

thanks a lot!
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
-~--~~~~--~~--~--~---



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



[sqlalchemy] Re: concurent modification

2007-11-22 Thread Sanjay

I think all one can do is just forget and start over again, when
concurrent modifications error occurs. That means, catchig the
exception and just showing some failure message to the user is all one
can do.

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



[sqlalchemy] Re: Looking for feedback on encapsulating SA logic (newbie)

2007-10-29 Thread Sanjay

 mapper(User, users_table)

Is not using assign_mapper preferable?


--~--~-~--~~~---~--~~
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: session issues in TG - automatic commits happening.

2007-06-26 Thread Sanjay

As I recall, this was discussed in TG forum sometime, and there is a
nice way to disable this. Searching there might help...

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



[sqlalchemy] Re: Concurrency control using version_id_col

2007-06-26 Thread Sanjay

Hi Mike,

Thanks a lot. It works fine (with or without default=0). The problem
was in my TG application, which was not preserving version while
populating the edit form. I made version as a hidden field in the
form, and it works fine now.

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



[sqlalchemy] Concurrency control using version_id_col

2007-06-21 Thread Sanjay

Hi,

In order to achieve concurrency control using optimistic locking, we
are doing the following:

1. Adding a column in the table like this:

page_tbl = Table('page', metadata,
Column('page_id', Integer, primary_key=True, autoincrement=True),
Column('link_name', Unicode(30), nullable=False),
.
.
Column('version', Integer, default=0))

2. Mapping like this:

assign_mapper(session.context, Page, page_tbl,
version_id_col=page_tbl.c.version, properties={...})


But it does not seem working. Are we missing any step?

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



[sqlalchemy] Re: In Turbogears, using the same transaction for mapped objects and direct operations

2007-06-07 Thread Sanjay

 So, cherrypy.request.sa_transaction.connection should work.

I had tries that. But it says Exceptions :'function' object has no
attribute 'execute' Don't know why.

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



[sqlalchemy] Re: In Turbogears, using the same transaction for mapped objects and direct operations

2007-06-06 Thread Sanjay

 conn = session.context.get_current().connection(SomeMappedClass)
 conn.execute(...)

Thanks! It is exactly what I needed.

BTW, the session transaction is stored in
cherrypy.request.sa_transaction. Does this help simplify the
statements?

thanks again,
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
-~--~~~~--~~--~--~---



[sqlalchemy] In Turbogears, using the same transaction for mapped objects and direct operations

2007-06-05 Thread Sanjay

Hi,

In a turbogears application that I am developing, in a single
transaction, I need to delete certain records of a table, and update
another table. the code is something like:

from sqlalchemy import *
from turbogears import metadata, session
.
.
.
document_tbl.delete(document_tbl.c.doc_id.in_(*doc_ids)).execute()
website.used_bytes -= size_of_deleted_documents # website is a mapped
object.
.
.

Problem is that, the delete statement runs in its own transaction, and
not in the same transaction in which the second statement runs.

Need help on how to do it. Being a turbogears application where db
entities like metadata and session are imported rather than created by
me, I am confused and could not successfully implement the pattern
provided in the docs.

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



[sqlalchemy] Re: Calling a function (Stored Procedure) returning a recordset

2007-05-15 Thread Sanjay

Thanks a lot, Michael and Eric! This long thread has been quite useful
to me.

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



[sqlalchemy] Re: Calling a function (Stored Procedure) returning a recordset

2007-05-13 Thread Sanjay

 Further findings and queries on SelectResults:

 1. Is SelectResults still needed in certain situations:

 a. Observed that SelectResults was having a count() method. If we
 don't use SelectResults, either we have to query the database for
 getting the count manually, or use len(list). Using 'len' may not be
 recommended in paginated data grids.

 b. Seeing the TurboGears code for 'paginate', it checks for the type
 of variable. If it is a list, it just applies len(list)! Does that
 mean, we have to explicitly use SelectResults with TurboGears?

 2. SelectResults not behaving properly:

 I have some code which returns a list although I expect a
 SelectResults. Here is the minimal version reproducing that. Can't
 guess whether I am doing something wrong or it's a bug. Need help.

 from sqlalchemy import *
 from sqlalchemy.ext.assignmapper import assign_mapper
 from sqlalchemy.ext.sessioncontext import SessionContext
 import sqlalchemy.mods.selectresults

 context = SessionContext(create_session)
 session = context.current

 metadata = BoundMetaData('sqlite:///satest', echo=True)

 # table definitions
 person_table = Table('person', metadata,
 Column('person_id', Integer, primary_key=True, autoincrement =
 True),
 Column('first_name', Unicode(30)),
 Column('last_name', Unicode(30)))

 metadata.drop_all()
 metadata.create_all()

 class Person(object):
 pass

 assign_mapper(context, Person, person_table)

 p1 = Person(first_name=Sanjay, last_name=Patel)
 p2 = Person(first_name=Ranjan, last_name=Naik)
 session.flush()
 del p1
 del p2
 session.clear()
 # persons = Person.select_by(person_id=1)
 # assert isinstance(persons,
 sqlalchemy.ext.selectresults.SelectResults) # OK
 persons = Person.select(Person.c.person_id.in_(1))
 assert isinstance(persons, sqlalchemy.ext.selectresults.SelectResults)
 # Fails!

Hi Michael,

The post being too long probably was not that clear to draw your
attention. In summary, it tries to justify the need of SelectResults
still in certain situations. Also, it tries to point out what seems
like a bug in SelectResults. Would need your comments  help on this.

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



[sqlalchemy] Re: Calling a function (Stored Procedure) returning a recordset

2007-05-11 Thread Sanjay

  Also SelectResults is deprecated as
  Query includes all of its functionality now.

 So nice! Does this mean, in laymans term,

 1. I do not have to bother writing import
 sqlalchemy.mods.selectresults
 2. Normal query, whether used raw or through ORM, can supply data to
 paginated data grids as efficiently as SelectResults was doing?

Further findings and queries on SelectResults:

1. Is SelectResults still needed in certain situations:

a. Observed that SelectResults was having a count() method. If we
don't use SelectResults, either we have to query the database for
getting the count manually, or use len(list). Using 'len' may not be
recommended in paginated data grids.

b. Seeing the TurboGears code for 'paginate', it checks for the type
of variable. If it is a list, it just applies len(list)! Does that
mean, we have to explicitly use SelectResults with TurboGears?

2. SelectResults not behaving properly:

I have some code which returns a list although I expect a
SelectResults. Here is the minimal version reproducing that. Can't
guess whether I am doing something wrong or it's a bug. Need help.

from sqlalchemy import *
from sqlalchemy.ext.assignmapper import assign_mapper
from sqlalchemy.ext.sessioncontext import SessionContext
import sqlalchemy.mods.selectresults

context = SessionContext(create_session)
session = context.current

metadata = BoundMetaData('sqlite:///satest', echo=True)

# table definitions
person_table = Table('person', metadata,
Column('person_id', Integer, primary_key=True, autoincrement =
True),
Column('first_name', Unicode(30)),
Column('last_name', Unicode(30)))

metadata.drop_all()
metadata.create_all()

class Person(object):
pass

assign_mapper(context, Person, person_table)

p1 = Person(first_name=Sanjay, last_name=Patel)
p2 = Person(first_name=Ranjan, last_name=Naik)
session.flush()
del p1
del p2
session.clear()
# persons = Person.select_by(person_id=1)
# assert isinstance(persons,
sqlalchemy.ext.selectresults.SelectResults) # OK
persons = Person.select(Person.c.person_id.in_(1))
assert isinstance(persons, sqlalchemy.ext.selectresults.SelectResults)
# Fails!


--~--~-~--~~~---~--~~
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: 'MapperExtension' object has no attribute 'translate_row'

2007-05-04 Thread Sanjay

 testcase please

Here is the sample code which works perfectly till 0.3.4 and produces
error in newer versions in my system:

from sqlalchemy import *
from sqlalchemy.ext.assignmapper import assign_mapper
from sqlalchemy.ext.sessioncontext import SessionContext

context = SessionContext(create_session)
session = context.current

metadata = BoundMetaData('sqlite:///satest', echo=False)

task_tbl = Table('task', metadata,
Column(task_id, Integer, primary_key=True, autoincrement=True),
Column(descr, Unicode(30), nullable=False))

metadata.drop_all()
metadata.create_all()

class Task(object):
pass

from sqlalchemy import EXT_PASS

class TaskExtension(object):

def get_session(self):
return EXT_PASS
def select_by(self, query, *args, **kwargs):
return EXT_PASS
def select(self, query, *args, **kwargs):
return EXT_PASS
def get_by(self, query, *args, **kwargs):
return EXT_PASS
def get(self, query, *args, **kwargs):
return EXT_PASS
def create_instance(self, mapper, selectcontext, row, class_):
return EXT_PASS
def append_result(self, mapper, selectcontext, row, instance,
identitykey, result, isnew):
return EXT_PASS
def populate_instance(self, mapper, selectcontext, row, instance,
identitykey, isnew):
mapper.populate_instance(selectcontext, instance, row,
identitykey, isnew)
def before_insert(self, mapper, connection, instance):
 return EXT_PASS
def before_update(self, mapper, connection, instance):
return EXT_PASS
def after_update(self, mapper, connection, instance):
return EXT_PASS
def after_insert(self, mapper, connection, instance):
return EXT_PASS
def before_delete(self, mapper, connection, instance):
return EXT_PASS
def after_delete(self, mapper, connection, instance):
return EXT_PASS

assign_mapper(context, Task, task_tbl, extension=TaskExtension())

t = Task(descr='xyz')
t.flush()
session.clear()
t = Task.get(1) # produces exception



--~--~-~--~~~---~--~~
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: 'MapperExtension' object has no attribute 'translate_row'

2007-05-04 Thread Sanjay

 Your TaskExtension class doesn't have a translate_row method, which
 apparently is part of the MapperExtension interface (although it doesn't
 appear in the docs). From the source code (in orm/mapper.py):

 def translate_row(self, mapper, context, row):
 Perform pre-processing on the given result row and return a
 new row instance.

 This is called as the very first step in the ``_instance()``
 method.
 

 return EXT_PASS

 You could make life much easier for yourself by making TaskExtension
 inherit from MapperExtension. In that way you would only need to
 implement the methods that you actually want to override, and you won't
 have to update your extension class every time new extension methods are
 added.

 Hope that helps,

 Simon


 class TaskExtension(object):

 MapperExtensions need to subclass the MapperExtension class:

 class TaskExtension(MapperExtension):

Thanks a lot Simon, Michael! I did not read the documentation properly
and had missed the inheritence. It indeed makes life a lot simpler.

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



[sqlalchemy] Re: Calling a function (Stored Procedure) returning a recordset

2007-05-02 Thread Sanjay

  tasklist = func.get_tasklist(engine=engine).execute()   # is this the
  correct way?

 looks fine to me.  for the rest of it, im not very familiar with PG
 stored procedures.

I think SQLAlchemy code is translating to SELECT get_tasklist(). But
what is actually needed is SELECT * FROM get_tasklist().

So, probably the question is, What SQLAlchemy code will translate to
SELECT * FROM get_tasklist(). Needing suggestions.

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



[sqlalchemy] Calling a function (Stored Procedure) returning a recordset

2007-05-01 Thread Sanjay

Hi,

I have a postgres function returning a set of records (using RETURN
NEXT). While calling the function like this:

tasklist = func.get_tasklist(engine=engine).execute()   # is this the
correct way?

I am getting this error:

SQLError: ('(ProgrammingError) set-valued function called in context
that cannot accept a set\nCONTEXT: PL/pgSQL function get_tasklist
line 6 at return next\n', bound method TaskController.get_tasks of
gcollab.controllers.task.TaskController object at 0xb742716c)
'SELECT get_tasklist()' {}

Am I calling the stored procedure correctly? Need help.

thanks
Sanjay



Here is code of the stored procedure:

CREATE OR REPLACE FUNCTION get_tasklist() RETURNS setof tasklist_t AS $
$
DECLARE
t tasklist_t%rowtype;
BEGIN
FOR t IN SELECT task_id, descr, 'Waiting', remind_at, 'Sanjay'
FROM task
LOOP
RETURN NEXT t;
END LOOP;
RETURN;
END;
$$ LANGUAGE PLPGSQL;


--~--~-~--~~~---~--~~
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] 'MapperExtension' object has no attribute 'translate_row'

2007-04-28 Thread Sanjay

Hi,

While updated from version 0.3.3 to 0.3.6, I am getting this error:

'MapperExtension' object has no attribute 'translate_row'

A bug? Any clues would help.

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



[sqlalchemy] Is it possible to know the size of a deferred PickleType?

2007-03-06 Thread Sanjay

Hi All,

Wondering if it is possible to know the size of a file stored in a
deferred column (PickleType), without retrieving the file itself.

Thanks in advance.

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



[sqlalchemy] Re: Is it possible to know the size of a deferred PickleType?

2007-03-06 Thread Sanjay

 I usually try to save the filesize as a separate column.

Hi Sean, Thanks for the suggestion. I think that might be the only way
to know a filesize without retrieving a file.

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



[sqlalchemy] Re: Running initialization code after creating/loading an object

2007-03-02 Thread Sanjay

Hi Rick,

This was exactly what I needed. Thanks a lot!

Sanjay

(I think I wrote this message yesterday also, which did not appear.
Might have pressed the discard button?!)


--~--~-~--~~~---~--~~
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] Running initialization code after creating/loading an object

2007-02-26 Thread Sanjay

Hi,

I am not able to code this pattern. I read about it at many places, in
doc, FAQ and at
http://groups.google.co.in/group/sqlalchemy/browse_thread/thread/66d0094c671bd5bc,
but still could not do it. May be my noviceness. Needing help. I tried
somethings like this, but it did not help:

from sqlalchemy import *
from sqlalchemy.ext.assignmapper import assign_mapper
from sqlalchemy.ext.sessioncontext import SessionContext

context = SessionContext(create_session)
session = context.current

metadata = BoundMetaData('sqlite:///satest', echo=False)

# table definitions
person_table = Table('person', metadata,
Column('person_id', Integer, primary_key=True, autoincrement =
True),
Column('first_name', Unicode(30)),
Column('last_name', Unicode(30)))

metadata.drop_all()
metadata.create_all()

class Person(object):

@staticmethod
def Create(first_name, last_name):
p = Person(first_name=first_name, last_name=last_name)
p.CallAfterInitializationOrFetchingFromDatabase()
return p

def CallAfterInitializationOrFetchingFromDatabase(self):
self.full_name = self.first_name + ' ' + self.last_name

class PersonExtension(object):

def create_instance(self, mapper, selectcontext, row, Person):
p = Person()
p.CallAfterInitializationOrFetchingFromDatabas()
return p

assign_mapper(context, Person, person_table,
extension=PersonExtension())

p = Person.Create(first_name=Sanjay, last_name=Patel)
Assert p.full_name == Sanjay Patel
p.flush()
del p
session.clear()
p = Person.get_by(person_id=1)
assert p.full_name == Sanjay Patel

I think using __new__ might be simpler, but can't guess how exactly
to use it.

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



[sqlalchemy] Re: Full Text Search using PostgreSQL and tsearch2

2007-02-01 Thread Sanjay

 Thanks a lot, guys. Will try a sample application and post in the wiki.
 Might take some time - meanwhile, if somebody gets some more stuff,
 posting it would help.

 thankssanjay

Really sorry - I could not touch this yet. Have got suddenly busy in
preparing for some training, which suddenly creeped in. It might take
some more time. Till then if somebody does this, kindly post in the
wiki.

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



[sqlalchemy] Re: new docs new docs new docs

2007-01-22 Thread Sanjay

 I present to you Michael Bayer, the amazing multitalented developer
 of SQLAlchemy--getting more done in one week than the average team of
 developers does in a month!! Not only is he a very fast coder, but he
 writes comprehensive documentation for his code--an unheard-of
 combination of willingness and ability in an open-source developer.

Fully seconded. I take SQLAlchemy as a boon to IT industry -
particularly while talking Agile development. I can't think agile
python frameworks entering enterprise level without it.

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



[sqlalchemy] Re: Full Text Search using PostgreSQL and tsearch2

2007-01-19 Thread Sanjay


Thanks a lot, guys. Will try a sample application and post in the wiki.
Might take some time - meanwhile, if somebody gets some more stuff,
posting it would help.

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



[sqlalchemy] Full Text Search using PostgreSQL and tsearch2

2007-01-18 Thread Sanjay


Hi All,

Trying to implement full text search with PostgreSQL and tsearch2,
being a beginner, I am facing some basic hurdles:

1. How to declare a table in SA, I mean, what SA datatype should
tsvector correspond to?
2. Can the index be defined using SA, or we need to do it in the
backend?
3. Can the trigger for auto update be defined using SA, or we need to
do it in the backend?
4. How to frame the query in SA?

A reference, tutorial, receipe or at least some key guidance could
really help me.

Dennis has mentioned in a post - I'm currently doing that with
Postgresql(tsearch2) for a project and it works quite well., but I am
not being able to guess the pattern.

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



[sqlalchemy] Re: PostgreSQL - fetching boolean type gives integer type

2006-12-22 Thread Sanjay


My system was having PostgreSQL 8.1.4 and psycopg. After Alan's code
failing in my system, I doubted on psycopg. With some struggle, I
successfully installed psycopg2 and removed psycopg, and things worked!

Thanks a lot for the diagnosis, guys. Extremely sorry to have bothered
you. Understanding SA docs recommending psycopg2, a few days back I had
tried to install it. But it gave some error, and I decided not to
bother and be happy with psycopg, as it was working without problems
for me for last few months. That was the mistake, which drained this
timeeffort of all of us.

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



[sqlalchemy] table_foo.c.column_foo.autoincrement returning True always

2006-12-22 Thread Sanjay


In order to know whether a column is an autoincrement column, I am
checking the above flag. But it is returning True always, irrespective
of the column. I am using SQLAlchemy 0.3.3, PostgreSQL 8.1.4 and
psycopg2 on fedora 5.

Wondering whether it's the correct flag, anything is wrong in my
system, or it's a bug.

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



[sqlalchemy] Re: table_foo.c.column_foo.autoincrement returning True always

2006-12-22 Thread Sanjay


I am not reflecting the tables. Example code:

from sqlalchemy import *

metadata = BoundMetaData('postgres://user:[EMAIL PROTECTED]/mydb',
echo=True)

company_tbl = Table('company', metadata,
Column('company_id', Integer, primary_key=True,
autoincrement=True),
Column('name', Unicode(30)))

metadata.create_all()

assert company_tbl.c.company_id.autoincrement == True
assert company_tbl.c.name.autoincrement == True# passes!
assert company_tbl.c.name.autoincrement == False   # fails!

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



[sqlalchemy] PostgreSQL - fetching boolean type gives integer type

2006-12-21 Thread Sanjay


In PostgreSQL, this code:

{{{
# select a row from website_type_tbl(wtype_id INTEGER PK, show_ads
BOOLEAN)
row = website_type_tbl.select().execute().fetchone()
# insert another row
website_type_tbl.insert().execute(wtype_id=5, show_ads=row.show_ads)
}}}

Produces error - SQLError: (ProgrammingError) ERROR:  column show_ads
is of type boolean but expression is of type integer

What happens is, while fetching, boolean columns are fetched as integer
type (0, 1).

I don't know whether it is the expected behaviour or a bug.  Bringing
to notice, in case it is a bug.

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



[sqlalchemy] Re: PGBigInteger behaving like Integer

2006-12-15 Thread Sanjay

Thanks! Again I am overwhelmed by the excellant response!!

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



[sqlalchemy] Configuration of SelectResults: per Query, per Mapper, or per application?

2006-12-14 Thread Sanjay

I am implementing @paginate in a few places in a turbogears
application, which needs SelectResults. Wondering whether to configure
it for per Query, per Mapper, or per application mode. Seeking
suggestions on advantages and disadvantages of each. 

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



[sqlalchemy] Re: SA 0.3.x: performance issues

2006-12-05 Thread Sanjay

 instance changes get picked up.  if you want the more simplistic
 comparison method (i.e. using is), set up your PickleType with the
 flag mutable=False.

You meant like this?

Column('content', PickleType, mutable=False)

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



[sqlalchemy] Selection criteria in a property(one-to-many) of a mapped object

2006-12-05 Thread Sanjay

Might be a novice question...

Say I have a business object Website, mapped using assign_mapper,
having a property(relation to Page object) pages. Needing suggestion
on what is a best way to fetch selective pages for a particular
website.

E.g.

website = Website.get(1)
# website.pages is a list refering to all pages of an website

website.pages(where page_id = 1)   # what is the ideal way to do
this
website.pages(where created_at 21-DEC-2006)  # and this

pages being a python list, searching for thing iteratively could do
the job, but would involve many database fetches.

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