Skip to content

Instantly share code, notes, and snippets.

@zs1621
Created March 29, 2014 05:00
Show Gist options
  • Save zs1621/9848784 to your computer and use it in GitHub Desktop.
Save zs1621/9848784 to your computer and use it in GitHub Desktop.
first run this script in pony-0.4.9 and then change `db.generate_mapping(create_tables=True)` to `db.generate_mapping()` and run it in pony-0.5-beta
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# Author : Rhapsodyzs
# E-mail : zs1213yh@gmail.com
# Date : 14/03/29 10:49:44
# Desc : Test pony-orm 0.5.0-beta
#
from decimal import Decimal
from pony.orm import *
import MySQLdb
import time
db_name = 'ttwalkout'
db_user = '***'
db_pass = '****'
m = MySQLdb.Connect(host='localhost', user=db_user, passwd=db_pass)
c = m.cursor()
try:
c.execute("create database %s" %db_name)
c.execute("grant all privileges on %s.* to %s'localhost' indetified by '%s'" %(db_name, db_user, db_pass))
c.execute("flush privileges")
c.close()
m.commit()
m.close()
except:
pass
db = Database("mysql", 'localhost', db_user, db_pass, db_name)
class User(db.Entity):
uid = PrimaryKey(int, auto=True)
name = Required(unicode, 30, unique=True)
avatar = Optional(unicode, 400)
bodystatus = Set('BodyStatus')
class BodyStatus(db.Entity):
blood_pressure = Optional(int)
bust = Optional(int)
color_vision = Optional(Decimal, 3, 1)
height = Optional(int)
weight = Optional(Decimal, 5, 2)
left_eye = Optional(Decimal, 2, 1)
right_eye = Optional(Decimal, 2, 1)
lung_capacity = Optional(int)
date = Required(Decimal, 13, 3, default = time.time())
user = Required(User)
sql_debug(True)
db.generate_mapping(create_tables=True) # sencod run put off `create_tables=True`
def populate_database():
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment