2016-07-18 18:28:12 +03:00
|
|
|
from sqlalchemy.ext.declarative.api import DeclarativeMeta
|
|
|
|
|
|
|
|
|
2016-07-23 06:18:23 +03:00
|
|
|
def get_session(context):
|
|
|
|
return context.get('session')
|
2016-07-18 18:28:12 +03:00
|
|
|
|
|
|
|
|
2016-07-23 06:18:23 +03:00
|
|
|
def get_query(model, context):
|
2016-07-18 18:28:12 +03:00
|
|
|
query = getattr(model, 'query', None)
|
|
|
|
if not query:
|
2016-07-23 06:18:23 +03:00
|
|
|
session = get_session(context)
|
2016-07-18 18:28:12 +03:00
|
|
|
if not session:
|
|
|
|
raise Exception('A query in the model Base or a session in the schema is required for querying.\n'
|
|
|
|
'Read more http://graphene-python.org/docs/sqlalchemy/tips/#querying')
|
|
|
|
query = session.query(model)
|
|
|
|
return query
|
|
|
|
|
|
|
|
|
|
|
|
def is_mapped(obj):
|
|
|
|
return isinstance(obj, DeclarativeMeta)
|