當前位置: 首頁>>代碼示例>>Python>>正文


Python SQLAlchemy.drop_all方法代碼示例

本文整理匯總了Python中flaskext.sqlalchemy.SQLAlchemy.drop_all方法的典型用法代碼示例。如果您正苦於以下問題:Python SQLAlchemy.drop_all方法的具體用法?Python SQLAlchemy.drop_all怎麽用?Python SQLAlchemy.drop_all使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在flaskext.sqlalchemy.SQLAlchemy的用法示例。


在下文中一共展示了SQLAlchemy.drop_all方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: from flaskext.sqlalchemy import SQLAlchemy [as 別名]
# 或者: from flaskext.sqlalchemy.SQLAlchemy import drop_all [as 別名]
def main():
    global app, db, web, database, pages
    parser = OptionParser()
    parser.add_option("-t", "--test-all", action="store_true", default=False, dest="test_all", help="Run all the tests.")
    parser.add_option("-d", "--test-db", action="store_true", default=False, dest="test_db", help="Run the database tests.")
    parser.add_option("-w", "--test-web", action="store_true", default=False, dest="test_web", help="Run the web tests.")
    parser.add_option("-r", "--reset-db", action="store_true", default=False, dest="reset_db", help="Reset the database.")
    parser.add_option("-s", "--script", metavar="SCRIPT", dest="script", default=None)
    parser.add_option("--server",  action="store_true", default=False, dest="start_server", help="Run the test webserver.")
    (options, args) = parser.parse_args()
    
    if options.test_all or options.test_db or options.test_web:
        app = Flask(__name__.split('.')[0])
        app.config['TESTING'] = True
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
        db = SQLAlchemy(app)
        suite = unittest.TestSuite()
        if options.test_all or options.test_db:
            import tests.database
            suite.addTest(tests.database.suite)
        if options.test_all or options.test_web:
            import tests.web
            suite.addTest(tests.web.suite)
        unittest.TextTestRunner(verbosity=2).run(suite)
    elif options.script is not None:
        app = Flask(__name__.split('.')[0])
        app.config.from_object(config.FlaskConfig)
        db = SQLAlchemy(app)
        import scripts
        scripts = scripts.load_scripts()
        if options.script in scripts:
            scripts[options.script].main()
    elif options.reset_db or options.start_server:
        # Setup the application and database
        app = Flask(__name__.split('.')[0])
        app.config.from_object(config.FlaskConfig)
        app.jinja_env.add_extension('jinja2.ext.do')
        db = SQLAlchemy(app)
        import database
        import web
        if options.reset_db:
            db.drop_all()
            db.create_all()
            dataset.populate()
            print 'Database reset.'
            exit(0)
        import pages
        app.run(host='0.0.0.0', port=config.dev_port, use_reloader=True)
    else:
        parser.print_help()
開發者ID:gclawes,項目名稱:eecis-accounts,代碼行數:52,代碼來源:__init__.py

示例2: Group

# 需要導入模塊: from flaskext.sqlalchemy import SQLAlchemy [as 別名]
# 或者: from flaskext.sqlalchemy.SQLAlchemy import drop_all [as 別名]
class Group(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), unique=True, nullable=False)

    users = db.relationship("User", secondary=user_group,
        backref=db.backref("groups", lazy='dynamic'))

    def __unicode__(self):
        return unicode(self.name)

    def __repr__(self):
        return '<Group %r>' % self.name


db.drop_all()
db.create_all()

group = Group(name="admin")
db_session.add(group)
company = Company(name="My company")
db_session.add(company)
db_session.commit()


UserForm = model_form(User, db_session, exclude=['password'])


class UserForm(UserForm):
    # Embeds OneToOne as FormField
    profile = wtforms.FormField(
開發者ID:Anioko,項目名稱:Flask-Dashed,代碼行數:32,代碼來源:sqlalchemy_backend.py

示例3: Category

# 需要導入模塊: from flaskext.sqlalchemy import SQLAlchemy [as 別名]
# 或者: from flaskext.sqlalchemy.SQLAlchemy import drop_all [as 別名]

class Category(db.Model):
    __tablename__ = 'fk_category'
    id = db.Column(db.Integer,primary_key = True)
    name = db.Column(db.String(50))

    def __init__(self,name):
        self.name = name

    def __repr__(self):
        return '<Category %r>' % self.name


# 新建或生成所有模型數據表
db.drop_all();
db.create_all()

#添加

user = User('test','[email protected]')
user1 = User('test1','[email protected]')

db.session.add(user)
db.session.add(user1)
db.session.commit()

#查找
users = User.query.all()
for u in users :
    print u
開發者ID:ajaxj,項目名稱:pyweb,代碼行數:32,代碼來源:test.py


注:本文中的flaskext.sqlalchemy.SQLAlchemy.drop_all方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。