Many times I felt the need to specify database schema in a DB neutral
way, so that the application I am building can be used with any
database.
I think web.py should have some way to do this.

Here is my proposal.

    # schema.py
    from web.schema import Schema, Table, Column, Unique, types, constants

    blog_table = Table('blog',
        Column('id', types.integer, primary_key=True),
        Column('title', types.varchar(100), default='My Blog'),
        Column('subtitle', types.varchar(100), default='Yet another blog'),
        Column('url', types.varchar(100)),
    )

    post_table = Table('post',
        Column('id', types.integer, primary_key=True),
        Column('blog_id', types.integer, references='blog.id')
        Column('title', types.varchar(100)),
        Column('body', types.text),
        Column('created', types.timestamp, default=constants.utc_now),
    )

    # if I want to use session from web.py
    from web.session import session_table

    schema = Schema(blog_table, post_table, session_table)

    if __name__ == "___main__":
        import sys
        print schema.query(sys.argv[1])

This schema script can be used to allow schema for any database engine.

    $ python schema.py postgres
     postgres schema...
    $ python schema.py postgres | psql mydbname
    $ python schema.py mysql | mysql mydbname

It is extensible. If you don't find something you need, you can define your own.

   from web.schema import DataType
   inet = DataType(postgres='inet', mysql='text', sqlite='text')

What do you think?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to