Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 11 and Version 12 of UsingSqlAlchemy


Ignore:
Timestamp:
06/04/06 00:53:08 (13 years ago)
Author:
anonymous
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UsingSqlAlchemy

    v11 v12  
    2929This document covers the 0.1.0 release and was written on February 13, 2006. 
    3030 
    31 Getting SQLAlchemy 
    32 ------------------ 
     31== Getting SQLAlchemy == 
     32 
    3333SQLAlchemy made its first public release (0.1.0) on February 13, 2006. You can 
    3434get it from the cheeseshop:: 
     
    5454the main SQLAlchemy docs. This document only covers points relevant to TG. 
    5555 
    56 Configuration 
    57 ------------- 
     56== Configuration == 
     57 
    5858This section describes how to set up SQLAlchemy so that it will use a seperate 
    5959config in development and production mode. 
     
    6464from one of the uris shown below:: 
    6565 
    66   !sqlite://filename=querytest.db 
    67   !sqlite://filename=:memory: 
    68   !postgres://database=test&host=localhost&user=scott&password=tiger 
    69   !mysql://db=test&host=localhost&user=scott&passwd=tiger 
    70   !mysql://db=test&unix_socket=/tmp/foo.socket&user=scott&passwd=tiger 
    71   !oracle://dsn=mydsn&user=scott&passwd=tiger 
     66 * !sqlite://filename=querytest.db 
     67 * !sqlite://filename=:memory: 
     68 * !postgres://database=test&host=localhost&user=scott&password=tiger 
     69 * !mysql://db=test&host=localhost&user=scott&passwd=tiger 
     70 * !mysql://db=test&unix_socket=/tmp/foo.socket&user=scott&passwd=tiger 
     71 * !oracle://dsn=mydsn&user=scott&passwd=tiger 
    7272 
    7373And insert the following into your ``devcfg.py`` and ``prodcfg.py`` files:: 
    74  
     74{{{ 
     75#!python 
    7576  sqlalchemy.dburi = *<your connection uri>* 
    7677  sqlalchemy.echo = 0                        #Set to 1 for echo 
    77  
     78}}} 
    7879Now flip over to your ``<project>/model.py`` file and replace the contents 
    79 with:: 
    80  
     80with: 
     81{{{ 
     82#!python 
    8183  from sqlalchemy import * 
    8284  import cherrypy 
     
    8486  engine = create_engine(cherrypy.config.get('sqlalchemy.dburi'), 
    8587                         echo=cherrypy.config.get('sqlalchemy.echo',0)) 
     88}}} 
    8689 
    8790With those lines, you're ready to go. Keep everything SQLAlchemy related below 
    8891the engine declaration. 
    8992 
    90 Tips and Gotchas 
    91 ---------------- 
     93== Tips and Gotchas == 
     94 
    9295You may want to keep echo off by default and turn it on when you're debugging 
    9396in ``tg-admin shell`` by simply ``engine.echo = 1`` in the interpreter. 
     
    104107 
    105108 
    106 Custom Column Types 
    107 ------------------- 
     109== Custom Column Types == 
     110 
    108111SQLObject uses formencode to perform python to database conversions. This 
    109112shows how to use the SQLAlchemy column datatypes. Below are two examples, one 
     
    145148          return inet_ntoa(struct.pack('!L',super(IPV4,self).convert_result_value(value,engine)) 
    146149}}} 
    147 Future Developments 
    148 ------------------- 
     150 
     151== Future Developments == 
     152 
    149153 
    150154Jonathan LaCour is working on a declarative way of describing forms through