60 lines
2.2 KiB
Python
60 lines
2.2 KiB
Python
from sqlalchemy import Table, Column, String, MetaData, ForeignKey, JSON
|
|
from sqlalchemy.sql import select, func
|
|
from sqlalchemy.types import Integer, BigInteger, String, Boolean, TIMESTAMP, Numeric
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
from biopro.db.base import Session
|
|
|
|
from .base import Base
|
|
|
|
class SubjectData(Base):
|
|
__tablename__ = "subject_datas"
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
subject_id = Column(Integer)
|
|
mode = Column(JSONB)
|
|
data = Column(JSONB)
|
|
user_auth = Column(JSONB)
|
|
meta = Column(String(255))
|
|
project = Column(String(255))
|
|
deleted = Column(Boolean)
|
|
created_at = Column(TIMESTAMP(timezone=True), server_default=func.now())
|
|
updated_at = Column(TIMESTAMP(timezone=True), onupdate=func.now())
|
|
|
|
@classmethod
|
|
def create_subject_data(cls, subject_id, project, meta, data):
|
|
with Session() as session:
|
|
subject = SubjectData(
|
|
subject_id = subject_id,
|
|
project = project,
|
|
meta= meta,
|
|
data = data
|
|
)
|
|
session.add(subject)
|
|
session.commit()
|
|
return subject
|
|
|
|
# @classmethod
|
|
# def check_name_duplicate(cls, collection_name, parent, n):
|
|
# with Session() as session:
|
|
# result = session.query(Collection).filter(Collection.name == cls.generate_name(collection_name, n), Collection.parent == parent).first()
|
|
# if result is None:
|
|
# return cls.generate_name(collection_name, n)
|
|
# else:
|
|
# new_num = n + 1
|
|
# # new_name = f"{collection_name}({new_num})"
|
|
# return cls.check_name_duplicate(collection_name, parent, new_num)
|
|
|
|
# @classmethod
|
|
# def generate_name(cls, collection_name, n):
|
|
# if n==0:
|
|
# return collection_name
|
|
# else:
|
|
# return f"{collection_name}({n})"
|
|
|
|
# @classmethod
|
|
# def find_collection(cls, collection_name, parent):
|
|
# with Session() as session:
|
|
# result = session.query(Collection).filter(Collection.name == collection_name, Collection.parent == parent).first()
|
|
# return result
|
|
|
|
|