Module kibicara.model
ORM Models for core.
Expand source code
# Copyright (C) 2020 by Thomas Lindner <tom@dl6tom.de>
# Copyright (C) 2020 by Cathy Hu <cathy.hu@fau.de>
#
# SPDX-License-Identifier: 0BSD
""" ORM Models for core. """
from databases import Database
from kibicara.config import config
from ormantic import Boolean, Integer, ForeignKey, Model, Text
from sqlalchemy import create_engine, MetaData
class Mapping:
database = Database(config['database_connection'])
metadata = MetaData()
@classmethod
def create_all(cls):
engine = create_engine(str(cls.database.url))
cls.metadata.create_all(engine)
@classmethod
def drop_all(cls):
engine = create_engine(str(cls.database.url))
cls.metadata.drop_all(engine)
class Admin(Model):
id: Integer(primary_key=True) = None
email: Text(unique=True)
passhash: Text()
class Mapping(Mapping):
table_name = 'admins'
class Hood(Model):
id: Integer(primary_key=True) = None
name: Text(unique=True)
landingpage: Text()
email_enabled: Boolean() = True
class Mapping(Mapping):
table_name = 'hoods'
class AdminHoodRelation(Model):
id: Integer(primary_key=True) = None
admin: ForeignKey(Admin)
hood: ForeignKey(Hood)
class Mapping(Mapping):
table_name = 'admin_hood_relations'
class Trigger(Model):
id: Integer(primary_key=True) = None
hood: ForeignKey(Hood)
pattern: Text()
class Mapping(Mapping):
table_name = 'triggers'
class BadWord(Model):
id: Integer(primary_key=True) = None
hood: ForeignKey(Hood)
pattern: Text()
class Mapping(Mapping):
table_name = 'badwords'
Classes
class Admin (**data)
-
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Expand source code
class Admin(Model): id: Integer(primary_key=True) = None email: Text(unique=True) passhash: Text() class Mapping(Mapping): table_name = 'admins'
Ancestors
- ormantic.models.Model
- pydantic.main.BaseModel
- pydantic.utils.Representation
Class variables
var Mapping
var email : ormantic.fields.Text
var id : ormantic.fields.Integer
var passhash : ormantic.fields.Text
Instance variables
var objects
-
Expand source code
def __get__(self, instance, owner): return self.__class__(model_cls=owner)
class AdminHoodRelation (**data)
-
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Expand source code
class AdminHoodRelation(Model): id: Integer(primary_key=True) = None admin: ForeignKey(Admin) hood: ForeignKey(Hood) class Mapping(Mapping): table_name = 'admin_hood_relations'
Ancestors
- ormantic.models.Model
- pydantic.main.BaseModel
- pydantic.utils.Representation
Class variables
var Mapping
var admin : ormantic.fields.ForeignKey
var hood : ormantic.fields.ForeignKey
var id : ormantic.fields.Integer
Instance variables
var objects
-
Expand source code
def __get__(self, instance, owner): return self.__class__(model_cls=owner)
class BadWord (**data)
-
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Expand source code
class BadWord(Model): id: Integer(primary_key=True) = None hood: ForeignKey(Hood) pattern: Text() class Mapping(Mapping): table_name = 'badwords'
Ancestors
- ormantic.models.Model
- pydantic.main.BaseModel
- pydantic.utils.Representation
Class variables
var Mapping
var hood : ormantic.fields.ForeignKey
var id : ormantic.fields.Integer
var pattern : ormantic.fields.Text
Instance variables
var objects
-
Expand source code
def __get__(self, instance, owner): return self.__class__(model_cls=owner)
class Hood (**data)
-
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Expand source code
class Hood(Model): id: Integer(primary_key=True) = None name: Text(unique=True) landingpage: Text() email_enabled: Boolean() = True class Mapping(Mapping): table_name = 'hoods'
Ancestors
- ormantic.models.Model
- pydantic.main.BaseModel
- pydantic.utils.Representation
Class variables
var Mapping
var email_enabled : ormantic.fields.Boolean
var id : ormantic.fields.Integer
var landingpage : ormantic.fields.Text
var name : ormantic.fields.Text
Instance variables
var objects
-
Expand source code
def __get__(self, instance, owner): return self.__class__(model_cls=owner)
class Mapping
-
Expand source code
class Mapping: database = Database(config['database_connection']) metadata = MetaData() @classmethod def create_all(cls): engine = create_engine(str(cls.database.url)) cls.metadata.create_all(engine) @classmethod def drop_all(cls): engine = create_engine(str(cls.database.url)) cls.metadata.drop_all(engine)
Subclasses
- Admin.Mapping
- AdminHoodRelation.Mapping
- BadWord.Mapping
- Hood.Mapping
- Trigger.Mapping
- Email.Mapping
- EmailSubscribers.Mapping
- Telegram.Mapping
- TelegramUser.Mapping
- Test.Mapping
- Twitter.Mapping
Class variables
var database
var metadata
Static methods
def create_all()
-
Expand source code
@classmethod def create_all(cls): engine = create_engine(str(cls.database.url)) cls.metadata.create_all(engine)
def drop_all()
-
Expand source code
@classmethod def drop_all(cls): engine = create_engine(str(cls.database.url)) cls.metadata.drop_all(engine)
class Trigger (**data)
-
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Expand source code
class Trigger(Model): id: Integer(primary_key=True) = None hood: ForeignKey(Hood) pattern: Text() class Mapping(Mapping): table_name = 'triggers'
Ancestors
- ormantic.models.Model
- pydantic.main.BaseModel
- pydantic.utils.Representation
Class variables
var Mapping
var hood : ormantic.fields.ForeignKey
var id : ormantic.fields.Integer
var pattern : ormantic.fields.Text
Instance variables
var objects
-
Expand source code
def __get__(self, instance, owner): return self.__class__(model_cls=owner)