On 25/12/2007, Anand Chitipothu <[EMAIL PROTECTED]> wrote: > > > 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.
http://www.sqlalchemy.org/ does stuff like that. There's something slightly nasty about specifying the schema like that, because when you read it you have to 'translate' the declarative Python code to SQL in your head in order to understand it. It should be possible to write schemas using a safe, vendor neutral subset of SQL, and if there are many features you can't get that way, maybe a translator from some kind of neutral SQL to the variants supported by all the different vendors would be a nice thing to have (and useful beyond just web.py and even Python). Tom 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? > > > > -- Tom Berger http://intellectronica.net/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
