class Buyer(db.Model): # purchaser info __tablename__ = 'order_purchaser' id = db.Column(db.Integer, primary_key=True) purchaser = db.Column(db.String(255),unique=True) contact = db.Column(db.String(255),unique=True) def __repr__(self): return '<Purchaser name:%r contact:%r>' % (self.purchaser,self.contact)
class User(db.Model): # pylint: disable=too-few-public-methods """ Abstract model for users """ __abstract__ = True user_id = db.Column(db.Integer, primary_key=True) first_name = db.Column(db.String(50), nullable=False) last_name = db.Column(db.String(50), nullable=False)
class Creator(db.Model): # creator info __tablename__ = 'stock_creator' id = db.Column(db.Integer, primary_key=True) creator = db.Column(db.String(255), unique=True) contact = db.Column(db.String(255), unique=True) def __repr__(self): return '<Creator name:%r contact:%r>' % (self.creator, self.contact)
class Order(db.Model): # order info __tablename__ = 'order_info' id = db.Column(db.Integer,primary_key=True) userId = db.Column(db.Integer, unique=True) dateTime = db.Column(db.DateTime, unique=True) productType = db.Column(db.String(255),unique=True) productName = db.Column(db.String(255),unique=True) productDescription = db.Column(db.String(255),unique=True) platform = db.Column(db.String(255),unique=True) stockId = db.Column(db.Integer, unique=True) note = db.Column(db.String(255),unique=True) isActive = db.Column(db.Integer,unique=True) def __repr__(self): return '<Order id:%r name:%r sku:%r>' % (self.id,self.productName,self.productDescription)
class UserModel(db.Model): __tablename__ = 'users' __table_agrs__ = {"extend_eisting": True} # 如果表已经被创建过,需要加这个参数提供扩展 id = db.Column(db.Integer, primary_key=True, autoincrement=True) username = db.Column(db.String(120), unique=True, nullable=False, info="用户名") password = db.Column(db.String(120), nullable=False, info="密码") def save_to_db(self): '''创建实例,调用save_to_db保存数据''' db.session.add(self) db.session.commit() @classmethod def find_by_username(cls, username): '''调用类方法,按username查询用户信息''' return cls.query.filter_by(username=username).first() @classmethod def return_all(cls): '''返回所有的用户''' def to_json(x): return {'username': x.username, 'password': x.password} return { "user": list(map(lambda x: to_json(x), UserModel.query.all())) } # 直接用to_json @classmethod def delete_all(cls): try: num_rows_delete = db.session.query(cls) db.session.commit() return {'message': f"{num_rows_delete} row(s) deleted"} except: return {'message': "Someting went wrong"} @staticmethod def generate_hash(password): return sha256.hash(password) @staticmethod def verify_hash(password, hash): return sha256.verify(password, hash)
class UserPhoneModel(db.Model): __tablename__ = 'user_phone' id = db.Column(db.Integer, primary_key=True) phone_number = db.Column(db.String(128)) is_confirmed = db.Column(db.Boolean, default=False, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) user = db.relationship('UserModel')
class UserEmailModel(db.Model): __tablename__ = 'user_email' id = db.Column(db.Integer, primary_key=True) email_address = db.Column(db.String(128)) is_confirmed = db.Column(db.Boolean, default=False, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) user = db.relationship('UserModel')
class ProjectModel(db.Model): __tablename__ = 'adam_project' __table_agrs__ = {"extend_eisting": True} # 如果表已经被创建过,需要加这个参数提供扩展 project_id = db.Column(db.Integer, primary_key=True, autoincrement=True, info='项目id') project_name = db.Column(db.String(120), nullable=False, info="项目名称") project_v = db.Column(db.String(30), nullable=False, info="项目版本") project_desc = db.Column(db.String(500), nullable=False, info="项目描述") user_id = db.Column(db.Integer, nullable=False, info="所属用户") create_time = db.Column(db.DateTime, default=datetime.datetime.now, nullable=False, info="项目创建时间") updata_time = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, nullable=False, info="项目更新时间") project_state = db.Column(db.Integer, nullable=False, default=0, info="项目状态0进行中1项目暂停2项目结束") delete_sign = db.Column(db.Integer, nullable=False, default=0, info="项目删除标志") def save_to_db(self): '''创建实例,调用save_to_db保存数据''' db.session.add(self) db.session.commit() @classmethod def find_by_project_name(cls, project_name): '''调用类方法,按username查询用户信息''' return cls.query.filter( cls.project_name.like("%" + project_name + "%") if project_name is not None else "").all
class HostModel(db.Model): __tablename__ = 'adam_host' __table_agrs__ = {"extend_eisting": True} # 如果表已经被创建过,需要加这个参数提供扩展 host_id = db.Column(db.Integer, primary_key=True, autoincrement=True, info='主机id') project_id = db.Column(db.Integer, nullable=False, info="所属项目id") host_name = db.Column(db.String(120), nullable=False, info="名称") host_addr = db.Column(db.String(120), nullable=False, info="域名") host_desc = db.Column(db.String(500), info="描述") user_id = db.Column(db.Integer, nullable=False, info="所属用户") delete_sign = db.Column(db.Integer, nullable=False, default=0, info="主机删除标志") def save_to_db(self): '''创建实例,调用save_to_db保存数据''' id = db.session.add(self) db.session.commit() return id
class RevokedTokenModel(db.Model): __tablename__ = 'revoked_tokens' __table_args__ = {"extend_existing": True} id = db.Column(db.Integer, primary_key=True) jti = db.Column(db.String(120)) def add(self): db.session.add(self) db.session.commit() @classmethod def is_jti_blacklisted(cls, jti): query = cls.query.filter_by(jti=jti).first() return bool(query)
class UserModel(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(128)) is_active = db.Column(db.Boolean, default=True, nullable=False)