Lukasz Szybalski wrote:
> On Thu, Jul 10, 2008 at 11:59 AM, jason kirtland <[EMAIL PROTECTED]> wrote:
>> Lukasz Szybalski wrote:
>>> On Thu, Jul 10, 2008 at 11:26 AM, Heston James - Cold Beans
>>> <[EMAIL PROTECTED]> wrote:
>>>>> Session.add is a version 0.5 method, you're maybe running 0.4.6?
>>>>>
>>>>> In the 0.4.x series, it's going to be:
>>>>>
>>>>> Session.save() for objects that are to be newly added to the session
>>>>> Session.update() for objects that are already in the session, or
>>>>> Session.save_or_update() to have the library figure it out as it does for
>>>> Session.add in v0.5.x
>>>>
>>>> Hi Rick,
>>>>
>>>> That's exactly what the problem was :-) Is there any reason I should avoid
>>>> using 0.5? I'm running python 2.4 at the moment, are they compatible?
>>>>
>>>> Next quick question: I have a habbit of using 'created' and 'modified'
>>>> columns on my tables, is there any way in which I can have the ORM update
>>>> the dates for me when creating and modifying rows?
>>>>
>>> From the link I sent you previously:
>>>
>>>  sqlalchemy.Column('CreatedDate', sqlalchemy.Date,
>>> default=datetime.now().date()),
>>>   sqlalchemy.Column('CreatedTime', sqlalchemy.Time,
>>> default=datetime.now().time())
>> Not so much.  That'll stamp every inserted row with the same time-
>> whatever time it was when python evaluated the Table definition.
>>
>> Here's a cross-db way to get timestamps:
>>
>>  from sqlalchemy import Table, Column, DateTime, func
>>  Table('abc', metadata,
>>        ...
>>        Column('created', DateTime, default=func.now()),
>>        Column('updated', DateTime, onupdate=func.now()))
>>
> 
> What exactly is "func" ? Is that a function that just gets time or?
> Can I use
> onupdate=func.now().time() for time
> onupdate=func.now().date() for date
> 
> I don't really prefer to have both date and time mixed in datetime field.

func is a SQL function expression builder: func.now() emits the sql
function NOW() as the column value in the insert, moving responsibility
for timestamp calculation to the database.  func can build any function
the database supports, like current_date or current_time.

http://www.sqlalchemy.org/docs/04/sqlexpression.html#sql_everythingelse_functions

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

Reply via email to