def migrate(): old_matches = list(Match_2018_06_26.select().order_by(Match_2018_06_26.id)) print('old matches: {}'.format(old_matches)) def convert_match(old_match): return Match(winner_handle=old_match.winner.slack_id, winner_score=old_match.winner_score, loser_handle=old_match.loser.slack_id, loser_score=old_match.loser_score, pending=old_match.pending, played=old_match.played) new_matches = [convert_match(old_match) for old_match in old_matches] print('new matches (not yet committed): {}'.format(new_matches)) print('dropping old Match table') db.drop_tables([Match_2018_06_26]) print('dropping old Player table') db.drop_tables([Player_2018_06_26]) print('creating new Match table') Match.create_table() print('saving new matches') for new_match in new_matches: new_match.save()
def db_connection(): memdb = CountingSqliteDatabase(":memory:") models = [User, Post, Follow, Like] db.initialize(memdb) db.connect() db.create_tables(models) yield memdb db.drop_tables(models) db.close()
def cleanDB(): try: db.drop_tables([Site]) except OperationalError: pass #utilities.logger.debug('Site table did non exists') try: db.drop_tables([User]) except OperationalError: pass
def use_db(): db.connect() db.drop_tables(app_models) db.create_tables(app_models) yield db db.close()
def delete_tables(): '''テーブルを削除する ''' db.connect() db.drop_tables([Location]) db.close()
def _drop_tables(): with db: db.drop_tables(MODELS)
def drop_tables(): db.connect() db.drop_tables([Athlete, Team, Game, Play, Collaboration, Action, Observation]); db.close()
u['id'] = int(user['id']) u['create_'] = ingest_timestring(user['create_']) u['update_'] = ingest_timestring(user['update_']) u['tt'] = {} u['tt']['code'] = user['config'].get('tt_code', "") u['timers'] = {} u['xp'] = {} u['xp']['amount'] = user['config'].get('xp', 0) u['currency'] = {} u['fun'] = {} ujson.append(u) pprint(ujson[0]) pprint(sjson[1]) with db.atomic(): db.drop_tables([Server, User]) with db.atomic(): db.create_tables([Server, User]) with db.atomic(): Server.insert_many(sjson).execute() with db.atomic(): User.insert_many(ujson).execute() user = User.get_by_id(305879281580638228) print(user.__class__) pprint(user.xp) pprint(user.create_)
def recreate_tables(): with db: db.drop_tables([User, List, Item]) db.create_tables([User, List, Item])
def tearDown(self): db.drop_tables([Game, LetterGuessed])
import controller from flask import Flask, jsonify, request from models import db, Product, ProductHistory app = Flask(__name__) db.connect() db.drop_tables([Product, ProductHistory]) db.create_tables([Product, ProductHistory]) @app.route('/') def hello(): return jsonify({'hello': 'world'}) @app.route('/products/') def products(): products = Product.select() return jsonify({ 'products': [p.to_dict() for p in products], 'count': products.count() }) @app.route('/products/<string:upc>/', methods=['GET']) def product(upc): product = controller.get_product(upc) if product: return jsonify(product.to_dict())
def dropdb(): """Clear database""" db.drop_tables(MODELS) click.echo('Dropped the database') if os.path.isfile(USER_SECRET_FILE): os.remove(USER_SECRET_FILE)
import os import base64 from models import db, Donor, Donation # noqa F403 from peewee import * # noqa F403 import logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) try: db.connect() db.drop_tables([Donor, Donation]) # noqa F403 db.create_tables([Donor, Donation]) # noqa F403 logger.info('Drop and create tables.') except Exception as e: logger.info(e) finally: db.close() def add_people(): FIRST_NAME = 0 LAST_NAME = 1 donors = [('Jim', 'Halpert'), ('Pam', 'Beesley'), ('Dwight', 'Shrute'), ('Michael', 'Scott'), ('Andy', 'Bernard')] try: db.connect()