from peewee import (Model, # SqliteDatabase, CharField, BooleanField, IntegerField, ForeignKeyField, TextField) from playhouse.apsw_ext import APSWDatabase from gutenbergtozim import logger # db = SqliteDatabase('gutenberg.db') timeout = 1000 * 60 * 5 * 16 db = APSWDatabase('gutenberg.db', pragmas=( ('journal_mode', 'WAL'), ('cache_size', 10000), ('mmap_size', 1024 * 1024 * 32)), timeout=timeout) db.connect() db.execute_sql("PRAGMA journal_mode=WAL;") class BaseModel(Model): @classmethod def get_or_none(cls, *query, **kwargs): try: return cls.get(*query, **kwargs) except cls.DoesNotExist: return None class License(BaseModel): class Meta: database = db
from gutenbergtozim import logger # db = SqliteDatabase('gutenberg.db') timeout = 1000 * 60 * 5 * 16 db = APSWDatabase( "gutenberg.db", pragmas=( ("journal_mode", "WAL"), ("cache_size", 10000), ("mmap_size", 1024 * 1024 * 32), ), timeout=timeout, ) db.connect() db.execute_sql("PRAGMA journal_mode=WAL;") class BaseModel(Model): @classmethod def get_or_none(cls, *query, **kwargs): try: return cls.get(*query, **kwargs) except cls.DoesNotExist: return None class License(BaseModel): class Meta: database = db fixtures = [
on_delete='RESTRICT', primary_key=True) value = DecimalField(verbose_name='Rank for Place', decimal_places=2) class Quality(ObraModel): """ Race Quality figures for a Race """ race = ForeignKeyField(verbose_name='Quality Race', model=Race, backref='quality', on_update='RESTRICT', on_delete='RESTRICT') value = DecimalField(verbose_name='Race Quality', decimal_places=2) points_per_place = DecimalField(verbose_name='Points per Place', decimal_places=2) with db.connection_context(): db.create_tables([ Series, Event, Race, Person, ObraPersonSnapshot, PendingUpgrade, Result, Points, Rank, Quality ], fail_silently=True) try: db.execute_sql('VACUUM') except Exception as e: logger.warn('Failed to vacuum database: {}'.format(e))