Some of the information here may be outdated, please check the book instead
[edit]

Many people ask if they can use the web2py Database Abstraction Layer without using the framework.

Yes, this is possible, assuming you have the proper database drivers (psycopg2 for PostgreSQL, mysqldb for MySQL, cs_oracle for Oracle, pyodbc for MSSQL, DB2, FireBird)

  • Download the web2py source
  • Move the gluon folder into the Python/lib/site-packages folder
  • use it

Example:

from gluon.sql import DAL, Field
db=DAL('postgres://username:password@localhost/database')

db.define_table('friend',Field('name'))
print db.tables

db.field.insert(name='Tim')
print db.friend.fields

for row in db().select(db.friend.name,orderby=db.friend.name):
    print row.name

You can also use it in the google app engine

db=DAL('gae')

read more

download code

© 2008-2010 by Massimo Di Pierro - All rights reserved - Powered by web2py - design derived from a theme by the earlybird
The content of this book is released under the Artistic License 2.0 - Modified content cannot be reproduced.