Beispiel #1
0
def prepare_db():
    from playhouse.sqliteq import SqliteQueueDatabase
    from cozy.db.artwork_cache import ArtworkCache
    from cozy.db.book import Book
    from cozy.db.offline_cache import OfflineCache
    from cozy.db.settings import Settings
    from cozy.db.storage import Storage
    from cozy.db.storage_blacklist import StorageBlackList
    from cozy.db.track import Track

    models = [
        Track, Book, Settings, ArtworkCache, Storage, StorageBlackList,
        OfflineCache
    ]

    print("Setup database...")

    db_path = '/tmp/cozy_test.db'
    test_db = SqliteQueueDatabase(db_path, pragmas=[('journal_mode', 'wal')])
    test_db.bind(models, bind_refs=False, bind_backrefs=False)
    test_db.connect()
    test_db.create_tables(models)
    test_db.stop()
    test_db.start()

    return db_path, models, test_db
Beispiel #2
0
def create_model(file_path, file_name):
    db = SqliteQueueDatabase(file_path + file_name + '.db')

    class BaseModel(Model):
        class Meta:
            database = db

    class Message(BaseModel):
        message_id = IntegerField()
        message_text = TextField()
        modified_text = TextField(null=True)
        posted = BooleanField(default=False)
        message_type = TextField()
        file_name = CharField(null=True)
        file_size = IntegerField(null=True)

    db.connect()
    db.create_tables([Message])

    return Message
        items_per_page: int = ERRORS_PER_PAGE,
        order_by: Field = None,
    ) -> List['User']:
        if not order_by:
            order_by = cls.date_time.desc()

        return cls.paginating(page=page,
                              items_per_page=items_per_page,
                              order_by=order_by)

    def get_short_title(self) -> str:
        date_time_str = get_date_time_str(self.date_time)
        return f'[{date_time_str}, {self.func_name}, {self.exception_class}] {self.error_text!r}'


db.connect()
db.create_tables([User, Chat, Quote, Comics, Request, Settings])

db_error.connect()
db_error.create_tables([Error])

if __name__ == '__main__':
    BaseModel.print_count_of_tables()
    print()

    from config import ADMIN_USERNAME
    admin: User = User.get(User.username == ADMIN_USERNAME[1:])
    print('Admin:', admin)
    # print(*Quote.get_user_unique_random(admin, limit=5), sep='\n')
    # print(*Quote.get_user_unique_random(admin, years=[2004], limit=5), sep='\n')
    # print(Quote.get_number_of_unique_quotes(admin))
Beispiel #4
0
from peewee import *
from playhouse.sqliteq import SqliteQueueDatabase

db = SqliteQueueDatabase('db.sqlite3',
                         use_gevent=False,  # Use the standard library "threading" module.
                         autostart=False,  # The worker thread now must be started manually.
                         queue_max_size=64)
ALAMER = "df548f-61ac83-624ea4"


class Items(Model):
    item_id = IntegerField()
    cost = IntegerField()

    class Meta:
        database = db


db.start()
db.connect()
# db.drop_tables([Items])
# db.create_tables([Items])
# db.stop()
Beispiel #5
0
        ("journal_mode", "wal"),
        ("ignore_check_constraints", 0),
        ("synchronous", "normal"),
    ],
)


class Users(peewee.Model):
    id = peewee.IntegerField(primary_key=True,
                             constraints=[peewee.Check(constraint="id > 0")])

    first_name = peewee.CharField(max_length=255)
    last_name = peewee.CharField(max_length=255, default=None, null=True)
    username = peewee.CharField(max_length=32, default=None, null=True)
    timestamp = peewee.DateTimeField(default=datetime.datetime.utcnow,
                                     null=False)
    # prevent forwards to master
    is_blocked = peewee.BooleanField(
        default=False,
        null=False,
        constraints=[peewee.Check(constraint="is_blocked BETWEEN 0 AND 1")],
    )

    class Meta:
        database = DB


DB.create_tables(models=[Users], safe=True)
DB.close()
DB.connect()