def initdb(drop): """Initialize the database.""" if drop: click.confirm('This operation will delete the database, do you want to continue?', abort=True) db.drop_all() click.echo('Drop tables.') db.create_all() click.echo('Initialized database.')
def initdb(drop): ''' initialize the database''' if drop: click.confirm('this operation will delete the database', abort=True) db.drop_all() click.echo('drop tables') db.create_all() click.echo('initialized database')
def insert_data(): db.drop_all() db.create_all() admin_role = Role(name='Admin') mod_role = Role(name='Moderator') user_role = Role(name='User') user_john = User(username='******', role=admin_role) user_susan = User(username='******', role=user_role) user_david = User(username='******', role=user_role) db.session.add_all( [admin_role, mod_role, user_role, user_john, user_susan, user_david]) db.session.commit()
def forge(count): ''' generate fake messages''' db.drop_all() db.create_all() click.echo("working...") for i in range(count): message = Message(name=fake.name(), body=fake.sentence(), age=fake.age(), score=fake.score(), timestamp=fake.date_time_this_year()) db.session.add(message) db.session.commit() click.echo('created %d fake messages' % count)
def forge(count): """Generate fake messages.""" from faker import Faker db.drop_all() db.create_all() fake = Faker() click.echo('Working...') for i in range(count): message = Message( name=fake.name(), body=fake.sentence(), timestamp=fake.date_time_this_year() ) db.session.add(message) db.session.commit() click.echo('Created %d fake messages.' % count)
def tearDown(self): db.drop_all()
def tearDown(self): db.session.remove() db.drop_all()
# !/usr/bin/env python # -*- coding: utf-8 -*- # Author : 湛允鹏 # Link : from hello import db from hello import User, Role db.drop_all() db.create_all() admin_role = Role(name='Admin') mod_roel = Role(name='Moderator') user_role = Role(name='User') user_john = User(username='******', role=admin_role) user_susan = User(username='******', role=user_role) user_steve = User(username='******', role=user_role) db.session.add_all( [admin_role, mod_roel, user_role, user_john, user_susan, user_steve]) db.session.commit() print(admin_role.id) print(mod_roel.id) print(user_role.id) admin_role.name = 'Administrator' db.session.add(admin_role) db.session.commit() db.session.delete(mod_roel) db.session.commit()
from hello import db from flask_sqlalchemy import SQLAlchemy from model import * db.drop_all() db.create_all() bob = User('Bob', 'Hello this is Bob') db.session.add(bob) db.session.commit() #action below image1 = PhotoInfo('Splash', 'Los Altos', '2013', 'IMG_9696.jpg', 'action') db.session.add(image1) db.session.commit() image2 = PhotoInfo('Chasing Yellow', 'Los Altos', '2013', 'IMG_9715.jpg', 'action') db.session.add(image2) db.session.commit() #nature below image3= PhotoInfo('Water crown', 'Oahu', '2014', 'IMG_1061.jpg', 'nature') db.session.add(image3) db.session.commit() image4= PhotoInfo('(unknown)', 'Oahu', '2014', 'IMG_1116.jpg', 'nature') db.session.add(image4) db.session.commit()
def tearDown(self): db.session.remove() db.drop_all() self.app_context.pop()