import os
from graphene_sqlalchemy import SQLAlchemyObjectType
from sqlalchemy import Column, Integer, String, create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base

POSTGRES_CONNECTION_STRING = (
    os.environ.get("POSTGRES_CONNECTION_STRING")
    or "postgres://postgres:password@localhost:6432/postgres"
)

engine = create_engine(POSTGRES_CONNECTION_STRING, convert_unicode=True)
db_session = scoped_session(
    sessionmaker(autocommit=False, autoflush=False, bind=engine)
)
Base = declarative_base()
Base.query = db_session.query_property()


class UserModel(Base):
    __tablename__ = "users"
    id = Column(Integer, primary_key=True)
    name = Column(String)
    balance = Column(Integer)


class MinAmountModel(Base):
    __tablename__ = "min_amount"
    amount = Column(Integer, primary_key=True)


class User(SQLAlchemyObjectType):
    class Meta:
        model = UserModel


class MinAmount(SQLAlchemyObjectType):
    class Meta:
        model = MinAmountModel

[((12, 9, 12, 72), 'sqlalchemy.create_engine', 'create_engine', (), '', False, 'from sqlalchemy import Column, Integer, String, create_engine\n'), ((16, 7, 16, 25), 'sqlalchemy.ext.declarative.declarative_base', 'declarative_base', ({}, {}), '()', False, 'from sqlalchemy.ext.declarative import declarative_base\n'), ((8, 4, 8, 48), 'os.environ.get', 'os.environ.get', ({(8, 19, 8, 47): '"""POSTGRES_CONNECTION_STRING"""'}, {}), "('POSTGRES_CONNECTION_STRING')", False, 'import os\n'), ((14, 4, 14, 64), 'sqlalchemy.orm.sessionmaker', 'sessionmaker', (), '', False, 'from sqlalchemy.orm import scoped_session, sessionmaker\n'), ((22, 9, 22, 42), 'sqlalchemy.Column', 'Column', (), '', False, 'from sqlalchemy import Column, Integer, String, create_engine\n'), ((23, 11, 23, 25), 'sqlalchemy.Column', 'Column', ({(23, 18, 23, 24): 'String'}, {}), '(String)', False, 'from sqlalchemy import Column, Integer, String, create_engine\n'), ((24, 14, 24, 29), 'sqlalchemy.Column', 'Column', ({(24, 21, 24, 28): 'Integer'}, {}), '(Integer)', False, 'from sqlalchemy import Column, Integer, String, create_engine\n'), ((29, 13, 29, 46), 'sqlalchemy.Column', 'Column', (), '', False, 'from sqlalchemy import Column, Integer, String, create_engine\n')]