#! /usr/bin/env python
#coding=utf-8
#同时创建表,类,和做map绑定
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import *
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column(String)
fullname = Column(String)
password = Column(String)
def __init__(self, id,name, fullname, password):
self.id = id
self.name = name
self.fullname = fullname
self.password = password
def __repr__(self):
return "" % (self.name, self.fullname, self.password)
users_table = User.__table__
metadata = Base.metadata
engine = create_engine("sqlite:///test.db",echo=True)
# 创建表
metadata.create_all(engine)
#生成个对象也是插入一条记录
oneUser = User(1,'david','davidmiao','123')
#oneUser
print oneUser.fullname
阅读(636) | 评论(0) | 转发(0) |