47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
'''
|
|
Tutorial link: https://docs.sqlalchemy.org/en/latest/orm/tutorial.html
|
|
Sqlalchemy version: 1.4.31
|
|
Python version: 3.10
|
|
'''
|
|
#!/usr/bin/python# -*- coding: utf-8 -*-
|
|
|
|
from datetime import datetime
|
|
# from config import db, ma
|
|
|
|
# import os
|
|
from sqlalchemy import (Column, Integer,
|
|
String, DateTime)
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.orm import session
|
|
from marshmallow import Schema
|
|
from db.pg_models import create_pg_session
|
|
from marshmallow_sqlalchemy import SQLAlchemyAutoSchema
|
|
|
|
Base = declarative_base()
|
|
|
|
|
|
class Person(Base):
|
|
""" Platform class """
|
|
__tablename__ = 'accounts'
|
|
__table_args__ = {"schema": "gba"}
|
|
person_id = Column('id', Integer, primary_key=True)
|
|
lname = Column('last_name', String(255), index=True)
|
|
fname = Column('first_name', String(255))
|
|
login = Column(String(255))
|
|
timestamp = Column('updated_at', DateTime, default=datetime.utcnow,
|
|
onupdate=datetime.utcnow)
|
|
def __repr__(self):
|
|
return "<User(name='%s', lastname='%s')>" % (
|
|
self.login, self.lname)
|
|
|
|
|
|
class PersonSchema(SQLAlchemyAutoSchema):
|
|
""" Platform class """
|
|
class Meta:
|
|
""" Platform class """
|
|
model = Person
|
|
include_relationships = True
|
|
load_instance = True
|
|
#pg_session: session = create_pg_session()
|
|
sqla_session: session = create_pg_session()
|