Markus Jais wrote:
> Hola
>
> I have another SQLObject question.
>
> this is my code:
> ---
> from sqlobject import *
>
> class Author(SQLObject):
>
> firstName = StringCol()
> lastName = StringCol()
>
> class AuthorTable:
>
> def __init__(self, connection):
> Author._connection = connection
> Author.createTable(ifNotExists=True)
>
>
> def createAuthorTable(connection):
> AuthorTable(connection)
>
>
>
> createAuthorTable(connectionForURI('mysql://markus:eagle@localhost/books'))
>
> a1 = Author(firstName = "J.R.R.", lastName =
> "Tolkien")
Yes, this is fine -- you can assign to ._connection as you set up the
classes. The AuthorTable class seems a little odd to me -- I'd probably
do it more like:
tableClasses = [Author]
def createTables(connection):
for tableClass in tableClasses:
tableClass._connection = connection
tableClass.createTable(ifNotExists=True)
But maybe that's just a matter of taste.
> the reason for this is that I want a generic modul
> about authors and I want to specify the connection
> Object at runtime, for example when I want
> to use PostgreSQL.
>
> the code works but I would like to know
> if it has any flaws I do not see.
>
> the reason for my question is, that I am
> preparing an article about Object Relational Mapping
> in Python for a german magazine. and
> the main focus will be on SQLObject with 2 or
> 3 simple Examples.
> I really like SQLObject and maybe the article
> helps to get more people interested in SQLObject.
> and I do not want to have any serious errors
> in my examples.
Cool, if you want to run any other scripts by, please do.
--
Ian Bicking / ia...@co... / http://blog.ianbicking.org
|