[sqlalchemy] Re: Connecting to MySQL

2008-07-11 Thread Heston James - Cold Beans

 Column('created', DateTime, default=func.now()),
 Column('updated', DateTime, onupdate=func.now()))

 You can set both default= and onupdate= on the same Column if you want
 'updated' to be non-NULL on insert.

That sounds like a nice clean way of doing this Jason, I'm more than happy with 
that, it seems the most logical way of implementing it.

Cheers for the advice,

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: Connecting to MySQL

2008-07-11 Thread Heston James - Cold Beans
Hello Rick,

 

These mapper extensions look very good, I've used a similar concept in other
ORM's in the past for all manner of things and have a couple of decent ways
to utilize them in this current application.

 

Cheers,

 

Heston

 

From: sqlalchemy@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Rick Morrison
Sent: 10 July 2008 17:37
To: sqlalchemy@googlegroups.com
Subject: [sqlalchemy] Re: Connecting to MySQL

 

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?


0.5 is still in beta, and I don't have much experience with it myself, but
if were just starting out, I would probably be using that, otherwise you'll
need to migrate later; it's easier to just start out with the new API.

 


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?


Yes, check out mapper extensions in the docs, you're going to want
after_insert and after_update extensions.

 




--~--~-~--~~~---~--~~
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: Connecting to MySQL

2008-07-11 Thread jason kirtland

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



[sqlalchemy] Re: Connecting to MySQL

2008-07-10 Thread Lukasz Szybalski

On Thu, Jul 10, 2008 at 8:20 AM, Heston James
[EMAIL PROTECTED] wrote:

 Good afternoon guys,

 I'm brand new to SQLAlchemy as of about 2 minutes ago, I have a couple
 of starter questions that I wanted to run past you, with any luck
 they'll be simple for you to answer.

 After looking through the quick tutorial, which showed me just about
 all I need to know http://www.sqlalchemy.org/docs/05/ormtutorial.html
 it talks about connecting to an in memory sqllite database using a
 connection string like so:

 create_engine('sqlite:///:memory:', echo=True)

Here is a list of possible connection strings. Its more towords
turbogears way but it will get you started.
http://lucasmanual.com/mywiki/TurboGears#head-8457721059b18a5f2264f8484082deb5b294d27a

Here is sqlalchemy:
http://www.sqlalchemy.org/docs/05/dbengine.html#dbengine_establishing

(ps. could you guys add the connection strings to you docs I have
listed them in the top link. I've mentioned this before but I guess it
wasn't added to you official docs back then.)

And you should read over:
http://www.rmunn.com/sqlalchemy-tutorial/tutorial.html


 How would I connect to a local MySQL database? The database I'm
 working with is already designed and built, which leads me onto my
 next question:

 In the tutorial documentation it talks about 'Defining and Creating a
 Table'. Is this something which need only be done when we're working
 with an in-memory database? or do I have to define my database schema
 even if its a pre-existing mysql database? or does SQLAlchemy
 introspect it or something?

You auto load the existing database.



 My thrid and final question is about the persistance of composed
 objects. If I save an object using sql alchamy, I see it also saves
 the objects children. Is this done in a transaction by default? if the
 save process on one of its children fails will it all be rolled back?
 or is this something I have to specify seperatly?

 Thanks guys, once I know those little items I'm sure I'll be able to
 get up and running pretty swiftly.

 Cheers,




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: Connecting to MySQL

2008-07-10 Thread Rick Morrison
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

--~--~-~--~~~---~--~~
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: Connecting to MySQL

2008-07-10 Thread Heston James - Cold Beans

 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?

Cheers,

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: Connecting to MySQL

2008-07-10 Thread Rick Morrison

 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?


0.5 is still in beta, and I don't have much experience with it myself, but
if were just starting out, I would probably be using that, otherwise you'll
need to migrate later; it's easier to just start out with the new API.




 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?


Yes, check out mapper extensions in the docs, you're going to want
after_insert and after_update extensions.

--~--~-~--~~~---~--~~
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: Connecting to MySQL

2008-07-10 Thread jason kirtland

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()))

You can set both default= and onupdate= on the same Column if you want
'updated' to be non-NULL on insert.

--~--~-~--~~~---~--~~
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: Connecting to MySQL

2008-07-10 Thread Lukasz Szybalski

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.

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