Esempio n. 1
0
    grade: int
    metadata: Dict[str, str]


class Submission_db(Model):
    learning_unit = IntegerField()
    slack_id = TextField()
    grade = IntegerField()
    metadata = JSONField()

    class Meta:
        database = DB
        primary_key = CompositeKey('learning_unit', 'slack_id')


DB.create_tables([Submission_db], safe=True)

app = FastAPI()


# This hook ensures that a connection is opened to handle any queries
# generated by the request .
@app.on_event("startup")
def startup():
    DB.connect(reuse_if_open=True)


# This hook ensures that the connection is closed when we've finished
# processing the request.
@app.on_event("shutdown")
def shutdown():
Esempio n. 2
0
                                       server_side_cursors=True,
                                       max_connections=2000,
                                       stale_timeout=300)  # 5 min

logger = logging.getLogger('snap.models')
logger.setLevel(logging.ERROR)


class Jobs(peewee.Model):
    title = peewee.CharField()
    category = peewee.CharField()
    status = peewee.CharField()
    location = peewee.CharField()

    class Meta:
        database = database
        primary_key = False
        schema = 'schema_snap'


if __name__ == "__main__":

    # Connect to our database.
    database.connect()
    # Create schemas
    try:
        database.create_tables([Jobs], safe=True)
    except peewee.OperationalError as e:
        logger.warn('Creating db scheme. Failed to create table Jobs'
                    ' or it already exist.')