From e125253b107623d9a4f396613d71a1381fec2fc9 Mon Sep 17 00:00:00 2001 From: Aurthur Musendame Date: Sun, 1 Sep 2024 16:00:19 +0200 Subject: [PATCH 1/6] added async support --- .vscode/PythonImportHelper-v2-Completion.json | 3149 +++++++++++++++++ sqlalchemy_mixins/__init__.py | 2 + sqlalchemy_mixins/activerecordasync.py | 201 ++ sqlalchemy_mixins/activerecordasync.pyi | 59 + 4 files changed, 3411 insertions(+) create mode 100644 .vscode/PythonImportHelper-v2-Completion.json create mode 100644 sqlalchemy_mixins/activerecordasync.py create mode 100644 sqlalchemy_mixins/activerecordasync.pyi diff --git a/.vscode/PythonImportHelper-v2-Completion.json b/.vscode/PythonImportHelper-v2-Completion.json new file mode 100644 index 0000000..83f2f09 --- /dev/null +++ b/.vscode/PythonImportHelper-v2-Completion.json @@ -0,0 +1,3149 @@ +[ + { + "label": "print_function", + "importPath": "__future__", + "description": "__future__", + "isExtraImport": true, + "detail": "__future__", + "documentation": {} + }, + { + "label": "print_function", + "importPath": "__future__", + "description": "__future__", + "isExtraImport": true, + "detail": "__future__", + "documentation": {} + }, + { + "label": "print_function", + "importPath": "__future__", + "description": "__future__", + "isExtraImport": true, + "detail": "__future__", + "documentation": {} + }, + { + "label": "print_function", + "importPath": "__future__", + "description": "__future__", + "isExtraImport": true, + "detail": "__future__", + "documentation": {} + }, + { + "label": "print_function", + "importPath": "__future__", + "description": "__future__", + "isExtraImport": true, + "detail": "__future__", + "documentation": {} + }, + { + "label": "print_function", + "importPath": "__future__", + "description": "__future__", + "isExtraImport": true, + "detail": "__future__", + "documentation": {} + }, + { + "label": "print_function", + "importPath": "__future__", + "description": "__future__", + "isExtraImport": true, + "detail": "__future__", + "documentation": {} + }, + { + "label": "print_function", + "importPath": "__future__", + "description": "__future__", + "isExtraImport": true, + "detail": "__future__", + "documentation": {} + }, + { + "label": "os", + "kind": 6, + "isExtraImport": true, + "importPath": "os", + "description": "os", + "detail": "os", + "documentation": {} + }, + { + "label": "sqlalchemy", + "kind": 6, + "isExtraImport": true, + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "event", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "event", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "select", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "inspect", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "inspect", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "asc", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "desc", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "inspect", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "hybrid_property", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "hybrid_method", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "hybrid_property", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "hybrid_property", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "hybrid_property", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "hybrid_method", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "hybrid_property", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "hybrid_property", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "hybrid_method", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "hybrid_property", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "hybrid_method", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "scoped_session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "sessionmaker", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "scoped_session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "sessionmaker", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Query", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "scoped_session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "sessionmaker", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "scoped_session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "sessionmaker", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "scoped_session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "sessionmaker", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Query", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "scoped_session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "sessionmaker", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "scoped_session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "sessionmaker", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Query", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "declarative_base", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Query", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "sessionmaker", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Query", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Query", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "joinedload", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Load", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "subqueryload", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "RelationshipProperty", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "scoped_session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Query", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "aliased", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "contains_eager", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "RelationshipProperty", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Mapper", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "ActiveRecordMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "ReprMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "ModelNotFoundError", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "AllFeaturesMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "TimestampsMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "EagerLoadMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "ReprMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "ReprMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "SerializeMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "SmartQueryMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "ReprMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "JOINED", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "smart_query", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "TimestampsMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "ActiveRecordMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "EagerLoadMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "InspectionMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "ReprMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "SerializeMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "SmartQueryMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "smart_query", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "TimestampsMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "JOINED", + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "SUBQUERY", + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "eager_expr", + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "JOINED", + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "SUBQUERY", + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "eager_expr", + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "JOINED", + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "SUBQUERY", + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "datetime", + "kind": 6, + "isExtraImport": true, + "importPath": "datetime", + "description": "datetime", + "detail": "datetime", + "documentation": {} + }, + { + "label": "datetime", + "importPath": "datetime", + "description": "datetime", + "isExtraImport": true, + "detail": "datetime", + "documentation": {} + }, + { + "label": "datetime", + "importPath": "datetime", + "description": "datetime", + "isExtraImport": true, + "detail": "datetime", + "documentation": {} + }, + { + "label": "time", + "kind": 6, + "isExtraImport": true, + "importPath": "time", + "description": "time", + "detail": "time", + "documentation": {} + }, + { + "label": "unittest", + "kind": 6, + "isExtraImport": true, + "importPath": "unittest", + "description": "unittest", + "detail": "unittest", + "documentation": {} + }, + { + "label": "ModelNotFoundError", + "importPath": "sqlalchemy_mixins.activerecord", + "description": "sqlalchemy_mixins.activerecord", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.activerecord", + "documentation": {} + }, + { + "label": "SessionMixin", + "importPath": "sqlalchemy_mixins.session", + "description": "sqlalchemy_mixins.session", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.session", + "documentation": {} + }, + { + "label": "NoSessionError", + "importPath": "sqlalchemy_mixins.session", + "description": "sqlalchemy_mixins.session", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.session", + "documentation": {} + }, + { + "label": "_AbstractLoad", + "importPath": "sqlalchemy.orm.strategy_options", + "description": "sqlalchemy.orm.strategy_options", + "isExtraImport": true, + "detail": "sqlalchemy.orm.strategy_options", + "documentation": {} + }, + { + "label": "string_types", + "importPath": "six", + "description": "six", + "isExtraImport": true, + "detail": "six", + "documentation": {} + }, + { + "label": "Iterable", + "importPath": "collections.abc", + "description": "collections.abc", + "isExtraImport": true, + "detail": "collections.abc", + "documentation": {} + }, + { + "label": "abc", + "importPath": "collections", + "description": "collections", + "isExtraImport": true, + "detail": "collections", + "documentation": {} + }, + { + "label": "OrderedDict", + "importPath": "collections", + "description": "collections", + "isExtraImport": true, + "detail": "collections", + "documentation": {} + }, + { + "label": "AliasedClass", + "importPath": "sqlalchemy.orm.util", + "description": "sqlalchemy.orm.util", + "isExtraImport": true, + "detail": "sqlalchemy.orm.util", + "documentation": {} + }, + { + "label": "operators", + "importPath": "sqlalchemy.sql", + "description": "sqlalchemy.sql", + "isExtraImport": true, + "detail": "sqlalchemy.sql", + "documentation": {} + }, + { + "label": "extract", + "importPath": "sqlalchemy.sql", + "description": "sqlalchemy.sql", + "isExtraImport": true, + "detail": "sqlalchemy.sql", + "documentation": {} + }, + { + "label": "setup", + "importPath": "setuptools", + "description": "setuptools", + "isExtraImport": true, + "detail": "setuptools", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, ActiveRecordMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "class BaseModel(Base, ActiveRecordMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n age = sa.Column(sa.Integer)", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n age = sa.Column(sa.Integer)\n posts = sa.orm.relationship('Post', backref='user')\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n # user = backref from User.post\n @hybrid_property\n def public(self):\n return not self.archived", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "log", + "kind": 2, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "def log(msg):\n print('\\n{}\\n'.format(msg))\n#################### setup ######################\nclass Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, ActiveRecordMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "db_file", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "db_file = os.path.join(os.path.dirname(__file__), 'test.sqlite')\nengine = create_engine('sqlite:///{}'.format(db_file), echo=True)\n# autocommit=True - it's to make you see data in 3rd party DB view tool\nsession = scoped_session(sessionmaker(bind=engine))\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\n# setup base model: inject session so it can be accessed from model\nBaseModel.set_session(session)\n#################### CRUD demo ######################\n# ['id', 'body', 'user_id', 'archived', # normal columns", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "engine = create_engine('sqlite:///{}'.format(db_file), echo=True)\n# autocommit=True - it's to make you see data in 3rd party DB view tool\nsession = scoped_session(sessionmaker(bind=engine))\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\n# setup base model: inject session so it can be accessed from model\nBaseModel.set_session(session)\n#################### CRUD demo ######################\n# ['id', 'body', 'user_id', 'archived', # normal columns\n# 'user', 'comments', # relations", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "session", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\n# setup base model: inject session so it can be accessed from model\nBaseModel.set_session(session)\n#################### CRUD demo ######################\n# ['id', 'body', 'user_id', 'archived', # normal columns\n# 'user', 'comments', # relations\n# 'public'] # hybrid attributes\nprint(Post.settable_attributes)", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "user1", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "user1 = User()\n# equal to\n# user1.name = 'Billy'\n# user1.age = 1\n# session.flush()\nuser1.fill(name='Billy', age=1)\n# you can use kwargs as above or, in real-world apps, unpack dict as below\ndata = {'name': 'Bill', 'age': 21}\nuser1.fill(**data)\n# equal to", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "data", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "data = {'name': 'Bill', 'age': 21}\nuser1.fill(**data)\n# equal to\n# session.add(user1)\n# session.flush()\nuser1.save()\n#### 2. ActiveRecordMixin.create(): ####\n# equal to\n# user2 = User(name='Bob')\n# session.add(user2)", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "user2", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "user2 = User.create(name='Bob')\npost1 = Post.create(body='post1', user=user2)\n#### 3. ActiveRecordMixin.update(): ####\n# equal to\n# post1.fill(...)\n# post1.save()\npost1.update(body='new body', public=True, user=user1)\n#### 4. ActiveRecordMixin.delete(): ####\n# equal to\n# session.delete(post_to_be_deleted)", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "post1", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "post1 = Post.create(body='post1', user=user2)\n#### 3. ActiveRecordMixin.update(): ####\n# equal to\n# post1.fill(...)\n# post1.save()\npost1.update(body='new body', public=True, user=user1)\n#### 4. ActiveRecordMixin.delete(): ####\n# equal to\n# session.delete(post_to_be_deleted)\n# session.flush()", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "post_to_be_deleted", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "post_to_be_deleted = Post.create()\npost_to_be_deleted.delete()\n#### 5. ActiveRecordMixin.destroy() ####\n# equal to\n# session.delete(session.query(User).get(91))\n# session.delete(session.query(User).get(92))\n# session.flush()\n_ = User.create(id=91)\n__ = User.create(id=92)\nUser.destroy(91, 92)", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "_", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "_ = User.create(id=91)\n__ = User.create(id=92)\nUser.destroy(91, 92)\n#################### Query demo ######################\n#### 1. ActiveRecordMixin.all() ####\n# equal to\n# session.query(User).all()\nlog('all users: ' + str(User.all()))\n#### 2. ActiveRecordMixin.first() ####\n# equal to", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "__", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "__ = User.create(id=92)\nUser.destroy(91, 92)\n#################### Query demo ######################\n#### 1. ActiveRecordMixin.all() ####\n# equal to\n# session.query(User).all()\nlog('all users: ' + str(User.all()))\n#### 2. ActiveRecordMixin.first() ####\n# equal to\n# session.query(User).first()", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "user3", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "user3 = User.create(name='Bishop', id=3)\nlog('user with id=3: ' + str(User.find(3)))\n#### 4. ActiveRecordMixin.find_or_fail() ####\n# closest code on raw sqlalchemy will be\n# session.query(User).filter_by(id=).one()\n# but one() method throws common error without describing which ID was not\n# found, which is inconvenient: http://www.qopy.me/c5Csw1vWTCuOMKuP07J7iA\ntry:\n print(User.find_or_fail(123987))\nexcept ModelNotFoundError as e:", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "examples.all_features", + "description": "examples.all_features", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nclass BaseModel(Base, AllFeaturesMixin, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", + "detail": "examples.all_features", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "examples.all_features", + "description": "examples.all_features", + "peekOfCode": "class BaseModel(Base, AllFeaturesMixin, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'", + "detail": "examples.all_features", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "examples.all_features", + "description": "examples.all_features", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)", + "detail": "examples.all_features", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "examples.all_features", + "description": "examples.all_features", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n rating = sa.Column(sa.Integer)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n # we use this relation in smart_query, so it should be explicitly set\n # (not just a backref from User class)\n user = sa.orm.relationship('User', backref='posts') # but for eagerload", + "detail": "examples.all_features", + "documentation": {} + }, + { + "label": "Comment", + "kind": 6, + "importPath": "examples.all_features", + "description": "examples.all_features", + "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post = sa.orm.relationship('Post')\n user = sa.orm.relationship('User')\nengine = sa.create_engine('sqlite:///:memory:', echo=False)\nsession = scoped_session(sessionmaker(bind=engine))", + "detail": "examples.all_features", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "examples.all_features", + "description": "examples.all_features", + "peekOfCode": "engine = sa.create_engine('sqlite:///:memory:', echo=False)\nsession = scoped_session(sessionmaker(bind=engine))\nBase.metadata.create_all(engine)\nBaseModel.set_session(session)\nbob = User.create(name='Bob')\npost1 = Post.create(body='Post 1', user=bob, rating=3)\npost2 = Post.create(body='long-long-long-long-long body', rating=2,\n user=User.create(name='Bill'),\n comments=[Comment.create(body='cool!', user=bob)])\n# filter using operators like 'in' and 'contains' and relations like 'user'", + "detail": "examples.all_features", + "documentation": {} + }, + { + "label": "session", + "kind": 5, + "importPath": "examples.all_features", + "description": "examples.all_features", + "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nBase.metadata.create_all(engine)\nBaseModel.set_session(session)\nbob = User.create(name='Bob')\npost1 = Post.create(body='Post 1', user=bob, rating=3)\npost2 = Post.create(body='long-long-long-long-long body', rating=2,\n user=User.create(name='Bill'),\n comments=[Comment.create(body='cool!', user=bob)])\n# filter using operators like 'in' and 'contains' and relations like 'user'\n# will output this beauty: ", + "detail": "examples.all_features", + "documentation": {} + }, + { + "label": "bob", + "kind": 5, + "importPath": "examples.all_features", + "description": "examples.all_features", + "peekOfCode": "bob = User.create(name='Bob')\npost1 = Post.create(body='Post 1', user=bob, rating=3)\npost2 = Post.create(body='long-long-long-long-long body', rating=2,\n user=User.create(name='Bill'),\n comments=[Comment.create(body='cool!', user=bob)])\n# filter using operators like 'in' and 'contains' and relations like 'user'\n# will output this beauty: \nprint(Post.where(rating__in=[2, 3, 4], user___name__like='%Bi%').all())\n# joinedload post and user\nprint(Comment.with_joined(Comment.user, Comment.post).first())", + "detail": "examples.all_features", + "documentation": {} + }, + { + "label": "post1", + "kind": 5, + "importPath": "examples.all_features", + "description": "examples.all_features", + "peekOfCode": "post1 = Post.create(body='Post 1', user=bob, rating=3)\npost2 = Post.create(body='long-long-long-long-long body', rating=2,\n user=User.create(name='Bill'),\n comments=[Comment.create(body='cool!', user=bob)])\n# filter using operators like 'in' and 'contains' and relations like 'user'\n# will output this beauty: \nprint(Post.where(rating__in=[2, 3, 4], user___name__like='%Bi%').all())\n# joinedload post and user\nprint(Comment.with_joined(Comment.user, Comment.post).first())\n# subqueryload posts", + "detail": "examples.all_features", + "documentation": {} + }, + { + "label": "post2", + "kind": 5, + "importPath": "examples.all_features", + "description": "examples.all_features", + "peekOfCode": "post2 = Post.create(body='long-long-long-long-long body', rating=2,\n user=User.create(name='Bill'),\n comments=[Comment.create(body='cool!', user=bob)])\n# filter using operators like 'in' and 'contains' and relations like 'user'\n# will output this beauty: \nprint(Post.where(rating__in=[2, 3, 4], user___name__like='%Bi%').all())\n# joinedload post and user\nprint(Comment.with_joined(Comment.user, Comment.post).first())\n# subqueryload posts\nprint(User.with_subquery(User.posts).first())", + "detail": "examples.all_features", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, EagerLoadMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "class BaseModel(Base, EagerLoadMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\n comments = sa.orm.relationship('Comment')\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')\nclass Comment(BaseModel):\n __tablename__ = 'comment'", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "Comment", + "kind": 6, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body', 'post'] # we want to display body and post\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n user = sa.orm.relationship('User')\n post = sa.orm.relationship('Post')", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "log", + "kind": 2, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "def log(msg):\n print('\\n{}\\n'.format(msg))\n#################### setup ######################\nclass Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, EagerLoadMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "reset_session", + "kind": 2, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "def reset_session():\n session = scoped_session(sessionmaker(bind=engine))\n BaseModel.set_session(session)\n return session\n#################### setup some data ######################\nsession = reset_session()\nu1 = User(name='Bill u1', id=1)\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "db_file", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "db_file = os.path.join(os.path.dirname(__file__), 'test.sqlite')\nengine = create_engine('sqlite:///{}'.format(db_file), echo=True)\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\n# sqlalchemy caches data in session, so to not use cache, we recreate session\ndef reset_session():\n session = scoped_session(sessionmaker(bind=engine))\n BaseModel.set_session(session)\n return session\n#################### setup some data ######################", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "engine = create_engine('sqlite:///{}'.format(db_file), echo=True)\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\n# sqlalchemy caches data in session, so to not use cache, we recreate session\ndef reset_session():\n session = scoped_session(sessionmaker(bind=engine))\n BaseModel.set_session(session)\n return session\n#################### setup some data ######################\nsession = reset_session()", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "session", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "session = reset_session()\nu1 = User(name='Bill u1', id=1)\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nsession.commit()\np11 = Post(\n id=11,", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "u1", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "u1 = User(name='Bill u1', id=1)\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nsession.commit()\np11 = Post(\n id=11,\n body='1234567890123',", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "u2", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "u2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nsession.commit()\np11 = Post(\n id=11,\n body='1234567890123',\n archived=True\n)\np11.user = u1", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "p11", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "p11 = Post(\n id=11,\n body='1234567890123',\n archived=True\n)\np11.user = u1\nsession.add(p11)\nsession.commit()\np12 = Post(\n id=12,", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "p11.user", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "p11.user = u1\nsession.add(p11)\nsession.commit()\np12 = Post(\n id=12,\n body='1234567890',\n user=u1\n)\nsession.add(p12)\nsession.commit()", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "p12", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "p12 = Post(\n id=12,\n body='1234567890',\n user=u1\n)\nsession.add(p12)\nsession.commit()\ncm11 = Comment(\n id=11,\n body='cm11 to p11',", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "cm11", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "cm11 = Comment(\n id=11,\n body='cm11 to p11',\n user=u1,\n post=p11,\n rating=1\n)\nsession.add(cm11)\nsession.commit()\ncm12 = Comment(", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "cm12", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "cm12 = Comment(\n id=12,\n body='cm12 to p12',\n user=u2,\n post=p12,\n rating=2\n)\nsession.add(cm12)\nsession.commit()\n#################### Demo ######################", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "comment", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "comment = Comment.with_joined(Comment.user, Comment.post).first()\n# SQL will be like\n\"\"\"\nSELECT comment.*, user_1.*, post_1.*\nFROM comment\nLEFT OUTER JOIN user AS user_1 ON user_1.id = comment.user_id\nLEFT OUTER JOIN post AS post_1 ON post_1.id = comment.post_id\nLEFT OUTER JOIN comment AS comment_1 ON post_1.id = comment_1.post_id\nLIMIT 1 OFFSET 1\n\"\"\"", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "user", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "user = comment.user\npost = comment.post\ncomments = post.comments\nlog('NO ADDITIONAL SQL. END')\n#### 0.2 subqueryload ####\nreset_session()\nusers = User.with_subquery(User.posts).all()\n# there will be 3 queries:\n## first. on users:\n\"\"\"", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "post", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "post = comment.post\ncomments = post.comments\nlog('NO ADDITIONAL SQL. END')\n#### 0.2 subqueryload ####\nreset_session()\nusers = User.with_subquery(User.posts).all()\n# there will be 3 queries:\n## first. on users:\n\"\"\"\nSELECT user.* FROM user", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "comments", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "comments = post.comments\nlog('NO ADDITIONAL SQL. END')\n#### 0.2 subqueryload ####\nreset_session()\nusers = User.with_subquery(User.posts).all()\n# there will be 3 queries:\n## first. on users:\n\"\"\"\nSELECT user.* FROM user\n\"\"\"", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "users", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "users = User.with_subquery(User.posts).all()\n# there will be 3 queries:\n## first. on users:\n\"\"\"\nSELECT user.* FROM user\n\"\"\"\n# second. on posts:\n\"\"\"\nSELECT post.* FROM (SELECT user.id AS user_id FROM user) AS anon_1\nJOIN post ON anon_1.user_id = post.user_id", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "posts", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "posts = users[0].posts\ncomments = posts[0].comments\nlog('NO ADDITIONAL SQL. END')\n#### 1. nested joinedload ####\n# for nested eagerload, you should use dict instead of lists|\n# also make sure you use class properties\nschema = {\n User.posts: {\n Post.comments: {\n Comment.user: JOINED", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "comments", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "comments = posts[0].comments\nlog('NO ADDITIONAL SQL. END')\n#### 1. nested joinedload ####\n# for nested eagerload, you should use dict instead of lists|\n# also make sure you use class properties\nschema = {\n User.posts: {\n Post.comments: {\n Comment.user: JOINED\n }", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "schema", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "schema = {\n User.posts: {\n Post.comments: {\n Comment.user: JOINED\n }\n }\n}\nsession = reset_session()\n###### 1.1 query-level: more flexible\nuser = session.query(User).options(*eager_expr(schema)).get(1)", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "session", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "session = reset_session()\n###### 1.1 query-level: more flexible\nuser = session.query(User).options(*eager_expr(schema)).get(1)\n# SQL will be like\n# note that we select user as parent entity and as post.comments.user\n# EagerLoadMixin will make table aliases for us\n\"\"\"\nSELECT user.*, user_1.*, comment_1.*, post_1.*\nFROM user\nLEFT OUTER JOIN post AS post_1 ON user.id = post_1.user_id", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "user", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "user = session.query(User).options(*eager_expr(schema)).get(1)\n# SQL will be like\n# note that we select user as parent entity and as post.comments.user\n# EagerLoadMixin will make table aliases for us\n\"\"\"\nSELECT user.*, user_1.*, comment_1.*, post_1.*\nFROM user\nLEFT OUTER JOIN post AS post_1 ON user.id = post_1.user_id\nLEFT OUTER JOIN comment AS comment_1 ON post_1.id = comment_1.post_id\nLEFT OUTER JOIN user AS user_1 ON user_1.id = comment_1.user_id", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "user", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "user = User.with_(schema).get(1)\n# now, to get relationships, NO additional query is needed\nlog('NO ADDITIONAL SQL. BEGIN')\npost = user.posts[0]\ncomment = post.comments[0]\ncomment_user = comment.user\nlog('NO ADDITIONAL SQL. END')\n#### 2. combination of joinedload and subqueryload ####\n# sometimes we want to load relations in separate query.\n# i.g. when we load posts, to each post we want to have user and all comments.", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "post", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "post = user.posts[0]\ncomment = post.comments[0]\ncomment_user = comment.user\nlog('NO ADDITIONAL SQL. END')\n#### 2. combination of joinedload and subqueryload ####\n# sometimes we want to load relations in separate query.\n# i.g. when we load posts, to each post we want to have user and all comments.\n# when we load many posts, join comments and comments to each user\nschema = {\n Post.comments: (SUBQUERY, { # load comments in separate query", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "comment", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "comment = post.comments[0]\ncomment_user = comment.user\nlog('NO ADDITIONAL SQL. END')\n#### 2. combination of joinedload and subqueryload ####\n# sometimes we want to load relations in separate query.\n# i.g. when we load posts, to each post we want to have user and all comments.\n# when we load many posts, join comments and comments to each user\nschema = {\n Post.comments: (SUBQUERY, { # load comments in separate query\n Comment.user: JOINED # but, in this separate query, join comments", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "comment_user", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "comment_user = comment.user\nlog('NO ADDITIONAL SQL. END')\n#### 2. combination of joinedload and subqueryload ####\n# sometimes we want to load relations in separate query.\n# i.g. when we load posts, to each post we want to have user and all comments.\n# when we load many posts, join comments and comments to each user\nschema = {\n Post.comments: (SUBQUERY, { # load comments in separate query\n Comment.user: JOINED # but, in this separate query, join comments\n })", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "schema", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "schema = {\n Post.comments: (SUBQUERY, { # load comments in separate query\n Comment.user: JOINED # but, in this separate query, join comments\n })\n}\n###### 2.1 query-level: more flexible\nreset_session()\nposts = session.query(Post).options(*eager_expr(schema)).all()\n###### 2.2 ORM-level: more convenient\nreset_session()", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "posts", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "posts = session.query(Post).options(*eager_expr(schema)).all()\n###### 2.2 ORM-level: more convenient\nreset_session()\nposts = Post.with_(schema).all()\n# there will be 2 queries:\n## first:\n\"\"\"\nSELECT post.* FROM post\n\"\"\"\n# second query loads comments with joined comment users", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "posts", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "posts = Post.with_(schema).all()\n# there will be 2 queries:\n## first:\n\"\"\"\nSELECT post.* FROM post\n\"\"\"\n# second query loads comments with joined comment users\n# it uses first query to get comments for specific posts\n\"\"\"\nSELECT comment.*, user_1.*", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "comments1", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "comments1 = posts[0].comments\ncomments2 = posts[1].comments\nuser1 = posts[0].comments[0].user\nuser2 = posts[1].comments[0].user\nlog('NO ADDITIONAL SQL. END')", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "comments2", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "comments2 = posts[1].comments\nuser1 = posts[0].comments[0].user\nuser2 = posts[1].comments[0].user\nlog('NO ADDITIONAL SQL. END')", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "user1", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "user1 = posts[0].comments[0].user\nuser2 = posts[1].comments[0].user\nlog('NO ADDITIONAL SQL. END')", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "user2", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "user2 = posts[1].comments[0].user\nlog('NO ADDITIONAL SQL. END')", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "examples.repr", + "description": "examples.repr", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = sa.create_engine('sqlite:///:memory:')\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'", + "detail": "examples.repr", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "examples.repr", + "description": "examples.repr", + "peekOfCode": "class BaseModel(Base, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')", + "detail": "examples.repr", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "examples.repr", + "description": "examples.repr", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\nclass Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n __repr_max_length__ = 25", + "detail": "examples.repr", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "examples.repr", + "description": "examples.repr", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n __repr_max_length__ = 25\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\nBase.metadata.create_all(engine)\nbob = User(name='Bob')\nsession.add(bob)", + "detail": "examples.repr", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "examples.repr", + "description": "examples.repr", + "peekOfCode": "engine = sa.create_engine('sqlite:///:memory:')\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "examples.repr", + "documentation": {} + }, + { + "label": "session", + "kind": 5, + "importPath": "examples.repr", + "description": "examples.repr", + "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", + "detail": "examples.repr", + "documentation": {} + }, + { + "label": "bob", + "kind": 5, + "importPath": "examples.repr", + "description": "examples.repr", + "peekOfCode": "bob = User(name='Bob')\nsession.add(bob)\nsession.flush()\npost1 = Post(body='Post 1', user=bob)\nsession.add(post1)\nsession.flush()\npost2 = Post(body='Post 2 long-long body', user=bob)\nsession.add(post2)\nsession.flush()\n# ", + "detail": "examples.repr", + "documentation": {} + }, + { + "label": "post1", + "kind": 5, + "importPath": "examples.repr", + "description": "examples.repr", + "peekOfCode": "post1 = Post(body='Post 1', user=bob)\nsession.add(post1)\nsession.flush()\npost2 = Post(body='Post 2 long-long body', user=bob)\nsession.add(post2)\nsession.flush()\n# \nprint(bob)\n# \nprint(post1)", + "detail": "examples.repr", + "documentation": {} + }, + { + "label": "post2", + "kind": 5, + "importPath": "examples.repr", + "description": "examples.repr", + "peekOfCode": "post2 = Post(body='Post 2 long-long body', user=bob)\nsession.add(post2)\nsession.flush()\n# \nprint(bob)\n# \nprint(post1)\n# \nprint(post2)", + "detail": "examples.repr", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "examples.serialize", + "description": "examples.serialize", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = sa.create_engine('sqlite:///:memory:')\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "examples.serialize", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "examples.serialize", + "description": "examples.serialize", + "peekOfCode": "class BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n password = sa.Column(sa.String)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\nclass Post(BaseModel):", + "detail": "examples.serialize", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "examples.serialize", + "description": "examples.serialize", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n password = sa.Column(sa.String)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)", + "detail": "examples.serialize", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "examples.serialize", + "description": "examples.serialize", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\nBase.metadata.create_all(engine)\nbob = User(name='Bob' , password = \"pass123\")\nsession.add(bob)\nsession.flush()\npost1 = Post(body='Post 1', user=bob)", + "detail": "examples.serialize", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "examples.serialize", + "description": "examples.serialize", + "peekOfCode": "engine = sa.create_engine('sqlite:///:memory:')\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n password = sa.Column(sa.String)\n name = sa.Column(sa.String)", + "detail": "examples.serialize", + "documentation": {} + }, + { + "label": "session", + "kind": 5, + "importPath": "examples.serialize", + "description": "examples.serialize", + "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n password = sa.Column(sa.String)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')", + "detail": "examples.serialize", + "documentation": {} + }, + { + "label": "bob", + "kind": 5, + "importPath": "examples.serialize", + "description": "examples.serialize", + "peekOfCode": "bob = User(name='Bob' , password = \"pass123\")\nsession.add(bob)\nsession.flush()\npost1 = Post(body='Post 1', user=bob)\nsession.add(post1)\nsession.flush()\npost2 = Post(body='Post 2', user=bob)\nsession.add(post2)\nsession.flush()\n# {'id': 1, 'name': 'Bob' , 'password' : 'pass123'}", + "detail": "examples.serialize", + "documentation": {} + }, + { + "label": "post1", + "kind": 5, + "importPath": "examples.serialize", + "description": "examples.serialize", + "peekOfCode": "post1 = Post(body='Post 1', user=bob)\nsession.add(post1)\nsession.flush()\npost2 = Post(body='Post 2', user=bob)\nsession.add(post2)\nsession.flush()\n# {'id': 1, 'name': 'Bob' , 'password' : 'pass123'}\nprint(bob.to_dict())\n# {'id': 1,\n# 'name': 'Bob',", + "detail": "examples.serialize", + "documentation": {} + }, + { + "label": "post2", + "kind": 5, + "importPath": "examples.serialize", + "description": "examples.serialize", + "peekOfCode": "post2 = Post(body='Post 2', user=bob)\nsession.add(post2)\nsession.flush()\n# {'id': 1, 'name': 'Bob' , 'password' : 'pass123'}\nprint(bob.to_dict())\n# {'id': 1,\n# 'name': 'Bob',\n# 'posts': [{'body': 'Post 1', 'id': 1, 'user_id': 1},\n# {'body': 'Post 2', 'id': 2, 'user_id': 1}]}\nprint(bob.to_dict(nested=True , exclude = ['password']))", + "detail": "examples.serialize", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, SmartQueryMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "class BaseModel(Base, SmartQueryMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n # to smart query relationship, it should be explicitly set,", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n # to smart query relationship, it should be explicitly set,\n # not to be a backref\n posts = sa.orm.relationship('Post')\n comments = sa.orm.relationship('Comment')\n # below relationship will just return query (without executing)", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n # to smart query relationship, it should be explicitly set,\n # not to be a backref\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "Comment", + "kind": 6, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n created_at = sa.Column(sa.DateTime)\n # to smart query relationship, it should be explicitly set,", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "log", + "kind": 2, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "def log(msg):\n print('\\n{}\\n'.format(msg))\n#################### setup ######################\nclass Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, SmartQueryMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "db_file", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "db_file = os.path.join(os.path.dirname(__file__), 'test.sqlite')\nengine = create_engine('sqlite:///{}'.format(db_file), echo=True)\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\nsession = scoped_session(sessionmaker(bind=engine))\nBaseModel.set_session(session)\n#################### setup some data ######################\nu1 = User(name='Bill u1')\nsession.add(u1)\nsession.commit()", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "engine = create_engine('sqlite:///{}'.format(db_file), echo=True)\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\nsession = scoped_session(sessionmaker(bind=engine))\nBaseModel.set_session(session)\n#################### setup some data ######################\nu1 = User(name='Bill u1')\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "session", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nBaseModel.set_session(session)\n#################### setup some data ######################\nu1 = User(name='Bill u1')\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nu3 = User(name='Bishop u3')", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "u1", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "u1 = User(name='Bill u1')\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nu3 = User(name='Bishop u3')\nsession.add(u3)\nsession.commit()\nsession.commit()", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "u2", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "u2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nu3 = User(name='Bishop u3')\nsession.add(u3)\nsession.commit()\nsession.commit()\np11 = Post(\n id=11,\n body='1234567890123',", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "u3", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "u3 = User(name='Bishop u3')\nsession.add(u3)\nsession.commit()\nsession.commit()\np11 = Post(\n id=11,\n body='1234567890123',\n archived=True,\n user=u1\n)", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "p11", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "p11 = Post(\n id=11,\n body='1234567890123',\n archived=True,\n user=u1\n)\nsession.add(p11)\nsession.commit()\np12 = Post(\n id=12,", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "p12", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "p12 = Post(\n id=12,\n body='1234567890',\n user=u1\n)\nsession.add(p12)\nsession.commit()\np21 = Post(\n id=21,\n body='p21',", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "p21", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "p21 = Post(\n id=21,\n body='p21',\n user=u2\n)\nsession.add(p21)\nsession.commit()\np22 = Post(\n id=22,\n body='p22',", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "p22", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "p22 = Post(\n id=22,\n body='p22',\n user=u2\n)\nsession.add(p22)\nsession.commit()\ncm11 = Comment(\n id=11,\n body='cm11',", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "cm11", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "cm11 = Comment(\n id=11,\n body='cm11',\n user=u1,\n post=p11,\n rating=1,\n created_at=datetime.datetime(2014, 1, 1)\n)\nsession.add(cm11)\nsession.commit()", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "cm12", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "cm12 = Comment(\n id=12,\n body='cm12',\n user=u2,\n post=p12,\n rating=2,\n created_at=datetime.datetime(2015, 10, 20)\n)\nsession.add(cm12)\nsession.commit()", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "cm21", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "cm21 = Comment(\n id=21,\n body='cm21',\n user=u1,\n post=p21,\n rating=1,\n created_at=datetime.datetime(2015, 11, 21)\n)\nsession.add(cm21)\nsession.commit()", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "cm22", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "cm22 = Comment(\n id=22,\n body='cm22',\n user=u3,\n post=p22,\n rating=3,\n created_at=datetime.datetime(2016, 11, 20)\n)\nsession.add(cm22)\nsession.commit()", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "cm_empty", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "cm_empty = Comment(\n id=29,\n # no body\n # no user\n # no post\n # no rating\n)\nsession.add(cm_empty)\nsession.commit()\n#################### Demo ######################", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "filters", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "filters = {'user': u1, 'public': True}\nlog(Post.where(**filters).all())\n##### 1.2 filter by hybrid_method 'is_commented_by_user' #####\n# low-level filter_expr()\nlog(session.query(Post).filter(\n *Post.filter_expr(is_commented_by_user=u1)).all())\n# high-level SmartQueryMixin.where() method\nlog(Post.where(is_commented_by_user=u1).all())\n##### 1.3 operators #####\n# rating == None", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "sort_attrs", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "sort_attrs = ['-rating', 'created_at']\nlog(Comment.sort(*sort_attrs))\n##### 2.1.3 hybrid properties\nlog(session.query(Post).order_by(*Post.order_expr('-public')).all())\nlog(Post.sort('-public').all())\n#### 2.2 sort() with auto-joined relations ####\n# sort by name of user ASC (user relation will be auto-joined), then by\n# created_at DESC\nlog(Comment.sort('user___name', '-created_at').all())\n# get comments on public posts first, then order by post user name", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "schema", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "schema = {\n Comment.post: {\n Post.user: JOINED\n }\n}\n##### 3.1 high-level smart_query() class method #####\nres = Comment.smart_query(\n filters={\n 'post___public': True,\n 'user__isnull': False", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "res", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "res = Comment.smart_query(\n filters={\n 'post___public': True,\n 'user__isnull': False\n },\n sort_attrs=['user___name', '-created_at'],\n schema=schema).all()\nlog(res) # cm12, cm21, cm22\n##### 3.2 more flexible smart_query() function #####\n##### 3.2.1. The same as 3.1", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "query", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "query = Comment.query # could be any query you want\nres = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False\n },\n sort_attrs=['user___name', '-created_at'],\n schema=schema).all()\nlog(res) # cm12, cm21, cm22\n##### 3.2.2. Real-life example with lazy='dynamic' relationship", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "res", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "res = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False\n },\n sort_attrs=['user___name', '-created_at'],\n schema=schema).all()\nlog(res) # cm12, cm21, cm22\n##### 3.2.2. Real-life example with lazy='dynamic' relationship\n# let's imagine we want to display some user relations", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "user", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "user = session.query(User).first()\n# and we have initial query for his/her comments\n# (see User.comments_ relationship)\nquery = user.comments_\n# now we just smartly apply all filters, sorts and eagerload. Perfect!\nres = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False\n },", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "query", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "query = user.comments_\n# now we just smartly apply all filters, sorts and eagerload. Perfect!\nres = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False\n },\n sort_attrs=['user___name', '-created_at'],\n schema=schema).all()\nlog(res) # cm21", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "res", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "res = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False\n },\n sort_attrs=['user___name', '-created_at'],\n schema=schema).all()\nlog(res) # cm21\n##### 3.2.3 Logical operators and arbitrary expressions in filters\n# If we want to use OR, NOT or other logical operators in our queries", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "res", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "res = Post.smart_query(filters={\n sa.or_: {'archived': True, 'is_commented_by_user': u3}\n})\nlog(res) # p11, p22\n# Some logic cannot be expressed without using a list instead, e.g.\n# (X OR Y) AND (W OR Z)\n# E.g. (somewhat contrived example):\n# (non-archived OR has comments) AND \n# (user_name like 'B%' or user_name like 'C%')\nres = Post.smart_query(filters=[", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "res", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "res = Post.smart_query(filters=[\n {sa.or_: {'archived': False, 'comments__isnull': False }},\n {sa.or_: [\n {'user___name__like': 'B%'},\n {'user___name__like': 'C%'}\n ]}\n])\n# !! NOTE !! This cannot be used with the where method, e.g. \n# Post.where(**{sa.or: {...}})\n# TypeError!! (only strings are allowed as keyword arguments)", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "res", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "res = Comment.where(post___public=True, post___user___name__like='Bi%').all()\nlog(res)\n# no additional query needed: we used 'post' and 'post__user'\n# relations in smart_query()\nlog(res[0].post)\nlog(res[0].post.user)\n# we didn't use post___comments in filters, so additional query is needed\nlog(res[0].post.comments)\n##### 3.3.2 sort()\nres = Comment.sort('-post___public', 'post___user___name').all()", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "res", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "res = Comment.sort('-post___public', 'post___user___name').all()\nlog(res)\n# no additional query needed: we used 'post' and 'post__user'\n# relations in smart_query()\nlog(res[0].post)\nlog(res[0].post.user)\n# we didn't use post___comments in filters, so additional query is needed\nlog(res[0].post.comments)", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "examples.timestamp", + "description": "examples.timestamp", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = sa.create_engine(\"sqlite:///:memory:\")\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n \"\"\"User Model to example.\"\"\"\n __tablename__ = \"users\"", + "detail": "examples.timestamp", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "examples.timestamp", + "description": "examples.timestamp", + "peekOfCode": "class BaseModel(Base, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n \"\"\"User Model to example.\"\"\"\n __tablename__ = \"users\"\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nBase.metadata.create_all(engine)\nprint(\"Current time: \", datetime.utcnow())", + "detail": "examples.timestamp", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "examples.timestamp", + "description": "examples.timestamp", + "peekOfCode": "class User(BaseModel):\n \"\"\"User Model to example.\"\"\"\n __tablename__ = \"users\"\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nBase.metadata.create_all(engine)\nprint(\"Current time: \", datetime.utcnow())\n# Current time: 2019-03-04 03:53:53.605602\nbob = User(name=\"Bob\")\nsession.add(bob)", + "detail": "examples.timestamp", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "examples.timestamp", + "description": "examples.timestamp", + "peekOfCode": "engine = sa.create_engine(\"sqlite:///:memory:\")\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n \"\"\"User Model to example.\"\"\"\n __tablename__ = \"users\"\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", + "detail": "examples.timestamp", + "documentation": {} + }, + { + "label": "session", + "kind": 5, + "importPath": "examples.timestamp", + "description": "examples.timestamp", + "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n \"\"\"User Model to example.\"\"\"\n __tablename__ = \"users\"\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nBase.metadata.create_all(engine)", + "detail": "examples.timestamp", + "documentation": {} + }, + { + "label": "bob", + "kind": 5, + "importPath": "examples.timestamp", + "description": "examples.timestamp", + "peekOfCode": "bob = User(name=\"Bob\")\nsession.add(bob)\nsession.flush()\nprint(\"Created Bob: \", bob.created_at)\n# Created Bob: 2019-03-04 03:53:53.606765\nprint(\"Pre-update Bob: \", bob.updated_at)\n# Pre-update Bob: 2019-03-04 03:53:53.606769\ntime.sleep(2)\nbob.name = \"Robert\"\nsession.commit()", + "detail": "examples.timestamp", + "documentation": {} + }, + { + "label": "bob.name", + "kind": 5, + "importPath": "examples.timestamp", + "description": "examples.timestamp", + "peekOfCode": "bob.name = \"Robert\"\nsession.commit()\nprint(\"Updated Bob: \", bob.updated_at)\n# Updated Bob: 2019-03-04 03:53:55.613044", + "detail": "examples.timestamp", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nAlternativeBase = declarative_base()\nengine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ActiveRecordMixin):\n __abstract__ = True\n pass\nclass BaseModelAlternative(AlternativeBase, ActiveRecordMixin):", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "class BaseModel(Base, ActiveRecordMixin):\n __abstract__ = True\n pass\nclass BaseModelAlternative(AlternativeBase, ActiveRecordMixin):\n __abstract__ = True\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "BaseModelAlternative", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "class BaseModelAlternative(AlternativeBase, ActiveRecordMixin):\n __abstract__ = True\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\n posts_viewonly = sa.orm.relationship('Post', viewonly=True)\nclass UserAlternative(BaseModelAlternative):", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\n posts_viewonly = sa.orm.relationship('Post', viewonly=True)\nclass UserAlternative(BaseModelAlternative):\n __tablename__ = 'user_alt'\n __repr_attrs__ = ['name']", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "UserAlternative", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "class UserAlternative(BaseModelAlternative):\n __tablename__ = 'user_alt'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n # user = backref from User.post\n comments = sa.orm.relationship('Comment', backref='post')\n @hybrid_property\n def public(self):", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "Comment", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n user = sa.orm.relationship('User', backref='comments')\n # post = backref from Post.comments\nclass TestActiveRecord(unittest.TestCase):", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "TestActiveRecord", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "class TestActiveRecord(unittest.TestCase):\n def setUp(self):\n sess.rollback()\n BaseModel.set_session(None)\n Base.metadata.drop_all(engine)\n Base.metadata.create_all(engine)\n BaseModel.set_session(sess)\n def test_settable_attributes(self):\n self.assertEqual(set(User.settable_attributes),\n {'id', 'name', # normal columns", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "TestActiveRecordAlternative", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "class TestActiveRecordAlternative(unittest.TestCase):\n def setUp(self):\n sess.rollback()\n BaseModelAlternative.set_session(None)\n AlternativeBase.metadata.drop_all(engine)\n AlternativeBase.metadata.create_all(engine)\n BaseModelAlternative.set_session(sess)\n def test_create(self):\n u1 = UserAlternative.create(name='Bill u1')\n self.assertEqual(u1, sess.query(UserAlternative).first())", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "AlternativeBase", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "AlternativeBase = declarative_base()\nengine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ActiveRecordMixin):\n __abstract__ = True\n pass\nclass BaseModelAlternative(AlternativeBase, ActiveRecordMixin):\n __abstract__ = True\nclass User(BaseModel):", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ActiveRecordMixin):\n __abstract__ = True\n pass\nclass BaseModelAlternative(AlternativeBase, ActiveRecordMixin):\n __abstract__ = True\nclass User(BaseModel):\n __tablename__ = 'user'", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "sess", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "sess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ActiveRecordMixin):\n __abstract__ = True\n pass\nclass BaseModelAlternative(AlternativeBase, ActiveRecordMixin):\n __abstract__ = True\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, EagerLoadMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class BaseModel(Base, EagerLoadMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\nclass Post(BaseModel):", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')\nclass Comment(BaseModel):\n __tablename__ = 'comment'", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "Comment", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n user = sa.orm.relationship('User')\n post = sa.orm.relationship('Post')", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "TestEagerLoad", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class TestEagerLoad(unittest.TestCase):\n def setUp(self):\n Base.metadata.drop_all(engine)\n Base.metadata.create_all(engine)\n BaseModel.set_session(sess)\n u1 = User(name='Bill u1')\n sess.add(u1)\n sess.commit()\n u2 = User(name='Alex u2')\n sess.add(u2)", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "TestNoEagerLoad", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class TestNoEagerLoad(TestEagerLoad):\n def test_no_eagerload(self):\n self.assertEqual(self.query_count, 0)\n post = Post.query.get(11)\n self.assertEqual(self.query_count, 1)\n # to get relationship, ADDITIONAL query is needed\n comment = post.comments[0]\n self.assertEqual(self.query_count, 2)\n # to get relationship, ADDITIONAL query is needed\n _ = comment.user", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "TestEagerExpr", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class TestEagerExpr(TestEagerLoad):\n \"\"\"test of low-level eager_expr function\"\"\"\n def _test_ok(self, schema):\n self.assertEqual(self.query_count, 0)\n user = sess.query(User).options(*eager_expr(schema)).get(1)\n self.assertEqual(self.query_count, 2)\n # now, to get relationships, NO additional query is needed\n post = user.posts[0]\n _ = post.comments[0]\n self.assertEqual(self.query_count, 2)", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "TestOrmWithJoinedClassProperties", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class TestOrmWithJoinedClassProperties(TestEagerLoad):\n def _test(self):\n self.assertEqual(self.query_count, 0)\n post = Post.with_joined(Post.comments, Post.user).get(11)\n self.assertEqual(self.query_count, 1)\n # now, to get relationship, NO additional query is needed\n _ = post.comments[0]\n _ = post.user\n self.assertEqual(self.query_count, 1)\nclass TestOrmWithSubquery(TestEagerLoad):", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "TestOrmWithSubquery", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class TestOrmWithSubquery(TestEagerLoad):\n def test(self):\n self.assertEqual(self.query_count, 0)\n # take post with user and comments (including comment author)\n # NOTE: you can separate relations with dot.\n # Its due to SQLAlchemy: https://goo.gl/yM2DLX\n post = Post.with_subquery(Post.user, Post.comments).get(11)\n # 3 queries were executed:\n # 1 - on posts\n # 2 - on user (eagerload subquery)", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "TestOrmWithSubqueryClassProperties", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class TestOrmWithSubqueryClassProperties(TestEagerLoad):\n def test(self):\n self.assertEqual(self.query_count, 0)\n post = Post.with_subquery(Post.comments, Post.user).get(11)\n # 3 queries were executed:\n # 1 - on posts\n # 2 - on comments (eagerload subquery)\n # 3 - on user (eagerload subquery)\n self.assertEqual(self.query_count, 3)\n # now, to get relationship, NO additional query is needed", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "TestOrmWithDict", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class TestOrmWithDict(TestEagerLoad):\n def _test_joinedload(self, schema):\n self.assertEqual(self.query_count, 0)\n post = Post.with_(schema).get(11)\n self.assertEqual(self.query_count, 1)\n # now, to get relationship, NO additional query is needed\n _ = post.comments[0]\n self.assertEqual(self.query_count, 1)\n def test_joinedload_class_properties(self):\n schema = {Post.comments: JOINED}", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, EagerLoadMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "sess", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "sess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, EagerLoadMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_inspection", + "description": "sqlalchemy_mixins.tests.test_inspection", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = create_engine('sqlite:///:memory:', echo=False)\nclass BaseModel(Base, InspectionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n first_name = sa.Column(sa.String)", + "detail": "sqlalchemy_mixins.tests.test_inspection", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_inspection", + "description": "sqlalchemy_mixins.tests.test_inspection", + "peekOfCode": "class BaseModel(Base, InspectionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n first_name = sa.Column(sa.String)\n last_name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\n posts_viewonly = sa.orm.relationship('Post', viewonly=True)", + "detail": "sqlalchemy_mixins.tests.test_inspection", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_inspection", + "description": "sqlalchemy_mixins.tests.test_inspection", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n first_name = sa.Column(sa.String)\n last_name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\n posts_viewonly = sa.orm.relationship('Post', viewonly=True)\n @hybrid_property\n def surname(self):\n return self.last_name", + "detail": "sqlalchemy_mixins.tests.test_inspection", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_inspection", + "description": "sqlalchemy_mixins.tests.test_inspection", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\nclass Parent(BaseModel):\n __tablename__ = 'parent'\n id = sa.Column(sa.Integer, primary_key=True)\nclass Child(Parent):\n some_prop = sa.Column(sa.String)", + "detail": "sqlalchemy_mixins.tests.test_inspection", + "documentation": {} + }, + { + "label": "Parent", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_inspection", + "description": "sqlalchemy_mixins.tests.test_inspection", + "peekOfCode": "class Parent(BaseModel):\n __tablename__ = 'parent'\n id = sa.Column(sa.Integer, primary_key=True)\nclass Child(Parent):\n some_prop = sa.Column(sa.String)\nclass ModelWithTwoPks(BaseModel):\n __tablename__ = 'two_pks'\n pk1 = sa.Column(sa.Integer, primary_key=True)\n pk2 = sa.Column(sa.Integer, primary_key=True)\nclass TestSessionMixin(unittest.TestCase):", + "detail": "sqlalchemy_mixins.tests.test_inspection", + "documentation": {} + }, + { + "label": "Child", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_inspection", + "description": "sqlalchemy_mixins.tests.test_inspection", + "peekOfCode": "class Child(Parent):\n some_prop = sa.Column(sa.String)\nclass ModelWithTwoPks(BaseModel):\n __tablename__ = 'two_pks'\n pk1 = sa.Column(sa.Integer, primary_key=True)\n pk2 = sa.Column(sa.Integer, primary_key=True)\nclass TestSessionMixin(unittest.TestCase):\n def setUp(self):\n Base.metadata.create_all(engine)\n def test_columns(self):", + "detail": "sqlalchemy_mixins.tests.test_inspection", + "documentation": {} + }, + { + "label": "ModelWithTwoPks", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_inspection", + "description": "sqlalchemy_mixins.tests.test_inspection", + "peekOfCode": "class ModelWithTwoPks(BaseModel):\n __tablename__ = 'two_pks'\n pk1 = sa.Column(sa.Integer, primary_key=True)\n pk2 = sa.Column(sa.Integer, primary_key=True)\nclass TestSessionMixin(unittest.TestCase):\n def setUp(self):\n Base.metadata.create_all(engine)\n def test_columns(self):\n self.assertEqual(set(User.columns), {'id', 'first_name', 'last_name'})\n self.assertEqual(set(Post.columns), {'id', 'body', 'user_id'})", + "detail": "sqlalchemy_mixins.tests.test_inspection", + "documentation": {} + }, + { + "label": "TestSessionMixin", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_inspection", + "description": "sqlalchemy_mixins.tests.test_inspection", + "peekOfCode": "class TestSessionMixin(unittest.TestCase):\n def setUp(self):\n Base.metadata.create_all(engine)\n def test_columns(self):\n self.assertEqual(set(User.columns), {'id', 'first_name', 'last_name'})\n self.assertEqual(set(Post.columns), {'id', 'body', 'user_id'})\n def test_nested_columns(self):\n self.assertEqual(set(Parent.columns), {'id'})\n self.assertEqual(set(Child.columns), {'id', 'some_prop'})\n def test_primary_keys(self):", + "detail": "sqlalchemy_mixins.tests.test_inspection", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_inspection", + "description": "sqlalchemy_mixins.tests.test_inspection", + "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nclass BaseModel(Base, InspectionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n first_name = sa.Column(sa.String)\n last_name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')", + "detail": "sqlalchemy_mixins.tests.test_inspection", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_repr", + "description": "sqlalchemy_mixins.tests.test_repr", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n # !!! IMPORTANT !!!\n # include below string to make mixin work\n __repr__ = ReprMixin.__repr__", + "detail": "sqlalchemy_mixins.tests.test_repr", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_repr", + "description": "sqlalchemy_mixins.tests.test_repr", + "peekOfCode": "class BaseModel(Base, ReprMixin):\n __abstract__ = True\n # !!! IMPORTANT !!!\n # include below string to make mixin work\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "sqlalchemy_mixins.tests.test_repr", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_repr", + "description": "sqlalchemy_mixins.tests.test_repr", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\nclass Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "sqlalchemy_mixins.tests.test_repr", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_repr", + "description": "sqlalchemy_mixins.tests.test_repr", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')\nclass Comment(BaseModel):", + "detail": "sqlalchemy_mixins.tests.test_repr", + "documentation": {} + }, + { + "label": "Comment", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_repr", + "description": "sqlalchemy_mixins.tests.test_repr", + "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body', 'post', 'user']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n user = sa.orm.relationship('User')\n post = sa.orm.relationship('Post')", + "detail": "sqlalchemy_mixins.tests.test_repr", + "documentation": {} + }, + { + "label": "TestEagerLoad", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_repr", + "description": "sqlalchemy_mixins.tests.test_repr", + "peekOfCode": "class TestEagerLoad(unittest.TestCase):\n def test(self):\n Base.metadata.drop_all(engine)\n Base.metadata.create_all(engine)\n u1 = User(name='Bill u1', id=1)\n sess.add(u1)\n sess.commit()\n u2 = User(name='Alex u2', id=2)\n sess.add(u2)\n sess.commit()", + "detail": "sqlalchemy_mixins.tests.test_repr", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_repr", + "description": "sqlalchemy_mixins.tests.test_repr", + "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n # !!! IMPORTANT !!!\n # include below string to make mixin work\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):", + "detail": "sqlalchemy_mixins.tests.test_repr", + "documentation": {} + }, + { + "label": "sess", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_repr", + "description": "sqlalchemy_mixins.tests.test_repr", + "peekOfCode": "sess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n # !!! IMPORTANT !!!\n # include below string to make mixin work\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'", + "detail": "sqlalchemy_mixins.tests.test_repr", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_serialize", + "description": "sqlalchemy_mixins.tests.test_serialize", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nclass BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')", + "detail": "sqlalchemy_mixins.tests.test_serialize", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_serialize", + "description": "sqlalchemy_mixins.tests.test_serialize", + "peekOfCode": "class BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\n password = sa.Column(sa.String)\n @hybrid_property", + "detail": "sqlalchemy_mixins.tests.test_serialize", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_serialize", + "description": "sqlalchemy_mixins.tests.test_serialize", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\n password = sa.Column(sa.String)\n @hybrid_property\n def posts_count(self):\n return len(self.posts)\nclass Post(BaseModel):", + "detail": "sqlalchemy_mixins.tests.test_serialize", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_serialize", + "description": "sqlalchemy_mixins.tests.test_serialize", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')\nclass Comment(BaseModel):\n __tablename__ = 'comment'", + "detail": "sqlalchemy_mixins.tests.test_serialize", + "documentation": {} + }, + { + "label": "Comment", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_serialize", + "description": "sqlalchemy_mixins.tests.test_serialize", + "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n user = sa.orm.relationship('User')\n post = sa.orm.relationship('Post')\nclass TestSerialize(unittest.TestCase):", + "detail": "sqlalchemy_mixins.tests.test_serialize", + "documentation": {} + }, + { + "label": "TestSerialize", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_serialize", + "description": "sqlalchemy_mixins.tests.test_serialize", + "peekOfCode": "class TestSerialize(unittest.TestCase):\n @classmethod\n def setUpClass(cls):\n cls.engine = create_engine('sqlite:///:memory:', echo=False)\n def setUp(self):\n self.session = Session(self.engine)\n Base.metadata.create_all(self.engine)\n user_1 = User(name='Bill u1', id=1 , password = 'pass1')\n self.session.add(user_1)\n self.session.commit()", + "detail": "sqlalchemy_mixins.tests.test_serialize", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_session", + "description": "sqlalchemy_mixins.tests.test_session", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = create_engine('sqlite:///:memory:', echo=False)\nsession = Session(engine)\nclass BaseModel(Base, SessionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "sqlalchemy_mixins.tests.test_session", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_session", + "description": "sqlalchemy_mixins.tests.test_session", + "peekOfCode": "class BaseModel(Base, SessionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "sqlalchemy_mixins.tests.test_session", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_session", + "description": "sqlalchemy_mixins.tests.test_session", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\nclass TestSessionMixin(unittest.TestCase):\n def setUp(self):", + "detail": "sqlalchemy_mixins.tests.test_session", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_session", + "description": "sqlalchemy_mixins.tests.test_session", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\nclass TestSessionMixin(unittest.TestCase):\n def setUp(self):\n Base.metadata.create_all(engine)\n def test_set_session(self):\n # before setting session, error is raised\n with self.assertRaises(NoSessionError):", + "detail": "sqlalchemy_mixins.tests.test_session", + "documentation": {} + }, + { + "label": "TestSessionMixin", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_session", + "description": "sqlalchemy_mixins.tests.test_session", + "peekOfCode": "class TestSessionMixin(unittest.TestCase):\n def setUp(self):\n Base.metadata.create_all(engine)\n def test_set_session(self):\n # before setting session, error is raised\n with self.assertRaises(NoSessionError):\n _ = BaseModel.session\n with self.assertRaises(NoSessionError):\n _ = User.session\n with self.assertRaises(NoSessionError):", + "detail": "sqlalchemy_mixins.tests.test_session", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_session", + "description": "sqlalchemy_mixins.tests.test_session", + "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nsession = Session(engine)\nclass BaseModel(Base, SessionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):", + "detail": "sqlalchemy_mixins.tests.test_session", + "documentation": {} + }, + { + "label": "session", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_session", + "description": "sqlalchemy_mixins.tests.test_session", + "peekOfCode": "session = Session(engine)\nclass BaseModel(Base, SessionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'", + "detail": "sqlalchemy_mixins.tests.test_session", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SmartQueryMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class BaseModel(Base, SmartQueryMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n # to smart query relationship, it should be explicitly set,\n # not to be a backref", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n # to smart query relationship, it should be explicitly set,\n # not to be a backref\n posts = sa.orm.relationship('Post')\n comments = sa.orm.relationship('Comment')\n # below relationship will just return query (without executing)", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n # to smart query relationship, it should be explicitly set,\n # not to be a backref\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "Comment", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n created_at = sa.Column(sa.DateTime)\n # to smart query relationship, it should be explicitly set,", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "BaseTest", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class BaseTest(unittest.TestCase):\n def setUp(self):\n sess.rollback()\n BaseModel.set_session(None)\n Base.metadata.drop_all(engine)\n Base.metadata.create_all(engine)\n BaseModel.set_session(sess)\n def _seed(self):\n u1 = User(name='Bill u1')\n sess.add(u1)", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "TestFilterExpr", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class TestFilterExpr(BaseTest):\n # def setUp(self):\n # Base.metadata.create_all(engine)\n def test_filterable_attributes(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n self.assertEqual(set(User.filterable_attributes),\n {'id', 'name', # normal columns\n 'posts', 'comments', 'comments_' # relations\n })", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "TestOrderExpr", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class TestOrderExpr(BaseTest):\n def test_incorrect_expr(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n with self.assertRaises(KeyError):\n _ = sess.query(Post).filter(\n *Post.order_expr('INCORRECT_ATTR')).all()\n with self.assertRaises(KeyError):\n _ = sess.query(Post).filter(\n *Post.order_expr('*body')).all()", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "TestSmartQueryFilters", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class TestSmartQueryFilters(BaseTest):\n def test_incorrect_expr(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n with self.assertRaises(KeyError):\n _ = User.where(INCORRECT_ATTR='nomatter').all()\n def test_is_a_shortcut_to_filter_expr_in_simple_cases(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n \"\"\"when have no joins, where() is a shortcut for filter_expr \"\"\"", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "TestSmartQuerySort", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class TestSmartQuerySort(BaseTest):\n def test_incorrect_expr(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n with self.assertRaises(KeyError):\n _ = Post.sort('INCORRECT_ATTR').all()\n with self.assertRaises(KeyError):\n _ = Post.sort('*body').all()\n def test_is_a_shortcut_to_order_expr_in_simple_cases(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "TestFullSmartQuery", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class TestFullSmartQuery(BaseTest):\n def test_schema_with_strings(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n # standalone function\n query = Comment.query\n res = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "TestSmartQueryAutoEagerLoad", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class TestSmartQueryAutoEagerLoad(BaseTest):\n \"\"\"\n Smart_query does auto-joins for filtering/sorting,\n so there's a sense to tell sqlalchemy that we alreeady joined that relation\n So we test that relations are set to be joinedload\n if they were used in smart_query()\n \"\"\"\n def _seed(self):\n result = BaseTest._seed(self)\n self.query_count = 0", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SmartQueryMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "sess", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "sess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SmartQueryMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_timestamp", + "description": "sqlalchemy_mixins.tests.test_timestamp", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nclass BaseModel(Base, TimestampsMixin):\n \"\"\"Model to use as base.\"\"\"\n __abstract__ = True\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass User(BaseModel):\n \"\"\"User model exemple.\"\"\"\n __tablename__ = 'user'", + "detail": "sqlalchemy_mixins.tests.test_timestamp", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_timestamp", + "description": "sqlalchemy_mixins.tests.test_timestamp", + "peekOfCode": "class BaseModel(Base, TimestampsMixin):\n \"\"\"Model to use as base.\"\"\"\n __abstract__ = True\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass User(BaseModel):\n \"\"\"User model exemple.\"\"\"\n __tablename__ = 'user'\nclass TestTimestamps(unittest.TestCase):\n \"\"\"Test case for Timestamp mixin.\"\"\"", + "detail": "sqlalchemy_mixins.tests.test_timestamp", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_timestamp", + "description": "sqlalchemy_mixins.tests.test_timestamp", + "peekOfCode": "class User(BaseModel):\n \"\"\"User model exemple.\"\"\"\n __tablename__ = 'user'\nclass TestTimestamps(unittest.TestCase):\n \"\"\"Test case for Timestamp mixin.\"\"\"\n @classmethod\n def setUpClass(cls):\n cls.engine = create_engine('sqlite:///:memory:', echo=False)\n def setUp(self):\n self.session = Session(self.engine)", + "detail": "sqlalchemy_mixins.tests.test_timestamp", + "documentation": {} + }, + { + "label": "TestTimestamps", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_timestamp", + "description": "sqlalchemy_mixins.tests.test_timestamp", + "peekOfCode": "class TestTimestamps(unittest.TestCase):\n \"\"\"Test case for Timestamp mixin.\"\"\"\n @classmethod\n def setUpClass(cls):\n cls.engine = create_engine('sqlite:///:memory:', echo=False)\n def setUp(self):\n self.session = Session(self.engine)\n Base.metadata.create_all(self.engine)\n user_1 = User(name='User')\n self.session.add(user_1)", + "detail": "sqlalchemy_mixins.tests.test_timestamp", + "documentation": {} + }, + { + "label": "ModelNotFoundError", + "kind": 6, + "importPath": "sqlalchemy_mixins.activerecord", + "description": "sqlalchemy_mixins.activerecord", + "peekOfCode": "class ModelNotFoundError(ValueError):\n pass\nclass ActiveRecordMixin(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classproperty\n def settable_attributes(cls):\n return cls.columns + cls.hybrid_properties + cls.settable_relations\n def fill(self, **kwargs):\n for name in kwargs.keys():\n if name in self.settable_attributes:", + "detail": "sqlalchemy_mixins.activerecord", + "documentation": {} + }, + { + "label": "ActiveRecordMixin", + "kind": 6, + "importPath": "sqlalchemy_mixins.activerecord", + "description": "sqlalchemy_mixins.activerecord", + "peekOfCode": "class ActiveRecordMixin(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classproperty\n def settable_attributes(cls):\n return cls.columns + cls.hybrid_properties + cls.settable_relations\n def fill(self, **kwargs):\n for name in kwargs.keys():\n if name in self.settable_attributes:\n setattr(self, name, kwargs[name])\n else:", + "detail": "sqlalchemy_mixins.activerecord", + "documentation": {} + }, + { + "label": "ActiveRecordMixinAsync", + "kind": 6, + "importPath": "sqlalchemy_mixins.activerecordasync", + "description": "sqlalchemy_mixins.activerecordasync", + "peekOfCode": "class ActiveRecordMixinAsync(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classproperty\n def query(cls):\n \"\"\"\n Override the default query property to handle async session.\n \"\"\"\n if not hasattr(cls.session, \"query\"):\n return select(cls)\n return cls.session.query(cls)", + "detail": "sqlalchemy_mixins.activerecordasync", + "documentation": {} + }, + { + "label": "async_root_cls", + "kind": 2, + "importPath": "sqlalchemy_mixins.activerecordasync", + "description": "sqlalchemy_mixins.activerecordasync", + "peekOfCode": "def async_root_cls(query: Query):\n \"\"\"Monkey patch SmaryQuery to handle async queries.\"\"\"\n try:\n return get_root_cls(query)\n except ValueError:\n # Handle async queries\n if query.__dict__[\"_propagate_attrs\"][\"plugin_subject\"].class_:\n return query.__dict__[\"_propagate_attrs\"][\"plugin_subject\"].class_\n raise\nSmaryQuery._get_root_cls = lambda query: async_root_cls(query)", + "detail": "sqlalchemy_mixins.activerecordasync", + "documentation": {} + }, + { + "label": "get_root_cls", + "kind": 5, + "importPath": "sqlalchemy_mixins.activerecordasync", + "description": "sqlalchemy_mixins.activerecordasync", + "peekOfCode": "get_root_cls = SmaryQuery._get_root_cls\ndef async_root_cls(query: Query):\n \"\"\"Monkey patch SmaryQuery to handle async queries.\"\"\"\n try:\n return get_root_cls(query)\n except ValueError:\n # Handle async queries\n if query.__dict__[\"_propagate_attrs\"][\"plugin_subject\"].class_:\n return query.__dict__[\"_propagate_attrs\"][\"plugin_subject\"].class_\n raise", + "detail": "sqlalchemy_mixins.activerecordasync", + "documentation": {} + }, + { + "label": "SmaryQuery._get_root_cls", + "kind": 5, + "importPath": "sqlalchemy_mixins.activerecordasync", + "description": "sqlalchemy_mixins.activerecordasync", + "peekOfCode": "SmaryQuery._get_root_cls = lambda query: async_root_cls(query)\nclass ActiveRecordMixinAsync(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classproperty\n def query(cls):\n \"\"\"\n Override the default query property to handle async session.\n \"\"\"\n if not hasattr(cls.session, \"query\"):\n return select(cls)", + "detail": "sqlalchemy_mixins.activerecordasync", + "documentation": {} + }, + { + "label": "EagerLoadMixin", + "kind": 6, + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "peekOfCode": "class EagerLoadMixin(SessionMixin):\n __abstract__ = True\n @classmethod\n def with_(cls, schema):\n \"\"\"\n Query class and eager load schema at once.\n :type schema: dict\n Example:\n schema = {\n Post.user: JOINED, # joinedload user", + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "eager_expr", + "kind": 2, + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "peekOfCode": "def eager_expr(schema):\n \"\"\"\n :type schema: dict\n \"\"\"\n return _eager_expr_from_schema(schema)\ndef _flatten_schema(schema):\n \"\"\"\n :type schema: dict\n \"\"\"\n def _flatten(schema, parent_path, result):", + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "JOINED", + "kind": 5, + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "peekOfCode": "JOINED = 'joined'\nSUBQUERY = 'subquery'\ndef eager_expr(schema):\n \"\"\"\n :type schema: dict\n \"\"\"\n return _eager_expr_from_schema(schema)\ndef _flatten_schema(schema):\n \"\"\"\n :type schema: dict", + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "SUBQUERY", + "kind": 5, + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "peekOfCode": "SUBQUERY = 'subquery'\ndef eager_expr(schema):\n \"\"\"\n :type schema: dict\n \"\"\"\n return _eager_expr_from_schema(schema)\ndef _flatten_schema(schema):\n \"\"\"\n :type schema: dict\n \"\"\"", + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "InspectionMixin", + "kind": 6, + "importPath": "sqlalchemy_mixins.inspection", + "description": "sqlalchemy_mixins.inspection", + "peekOfCode": "class InspectionMixin:\n @classproperty\n def columns(cls):\n return inspect(cls).columns.keys()\n @classproperty\n def primary_keys_full(cls):\n \"\"\"Get primary key properties for a SQLAlchemy cls.\n Taken from marshmallow_sqlalchemy\n \"\"\"\n mapper = cls.__mapper__", + "detail": "sqlalchemy_mixins.inspection", + "documentation": {} + }, + { + "label": "ReprMixin", + "kind": 6, + "importPath": "sqlalchemy_mixins.repr", + "description": "sqlalchemy_mixins.repr", + "peekOfCode": "class ReprMixin:\n __abstract__ = True\n __repr_attrs__ = []\n __repr_max_length__ = 15\n @property\n def _id_str(self):\n ids = inspect(self).identity\n if ids:\n return '-'.join([str(x) for x in ids]) if len(ids) > 1 \\\n else str(ids[0])", + "detail": "sqlalchemy_mixins.repr", + "documentation": {} + }, + { + "label": "SerializeMixin", + "kind": 6, + "importPath": "sqlalchemy_mixins.serialize", + "description": "sqlalchemy_mixins.serialize", + "peekOfCode": "class SerializeMixin(InspectionMixin):\n \"\"\"Mixin to make model serializable.\"\"\"\n __abstract__ = True\n def to_dict(self,nested = False, hybrid_attributes = False, exclude = None):\n \"\"\"Return dict object with model's data.\n :param nested: flag to return nested relationships' data if true\n :type: bool\n :param hybrid_attributes: flag to include hybrid attributes if true\n :type: bool\n :return: dict", + "detail": "sqlalchemy_mixins.serialize", + "documentation": {} + }, + { + "label": "NoSessionError", + "kind": 6, + "importPath": "sqlalchemy_mixins.session", + "description": "sqlalchemy_mixins.session", + "peekOfCode": "class NoSessionError(RuntimeError):\n pass\nclass SessionMixin:\n _session = None\n @classmethod\n def set_session(cls, session):\n \"\"\"\n :type session: scoped_session | Session\n \"\"\"\n cls._session = session", + "detail": "sqlalchemy_mixins.session", + "documentation": {} + }, + { + "label": "SessionMixin", + "kind": 6, + "importPath": "sqlalchemy_mixins.session", + "description": "sqlalchemy_mixins.session", + "peekOfCode": "class SessionMixin:\n _session = None\n @classmethod\n def set_session(cls, session):\n \"\"\"\n :type session: scoped_session | Session\n \"\"\"\n cls._session = session\n @classproperty\n def session(cls):", + "detail": "sqlalchemy_mixins.session", + "documentation": {} + }, + { + "label": "SmartQueryMixin", + "kind": 6, + "importPath": "sqlalchemy_mixins.smartquery", + "description": "sqlalchemy_mixins.smartquery", + "peekOfCode": "class SmartQueryMixin(InspectionMixin, EagerLoadMixin):\n __abstract__ = True\n _operators = {\n 'isnull': lambda c, v: (c == None) if v else (c != None),\n 'exact': operators.eq,\n 'ne': operators.ne, # not equal or is not (for None)\n 'gt': operators.gt, # greater than , >\n 'ge': operators.ge, # greater than or equal, >=\n 'lt': operators.lt, # lower than, <\n 'le': operators.le, # lower than or equal, <=", + "detail": "sqlalchemy_mixins.smartquery", + "documentation": {} + }, + { + "label": "smart_query", + "kind": 2, + "importPath": "sqlalchemy_mixins.smartquery", + "description": "sqlalchemy_mixins.smartquery", + "peekOfCode": "def smart_query(query, filters=None, sort_attrs=None, schema=None):\n \"\"\"\n Does magic Django-ish joins like post___user___name__startswith='Bob'\n (see https://goo.gl/jAgCyM)\n Does filtering, sorting and eager loading at the same time.\n And if, say, filters and sorting need the same joinm it will be done\n only one. That's why all stuff is combined in single method\n :param query: sqlalchemy.orm.query.Query\n :param filters: dict\n :param sort_attrs: List[basestring]", + "detail": "sqlalchemy_mixins.smartquery", + "documentation": {} + }, + { + "label": "RELATION_SPLITTER", + "kind": 5, + "importPath": "sqlalchemy_mixins.smartquery", + "description": "sqlalchemy_mixins.smartquery", + "peekOfCode": "RELATION_SPLITTER = '___'\nOPERATOR_SPLITTER = '__'\nDESC_PREFIX = '-'\ndef _flatten_filter_keys(filters):\n \"\"\"\n :type filters: dict|list\n Flatten the nested filters, extracting keys where they correspond \n to smart_query paths, e.g. \n {or_: {'id__gt': 1000, and_ : {\n 'id__lt': 500,", + "detail": "sqlalchemy_mixins.smartquery", + "documentation": {} + }, + { + "label": "OPERATOR_SPLITTER", + "kind": 5, + "importPath": "sqlalchemy_mixins.smartquery", + "description": "sqlalchemy_mixins.smartquery", + "peekOfCode": "OPERATOR_SPLITTER = '__'\nDESC_PREFIX = '-'\ndef _flatten_filter_keys(filters):\n \"\"\"\n :type filters: dict|list\n Flatten the nested filters, extracting keys where they correspond \n to smart_query paths, e.g. \n {or_: {'id__gt': 1000, and_ : {\n 'id__lt': 500,\n 'related___property__in': (1,2,3) ", + "detail": "sqlalchemy_mixins.smartquery", + "documentation": {} + }, + { + "label": "DESC_PREFIX", + "kind": 5, + "importPath": "sqlalchemy_mixins.smartquery", + "description": "sqlalchemy_mixins.smartquery", + "peekOfCode": "DESC_PREFIX = '-'\ndef _flatten_filter_keys(filters):\n \"\"\"\n :type filters: dict|list\n Flatten the nested filters, extracting keys where they correspond \n to smart_query paths, e.g. \n {or_: {'id__gt': 1000, and_ : {\n 'id__lt': 500,\n 'related___property__in': (1,2,3) \n }}}", + "detail": "sqlalchemy_mixins.smartquery", + "documentation": {} + }, + { + "label": "TimestampsMixin", + "kind": 6, + "importPath": "sqlalchemy_mixins.timestamp", + "description": "sqlalchemy_mixins.timestamp", + "peekOfCode": "class TimestampsMixin:\n \"\"\"Mixin that define timestamp columns.\"\"\"\n __abstract__ = True\n __created_at_name__ = 'created_at'\n __updated_at_name__ = 'updated_at'\n __datetime_func__ = sa.func.now()\n created_at = sa.Column(__created_at_name__,\n sa.TIMESTAMP(timezone=False),\n default=__datetime_func__,\n nullable=False)", + "detail": "sqlalchemy_mixins.timestamp", + "documentation": {} + }, + { + "label": "classproperty", + "kind": 6, + "importPath": "sqlalchemy_mixins.utils", + "description": "sqlalchemy_mixins.utils", + "peekOfCode": "class classproperty(object):\n \"\"\"\n @property for @classmethod\n taken from http://stackoverflow.com/a/13624858\n \"\"\"\n def __init__(self, fget):\n self.fget = fget\n def __get__(self, owner_self, owner_cls):\n return self.fget(owner_cls)\ndef get_relations(cls):", + "detail": "sqlalchemy_mixins.utils", + "documentation": {} + }, + { + "label": "get_relations", + "kind": 2, + "importPath": "sqlalchemy_mixins.utils", + "description": "sqlalchemy_mixins.utils", + "peekOfCode": "def get_relations(cls):\n if isinstance(cls, Mapper):\n mapper = cls\n else:\n mapper = cls.__mapper__\n return [c for c in mapper.attrs\n if isinstance(c, RelationshipProperty)]\ndef path_to_relations_list(cls, path):\n path_as_list = path.split('.')\n relations = get_relations(cls)", + "detail": "sqlalchemy_mixins.utils", + "documentation": {} + }, + { + "label": "path_to_relations_list", + "kind": 2, + "importPath": "sqlalchemy_mixins.utils", + "description": "sqlalchemy_mixins.utils", + "peekOfCode": "def path_to_relations_list(cls, path):\n path_as_list = path.split('.')\n relations = get_relations(cls)\n relations_list = []\n for item in path_as_list:\n for rel in relations:\n if rel.key == item:\n relations_list.append(rel)\n relations = get_relations(rel.entity)\n break", + "detail": "sqlalchemy_mixins.utils", + "documentation": {} + }, + { + "label": "requirements", + "kind": 2, + "importPath": "setup", + "description": "setup", + "peekOfCode": "def requirements():\n import os\n filename = os.path.join(os.path.dirname(__file__), 'requirements.txt')\n return [line.rstrip('\\n') for line in open(filename).readlines()]\nsetup(name='sqlalchemy_mixins',\n version='2.0.5',\n description='Active Record, Django-like queries, nested eager load '\n 'and beauty __repr__ for SQLAlchemy',\n url='https://github.com/absent1706/sqlalchemy-mixins',\n download_url='https://github.com/absent1706/sqlalchemy-mixins/archive/master.tar.gz',", + "detail": "setup", + "documentation": {} + } +] \ No newline at end of file diff --git a/sqlalchemy_mixins/__init__.py b/sqlalchemy_mixins/__init__.py index 42814dc..051ce4c 100644 --- a/sqlalchemy_mixins/__init__.py +++ b/sqlalchemy_mixins/__init__.py @@ -4,6 +4,7 @@ # high-level mixins from .activerecord import ActiveRecordMixin, ModelNotFoundError +from .activerecordasync import ActiveRecordMixinAsync from .smartquery import SmartQueryMixin, smart_query from .eagerload import EagerLoadMixin, JOINED, SUBQUERY from .repr import ReprMixin @@ -19,6 +20,7 @@ class AllFeaturesMixin(ActiveRecordMixin, SmartQueryMixin, ReprMixin, SerializeM __all__ = [ "ActiveRecordMixin", + "ActiveRecordMixinAsync", "AllFeaturesMixin", "EagerLoadMixin", "InspectionMixin", diff --git a/sqlalchemy_mixins/activerecordasync.py b/sqlalchemy_mixins/activerecordasync.py new file mode 100644 index 0000000..b01ef28 --- /dev/null +++ b/sqlalchemy_mixins/activerecordasync.py @@ -0,0 +1,201 @@ +from sqlalchemy import select +from sqlalchemy.orm import Query +from .utils import classproperty +from .session import SessionMixin +from .inspection import InspectionMixin +from .activerecord import ModelNotFoundError +from . import smartquery as SmaryQuery + +get_root_cls = SmaryQuery._get_root_cls +def async_root_cls(query: Query): + """Monkey patch SmaryQuery to handle async queries.""" + try: + return get_root_cls(query) + except ValueError: + # Handle async queries + if query.__dict__["_propagate_attrs"]["plugin_subject"].class_: + return query.__dict__["_propagate_attrs"]["plugin_subject"].class_ + raise + +SmaryQuery._get_root_cls = lambda query: async_root_cls(query) + + +class ActiveRecordMixinAsync(InspectionMixin, SessionMixin): + __abstract__ = True + + @classproperty + def query(cls): + """ + Override the default query property to handle async session. + """ + if not hasattr(cls.session, "query"): + return select(cls) + + return cls.session.query(cls) + + async def save_async(self): + """ + Async version of :meth:`save` method. + + :see: :meth:`save` method for more information. + """ + async with self.session() as session: + try: + session.add(self) + await session.commit() + return self + except: + await session.rollback() + raise + + @classmethod + async def create_async(cls, **kwargs): + """ + Async version of :meth:`create` method. + + :see: :meth:`create` + """ + return await cls().fill(**kwargs).save_async() + + async def update_async(self, **kwargs): + """ + Async version of :meth:`update` method. + + :see: :meth:`update` + """ + return await self.fill(**kwargs).save_async() + + async def delete_async(self): + """ + Async version of :meth:`delete` method. + + :see: :meth:`delete` + """ + async with self.session() as session: + try: + session.sync_session.delete(self) + await session.commit() + return self + except: + await session.rollback() + raise + finally: + await session.flush() + + @classmethod + async def destroy_async(cls, *ids): + """ + Async version of :meth:`destroy` method. + + :see: :meth:`destroy` + """ + primary_key = cls._get_primary_key_name() + if primary_key: + async with cls.session() as session: + try: + for row in await cls.where_async(**{f"{primary_key}__in": ids}): + session.sync_session.delete(row) + await session.commit() + except: + await session.rollback() + raise + await session.flush() + + @classmethod + async def select_async(cls, stmt=None, filters=None, sort_attrs=None, schema=None): + async with cls.session() as session: + if stmt is None: + stmt = cls.smart_query( + filters=filters, sort_attrs=sort_attrs, schema=schema) + return (await session.execute(stmt)).scalars() + + @classmethod + async def where_async(cls, **filters): + """ + Aync version of where method. + + :see: :meth:`where` method for more details. + """ + return await cls.select_async(filters=filters) + + @classmethod + async def sort_async(cls, *columns): + """ + Async version of sort method. + + :see: :meth:`sort` method for more details. + """ + return await cls.select_async(sort_attrs=columns) + + @classmethod + async def all_async(cls): + """ + Async version of all method. + This is same as calling ``(await select_async()).all()``. + + :see: :meth:`all` method for more details. + """ + return (await cls.select_async()).all() + + @classmethod + async def first_async(cls): + """ + Async version of first method. + This is same as calling ``(await select_async()).first()``. + + :see: :meth:`first` method for more details. + """ + return (await cls.select_async()).first() + + @classmethod + async def find_async(cls, id_): + """ + Async version of find method. + + :see: :meth:`find` method for more details. + """ + primary_key = cls._get_primary_key_name() + if primary_key: + return (await cls.where_async(**{primary_key: id_})).first() + return None + + @classmethod + async def find_or_fail_async(cls, id_): + """ + Async version of find_or_fail method. + + :see: :meth:`find_or_fail` method for more details. + """ + cursor = await cls.find_async(id_) + if cursor: + return cursor + else: + raise ModelNotFoundError("{} with id '{}' was not found" + .format(cls.__name__, id_)) + + @classmethod + async def with_async(cls, schema): + """ + Async version of with method. + + :see: :meth:`with` method for more details. + """ + return await cls.select_async(cls.with_(schema)) + + @classmethod + async def with_joined_async(cls, *paths): + """ + Async version of with_joined method. + + :see: :meth:`with_joined` method for more details. + """ + return await cls.select_async(cls.with_joined(*paths)) + + @classmethod + async def with_subquery_async(cls, *paths): + """ + Async version of with_subquery method. + + :see: :meth:`with_subquery` method for more details. + """ + return await cls.select_async(cls.with_subquery(*paths)) diff --git a/sqlalchemy_mixins/activerecordasync.pyi b/sqlalchemy_mixins/activerecordasync.pyi new file mode 100644 index 0000000..de80ce2 --- /dev/null +++ b/sqlalchemy_mixins/activerecordasync.pyi @@ -0,0 +1,59 @@ +from typing import Dict, Iterable, List, Any, Optional + +from sqlalchemy_mixins.inspection import InspectionMixin +from sqlalchemy_mixins.session import SessionMixin +from sqlalchemy_mixins.utils import classproperty +from sqlalchemy.orm import Query, QueryableAttribute + + +class ActiveRecordMixinAsync(InspectionMixin, SessionMixin): + + @classproperty + def settable_attributes(cls) -> List[str]: ... + + async def save_async(self) -> "ActiveRecordMixinAsync": ... + + @classmethod + async def create_async(cls, **kwargs: Any) -> "ActiveRecordMixinAsync": ... + + async def update_async(self, **kwargs: dict) -> "ActiveRecordMixinAsync": ... + + async def delete_async(self) -> None: ... + + @classmethod + async def destroy_async(cls, *ids: list) -> None: ... + + @classmethod + async def all_async(cls) -> List["ActiveRecordMixinAsync"]: ... + + @classmethod + async def first_async(cls) -> Optional["ActiveRecordMixinAsync"]: ... + + @classmethod + async def find_async(cls, id_: Any) -> Optional["ActiveRecordMixinAsync"]: ... + + @classmethod + async def find_or_fail_async(cls, id_: Any) -> "ActiveRecordMixinAsync": ... + + @classmethod + async def select_async(cls, + stmt:Optional[str] = None, + filters: Optional[Dict[str, Any]] = None, + sort_attrs: Optional[Iterable[str]] = None, + schema: Optional[dict] = None + ) -> "ActiveRecordMixinAsync": ... + + @classmethod + async def where_async(cls, **filters: Any) -> Query: ... + + @classmethod + async def sort_async(cls, *columns: str) -> Query: ... + + @classmethod + async def with_async(cls, schema: dict) -> Query: ... + + @classmethod + async def with_joined_async(cls, *paths: List[QueryableAttribute]) -> Query: ... + + @classmethod + async def with_subquery_async(cls, *paths: List[QueryableAttribute]) -> Query: ... From bc47412ae476c42c2fa3e74e50922c9dad8711d1 Mon Sep 17 00:00:00 2001 From: Aurthur Musendame Date: Sun, 1 Sep 2024 17:40:08 +0200 Subject: [PATCH 2/6] added tests for the async active record with smart query --- .vscode/PythonImportHelper-v2-Completion.json | 155 ++++++++++++- requirements-dev.txt | 3 +- sqlalchemy_mixins/activerecordasync.py | 36 ++- .../tests/test_activerecordasync.py | 210 ++++++++++++++++++ 4 files changed, 400 insertions(+), 4 deletions(-) create mode 100644 sqlalchemy_mixins/tests/test_activerecordasync.py diff --git a/.vscode/PythonImportHelper-v2-Completion.json b/.vscode/PythonImportHelper-v2-Completion.json index 83f2f09..1344ccc 100644 --- a/.vscode/PythonImportHelper-v2-Completion.json +++ b/.vscode/PythonImportHelper-v2-Completion.json @@ -273,6 +273,14 @@ "detail": "sqlalchemy.ext.hybrid", "documentation": {} }, + { + "label": "hybrid_property", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, { "label": "hybrid_method", "importPath": "sqlalchemy.ext.hybrid", @@ -537,6 +545,30 @@ "detail": "sqlalchemy.orm", "documentation": {} }, + { + "label": "sessionmaker", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "selectinload", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "relationship", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, { "label": "Query", "importPath": "sqlalchemy.orm", @@ -889,6 +921,22 @@ "detail": "sqlalchemy_mixins", "documentation": {} }, + { + "label": "ActiveRecordMixinAsync", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "SmartQueryMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, { "label": "EagerLoadMixin", "importPath": "sqlalchemy_mixins", @@ -1060,6 +1108,47 @@ "detail": "sqlalchemy_mixins.activerecord", "documentation": {} }, + { + "label": "ModelNotFoundError", + "importPath": "sqlalchemy_mixins.activerecord", + "description": "sqlalchemy_mixins.activerecord", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.activerecord", + "documentation": {} + }, + { + "label": "asyncio", + "kind": 6, + "isExtraImport": true, + "importPath": "asyncio", + "description": "asyncio", + "detail": "asyncio", + "documentation": {} + }, + { + "label": "create_async_engine", + "importPath": "sqlalchemy.ext.asyncio", + "description": "sqlalchemy.ext.asyncio", + "isExtraImport": true, + "detail": "sqlalchemy.ext.asyncio", + "documentation": {} + }, + { + "label": "AsyncSession", + "importPath": "sqlalchemy.ext.asyncio", + "description": "sqlalchemy.ext.asyncio", + "isExtraImport": true, + "detail": "sqlalchemy.ext.asyncio", + "documentation": {} + }, + { + "label": "declarative_base", + "importPath": "sqlalchemy.ext.declarative", + "description": "sqlalchemy.ext.declarative", + "isExtraImport": true, + "detail": "sqlalchemy.ext.declarative", + "documentation": {} + }, { "label": "SessionMixin", "importPath": "sqlalchemy_mixins.session", @@ -1076,6 +1165,14 @@ "detail": "sqlalchemy_mixins.session", "documentation": {} }, + { + "label": "InvalidRequestError", + "importPath": "sqlalchemy.exc", + "description": "sqlalchemy.exc", + "isExtraImport": true, + "detail": "sqlalchemy.exc", + "documentation": {} + }, { "label": "_AbstractLoad", "importPath": "sqlalchemy.orm.strategy_options", @@ -2363,6 +2460,60 @@ "detail": "sqlalchemy_mixins.tests.test_activerecord", "documentation": {} }, + { + "label": "AsyncBaseModel", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", + "description": "sqlalchemy_mixins.tests.test_activerecordasync", + "peekOfCode": "class AsyncBaseModel(Base, ActiveRecordMixinAsync, SmartQueryMixin):\n __abstract__ = True\nclass User(AsyncBaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = relationship('Post', backref='user', lazy=\"selectin\")\n posts_viewonly = relationship('Post', viewonly=True)\nclass Post(AsyncBaseModel):", + "detail": "sqlalchemy_mixins.tests.test_activerecordasync", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", + "description": "sqlalchemy_mixins.tests.test_activerecordasync", + "peekOfCode": "class User(AsyncBaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = relationship('Post', backref='user', lazy=\"selectin\")\n posts_viewonly = relationship('Post', viewonly=True)\nclass Post(AsyncBaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "sqlalchemy_mixins.tests.test_activerecordasync", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", + "description": "sqlalchemy_mixins.tests.test_activerecordasync", + "peekOfCode": "class Post(AsyncBaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n comments = relationship('Comment', backref='post', lazy=\"selectin\")\n @hybrid_property\n def public(self):\n return not self.archived", + "detail": "sqlalchemy_mixins.tests.test_activerecordasync", + "documentation": {} + }, + { + "label": "Comment", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", + "description": "sqlalchemy_mixins.tests.test_activerecordasync", + "peekOfCode": "class Comment(AsyncBaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n user = relationship('User', backref='comments', lazy=\"selectin\")\nclass TestAsyncActiveRecord(unittest.IsolatedAsyncioTestCase):\n async def asyncSetUp(self):", + "detail": "sqlalchemy_mixins.tests.test_activerecordasync", + "documentation": {} + }, + { + "label": "TestAsyncActiveRecord", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", + "description": "sqlalchemy_mixins.tests.test_activerecordasync", + "peekOfCode": "class TestAsyncActiveRecord(unittest.IsolatedAsyncioTestCase):\n async def asyncSetUp(self):\n self.engine = create_async_engine('sqlite+aiosqlite:///:memory:', echo=False)\n self.async_session = sessionmaker(self.engine, class_=AsyncSession, expire_on_commit=False)\n async with self.engine.begin() as conn:\n await conn.run_sync(Base.metadata.drop_all)\n await conn.run_sync(Base.metadata.create_all)\n AsyncBaseModel.set_session(self.async_session)\n async def asyncTearDown(self):\n await self.engine.dispose()", + "detail": "sqlalchemy_mixins.tests.test_activerecordasync", + "documentation": {} + }, + { + "label": "Base", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", + "description": "sqlalchemy_mixins.tests.test_activerecordasync", + "peekOfCode": "Base = declarative_base()\nclass AsyncBaseModel(Base, ActiveRecordMixinAsync, SmartQueryMixin):\n __abstract__ = True\nclass User(AsyncBaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = relationship('Post', backref='user', lazy=\"selectin\")\n posts_viewonly = relationship('Post', viewonly=True)", + "detail": "sqlalchemy_mixins.tests.test_activerecordasync", + "documentation": {} + }, { "label": "Base", "kind": 6, @@ -2944,7 +3095,7 @@ "kind": 6, "importPath": "sqlalchemy_mixins.activerecordasync", "description": "sqlalchemy_mixins.activerecordasync", - "peekOfCode": "class ActiveRecordMixinAsync(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classproperty\n def query(cls):\n \"\"\"\n Override the default query property to handle async session.\n \"\"\"\n if not hasattr(cls.session, \"query\"):\n return select(cls)\n return cls.session.query(cls)", + "peekOfCode": "class ActiveRecordMixinAsync(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classmethod\n def _get_primary_key_name(cls) -> str:\n \"\"\"\n Gets the primary key of the model.\n Note: This method can only be used if the model has a single primary key.\n :return: The name of the primary key.\n :raises InvalidRequestError: If the model does not have a primary key or \n has a composite primary key.", "detail": "sqlalchemy_mixins.activerecordasync", "documentation": {} }, @@ -2971,7 +3122,7 @@ "kind": 5, "importPath": "sqlalchemy_mixins.activerecordasync", "description": "sqlalchemy_mixins.activerecordasync", - "peekOfCode": "SmaryQuery._get_root_cls = lambda query: async_root_cls(query)\nclass ActiveRecordMixinAsync(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classproperty\n def query(cls):\n \"\"\"\n Override the default query property to handle async session.\n \"\"\"\n if not hasattr(cls.session, \"query\"):\n return select(cls)", + "peekOfCode": "SmaryQuery._get_root_cls = lambda query: async_root_cls(query)\nclass ActiveRecordMixinAsync(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classmethod\n def _get_primary_key_name(cls) -> str:\n \"\"\"\n Gets the primary key of the model.\n Note: This method can only be used if the model has a single primary key.\n :return: The name of the primary key.\n :raises InvalidRequestError: If the model does not have a primary key or ", "detail": "sqlalchemy_mixins.activerecordasync", "documentation": {} }, diff --git a/requirements-dev.txt b/requirements-dev.txt index 35d2ad5..efeb72b 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,4 +4,5 @@ coverage codeclimate-test-reporter tox mypy==1.1.1 -sqlalchemy[mypy] >= 2.0 \ No newline at end of file +sqlalchemy[mypy] >= 2.0 +aiosqlite==0.20.0 \ No newline at end of file diff --git a/sqlalchemy_mixins/activerecordasync.py b/sqlalchemy_mixins/activerecordasync.py index b01ef28..fad5858 100644 --- a/sqlalchemy_mixins/activerecordasync.py +++ b/sqlalchemy_mixins/activerecordasync.py @@ -1,5 +1,6 @@ from sqlalchemy import select from sqlalchemy.orm import Query +from sqlalchemy.exc import InvalidRequestError from .utils import classproperty from .session import SessionMixin from .inspection import InspectionMixin @@ -22,6 +23,39 @@ def async_root_cls(query: Query): class ActiveRecordMixinAsync(InspectionMixin, SessionMixin): __abstract__ = True + + @classmethod + def _get_primary_key_name(cls) -> str: + """ + Gets the primary key of the model. + + Note: This method can only be used if the model has a single primary key. + :return: The name of the primary key. + :raises InvalidRequestError: If the model does not have a primary key or + has a composite primary key. + """ + primary_keys = cls.__table__.primary_key.columns + if primary_keys is None: + raise InvalidRequestError( + f"Model {cls.__name__} does not have a primary key.") + if len(primary_keys) > 1: + raise InvalidRequestError( + f"Model {cls.__name__} has a composite primary key.") + + return primary_keys[0].name + + @classproperty + def settable_attributes(cls): + return cls.columns + cls.hybrid_properties + cls.settable_relations + + def fill(self, **kwargs): + for name in kwargs.keys(): + if name in self.settable_attributes: + setattr(self, name, kwargs[name]) + else: + raise KeyError("Attribute '{}' doesn't exist".format(name)) + + return self @classproperty def query(cls): @@ -105,7 +139,7 @@ async def destroy_async(cls, *ids): async def select_async(cls, stmt=None, filters=None, sort_attrs=None, schema=None): async with cls.session() as session: if stmt is None: - stmt = cls.smart_query( + stmt = SmaryQuery.smart_query(query=cls.query, filters=filters, sort_attrs=sort_attrs, schema=schema) return (await session.execute(stmt)).scalars() diff --git a/sqlalchemy_mixins/tests/test_activerecordasync.py b/sqlalchemy_mixins/tests/test_activerecordasync.py new file mode 100644 index 0000000..93a22e4 --- /dev/null +++ b/sqlalchemy_mixins/tests/test_activerecordasync.py @@ -0,0 +1,210 @@ +import unittest +import asyncio +import sqlalchemy as sa +from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession +from sqlalchemy.orm import sessionmaker +from sqlalchemy.orm import selectinload +from sqlalchemy.orm import relationship +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.ext.hybrid import hybrid_property + +from sqlalchemy_mixins.activerecord import ModelNotFoundError +from sqlalchemy_mixins import ActiveRecordMixinAsync, SmartQueryMixin + + +Base = declarative_base() + +class AsyncBaseModel(Base, ActiveRecordMixinAsync, SmartQueryMixin): + __abstract__ = True + +class User(AsyncBaseModel): + __tablename__ = 'user' + __repr_attrs__ = ['name'] + id = sa.Column(sa.Integer, primary_key=True) + name = sa.Column(sa.String) + posts = relationship('Post', backref='user', lazy="selectin") + posts_viewonly = relationship('Post', viewonly=True) + + +class Post(AsyncBaseModel): + __tablename__ = 'post' + id = sa.Column(sa.Integer, primary_key=True) + body = sa.Column(sa.String) + user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id')) + archived = sa.Column(sa.Boolean, default=False) + comments = relationship('Comment', backref='post', lazy="selectin") + + @hybrid_property + def public(self): + return not self.archived + + @public.setter + def public(self, public): + self.archived = not public + +class Comment(AsyncBaseModel): + __tablename__ = 'comment' + __repr_attrs__ = ['body'] + id = sa.Column(sa.Integer, primary_key=True) + body = sa.Column(sa.String) + user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id')) + post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id')) + user = relationship('User', backref='comments', lazy="selectin") + + +class TestAsyncActiveRecord(unittest.IsolatedAsyncioTestCase): + async def asyncSetUp(self): + self.engine = create_async_engine('sqlite+aiosqlite:///:memory:', echo=False) + self.async_session = sessionmaker(self.engine, class_=AsyncSession, expire_on_commit=False) + + async with self.engine.begin() as conn: + await conn.run_sync(Base.metadata.drop_all) + await conn.run_sync(Base.metadata.create_all) + + AsyncBaseModel.set_session(self.async_session) + + async def asyncTearDown(self): + await self.engine.dispose() + + async def test_settable_attributes(self): + self.assertEqual(set(User.settable_attributes), + {'id', 'name', 'posts', 'comments'}) + self.assertNotIn('posts_viewonly', set(User.settable_attributes)) + + self.assertEqual(set(Post.settable_attributes), + {'id', 'body', 'user_id', 'archived', + 'user', 'comments', 'public'}) + + self.assertEqual(set(Comment.settable_attributes), + {'id', 'body', 'post_id', 'user_id', + 'user', 'post'}) + + async def test_create_and_save_async(self): + u1 = User(name='Bill u1') + await u1.save_async() + + async with self.async_session() as session: + result = await session.execute(sa.select(User)) + saved = result.scalars().first() + self.assertEqual(u1.id, saved.id) + + p11 = Post(body='p11', user=u1, public=False) + await p11.save_async() + + async with self.async_session() as session: + result = await session.execute(sa.select(Post)) + saved_post = result.scalars().first() + self.assertEqual(p11.body, saved_post.body) + self.assertEqual(saved_post.archived, True) + + async def test_create_async(self): + u1 = await User.create_async(name='Bill u1') + + async with self.async_session() as session: + result = await session.execute(sa.select(User)) + saved = result.scalars().first() + self.assertEqual(u1.id, saved.id) + + p11 = await Post.create_async(body='p11', user=u1, public=False) + + async with self.async_session() as session: + result = await session.execute(sa.select(Post)) + saved_post = result.scalars().first() + self.assertEqual(p11.id, saved_post.id) + self.assertEqual(saved_post.archived, True) + + async def test_update_async(self): + u1 = await User.create_async(name='Bill', id=1) + u2 = await User.create_async(name='Bishop', id=2) + p11 = await Post.create_async(body='p11', user=u1, public=False, id=11) + + async with self.async_session() as session: + result = await session.execute( + sa.select(Post).options(selectinload(Post.user)) + .filter_by(id=11) + ) + post = result.scalars().first() + self.assertEqual(post.body, 'p11') + self.assertEqual(post.public, False) + self.assertEqual(post.user.id, u1.id) + + await p11.update_async(body='new body', public=True, user=u2) + + async with self.async_session() as session: + result = await session.execute( + sa.select(Post).options(selectinload(Post.user)) + .filter_by(id=11) + ) + updated_post = result.scalars().first() + self.assertEqual(updated_post.body, 'new body') + self.assertEqual(updated_post.public, True) + self.assertEqual(updated_post.user.id, u2.id) + + async def test_delete_async(self): + u1 = await User.create_async(name='Bill', id=1) + + async with self.async_session() as session: + result = await session.execute(sa.select(User).filter_by(id=1)) + saved = result.scalars().first() + self.assertEqual(saved.id, u1.id) + + await u1.delete_async() + + async with self.async_session() as session: + result = await session.execute(sa.select(User).filter_by(id=1)) + self.assertEqual(result.scalars().first(), None) + + async def test_destroy_async(self): + u1 = await User.create_async(name='Bill', id=1) + p11 = await Post.create_async(body='p11', user=u1, id=11) + p12 = await Post.create_async(body='p12', user=u1, id=12) + p13 = await Post.create_async(body='p13', user=u1, id=13) + + async with self.async_session() as session: + result = await session.execute(sa.select(Post)) + self.assertEqual(set([u.id for u in result.scalars().all()]), {p11.id, p12.id, p13.id}) + + await Post.destroy_async(11, 12) + + async with self.async_session() as session: + result = await session.execute(sa.select(Post)) + got = result.scalars().all() + self.assertEqual(len(got), 1) + self.assertEqual(got[0].id, p13.id) + + async def test_all_async(self): + u1 = await User.create_async(name='Bill', id=1) + u2 = await User.create_async(name='Bishop', id=2) + + users = await User.all_async() + self.assertEqual(set([u.id for u in users]), {u1.id, u2.id}) + + async def test_first_async(self): + u1 = await User.create_async(name='Bill', id=1) + u2 = await User.create_async(name='Bishop', id=2) + + first_user = await User.first_async() + self.assertEqual(first_user.id, u1.id) + + async def test_find_async(self): + u1 = await User.create_async(name='Bill', id=1) + u2 = await User.create_async(name='Bishop', id=2) + + found_user = await User.find_async(1) + self.assertEqual(found_user.id, u1.id) + + not_found_user = await User.find_async(3) + self.assertEqual(not_found_user, None) + + async def test_find_or_fail_async(self): + u1 = await User.create_async(name='Bill', id=1) + u2 = await User.create_async(name='Bishop', id=2) + + found_user = await User.find_or_fail_async(1) + self.assertEqual(found_user.id, u1.id) + + with self.assertRaises(ModelNotFoundError): + await User.find_or_fail_async(3) + +if __name__ == '__main__': + asyncio.run(unittest.main()) \ No newline at end of file From 2a0e2de2021d7ea3bc471642e00493c25e2f3cd4 Mon Sep 17 00:00:00 2001 From: Aurthur Musendame Date: Sun, 1 Sep 2024 17:46:35 +0200 Subject: [PATCH 3/6] remove vscode --- .vscode/PythonImportHelper-v2-Completion.json | 3300 ----------------- 1 file changed, 3300 deletions(-) delete mode 100644 .vscode/PythonImportHelper-v2-Completion.json diff --git a/.vscode/PythonImportHelper-v2-Completion.json b/.vscode/PythonImportHelper-v2-Completion.json deleted file mode 100644 index 1344ccc..0000000 --- a/.vscode/PythonImportHelper-v2-Completion.json +++ /dev/null @@ -1,3300 +0,0 @@ -[ - { - "label": "print_function", - "importPath": "__future__", - "description": "__future__", - "isExtraImport": true, - "detail": "__future__", - "documentation": {} - }, - { - "label": "print_function", - "importPath": "__future__", - "description": "__future__", - "isExtraImport": true, - "detail": "__future__", - "documentation": {} - }, - { - "label": "print_function", - "importPath": "__future__", - "description": "__future__", - "isExtraImport": true, - "detail": "__future__", - "documentation": {} - }, - { - "label": "print_function", - "importPath": "__future__", - "description": "__future__", - "isExtraImport": true, - "detail": "__future__", - "documentation": {} - }, - { - "label": "print_function", - "importPath": "__future__", - "description": "__future__", - "isExtraImport": true, - "detail": "__future__", - "documentation": {} - }, - { - "label": "print_function", - "importPath": "__future__", - "description": "__future__", - "isExtraImport": true, - "detail": "__future__", - "documentation": {} - }, - { - "label": "print_function", - "importPath": "__future__", - "description": "__future__", - "isExtraImport": true, - "detail": "__future__", - "documentation": {} - }, - { - "label": "print_function", - "importPath": "__future__", - "description": "__future__", - "isExtraImport": true, - "detail": "__future__", - "documentation": {} - }, - { - "label": "os", - "kind": 6, - "isExtraImport": true, - "importPath": "os", - "description": "os", - "detail": "os", - "documentation": {} - }, - { - "label": "sqlalchemy", - "kind": 6, - "isExtraImport": true, - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "event", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "event", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "select", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "inspect", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "inspect", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "asc", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "desc", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "inspect", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "hybrid_property", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_method", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_property", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_property", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_property", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_property", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_method", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_property", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_property", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_method", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_property", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_method", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "scoped_session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "sessionmaker", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "scoped_session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "sessionmaker", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Query", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "scoped_session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "sessionmaker", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "scoped_session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "sessionmaker", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "scoped_session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "sessionmaker", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Query", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "scoped_session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "sessionmaker", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "scoped_session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "sessionmaker", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Query", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "declarative_base", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "sessionmaker", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "selectinload", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "relationship", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Query", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "sessionmaker", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Query", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Query", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "joinedload", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Load", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "subqueryload", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "RelationshipProperty", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "scoped_session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Query", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "aliased", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "contains_eager", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "RelationshipProperty", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Mapper", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "ActiveRecordMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "ReprMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "ModelNotFoundError", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "AllFeaturesMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "TimestampsMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "EagerLoadMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "ReprMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "ReprMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "SerializeMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "SmartQueryMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "ReprMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "JOINED", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "smart_query", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "TimestampsMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "ActiveRecordMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "ActiveRecordMixinAsync", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "SmartQueryMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "EagerLoadMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "InspectionMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "ReprMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "SerializeMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "SmartQueryMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "smart_query", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "TimestampsMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "JOINED", - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "SUBQUERY", - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "eager_expr", - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "JOINED", - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "SUBQUERY", - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "eager_expr", - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "JOINED", - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "SUBQUERY", - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "datetime", - "kind": 6, - "isExtraImport": true, - "importPath": "datetime", - "description": "datetime", - "detail": "datetime", - "documentation": {} - }, - { - "label": "datetime", - "importPath": "datetime", - "description": "datetime", - "isExtraImport": true, - "detail": "datetime", - "documentation": {} - }, - { - "label": "datetime", - "importPath": "datetime", - "description": "datetime", - "isExtraImport": true, - "detail": "datetime", - "documentation": {} - }, - { - "label": "time", - "kind": 6, - "isExtraImport": true, - "importPath": "time", - "description": "time", - "detail": "time", - "documentation": {} - }, - { - "label": "unittest", - "kind": 6, - "isExtraImport": true, - "importPath": "unittest", - "description": "unittest", - "detail": "unittest", - "documentation": {} - }, - { - "label": "ModelNotFoundError", - "importPath": "sqlalchemy_mixins.activerecord", - "description": "sqlalchemy_mixins.activerecord", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.activerecord", - "documentation": {} - }, - { - "label": "ModelNotFoundError", - "importPath": "sqlalchemy_mixins.activerecord", - "description": "sqlalchemy_mixins.activerecord", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.activerecord", - "documentation": {} - }, - { - "label": "asyncio", - "kind": 6, - "isExtraImport": true, - "importPath": "asyncio", - "description": "asyncio", - "detail": "asyncio", - "documentation": {} - }, - { - "label": "create_async_engine", - "importPath": "sqlalchemy.ext.asyncio", - "description": "sqlalchemy.ext.asyncio", - "isExtraImport": true, - "detail": "sqlalchemy.ext.asyncio", - "documentation": {} - }, - { - "label": "AsyncSession", - "importPath": "sqlalchemy.ext.asyncio", - "description": "sqlalchemy.ext.asyncio", - "isExtraImport": true, - "detail": "sqlalchemy.ext.asyncio", - "documentation": {} - }, - { - "label": "declarative_base", - "importPath": "sqlalchemy.ext.declarative", - "description": "sqlalchemy.ext.declarative", - "isExtraImport": true, - "detail": "sqlalchemy.ext.declarative", - "documentation": {} - }, - { - "label": "SessionMixin", - "importPath": "sqlalchemy_mixins.session", - "description": "sqlalchemy_mixins.session", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.session", - "documentation": {} - }, - { - "label": "NoSessionError", - "importPath": "sqlalchemy_mixins.session", - "description": "sqlalchemy_mixins.session", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.session", - "documentation": {} - }, - { - "label": "InvalidRequestError", - "importPath": "sqlalchemy.exc", - "description": "sqlalchemy.exc", - "isExtraImport": true, - "detail": "sqlalchemy.exc", - "documentation": {} - }, - { - "label": "_AbstractLoad", - "importPath": "sqlalchemy.orm.strategy_options", - "description": "sqlalchemy.orm.strategy_options", - "isExtraImport": true, - "detail": "sqlalchemy.orm.strategy_options", - "documentation": {} - }, - { - "label": "string_types", - "importPath": "six", - "description": "six", - "isExtraImport": true, - "detail": "six", - "documentation": {} - }, - { - "label": "Iterable", - "importPath": "collections.abc", - "description": "collections.abc", - "isExtraImport": true, - "detail": "collections.abc", - "documentation": {} - }, - { - "label": "abc", - "importPath": "collections", - "description": "collections", - "isExtraImport": true, - "detail": "collections", - "documentation": {} - }, - { - "label": "OrderedDict", - "importPath": "collections", - "description": "collections", - "isExtraImport": true, - "detail": "collections", - "documentation": {} - }, - { - "label": "AliasedClass", - "importPath": "sqlalchemy.orm.util", - "description": "sqlalchemy.orm.util", - "isExtraImport": true, - "detail": "sqlalchemy.orm.util", - "documentation": {} - }, - { - "label": "operators", - "importPath": "sqlalchemy.sql", - "description": "sqlalchemy.sql", - "isExtraImport": true, - "detail": "sqlalchemy.sql", - "documentation": {} - }, - { - "label": "extract", - "importPath": "sqlalchemy.sql", - "description": "sqlalchemy.sql", - "isExtraImport": true, - "detail": "sqlalchemy.sql", - "documentation": {} - }, - { - "label": "setup", - "importPath": "setuptools", - "description": "setuptools", - "isExtraImport": true, - "detail": "setuptools", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, ActiveRecordMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "class BaseModel(Base, ActiveRecordMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n age = sa.Column(sa.Integer)", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n age = sa.Column(sa.Integer)\n posts = sa.orm.relationship('Post', backref='user')\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n # user = backref from User.post\n @hybrid_property\n def public(self):\n return not self.archived", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "log", - "kind": 2, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "def log(msg):\n print('\\n{}\\n'.format(msg))\n#################### setup ######################\nclass Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, ActiveRecordMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "db_file", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "db_file = os.path.join(os.path.dirname(__file__), 'test.sqlite')\nengine = create_engine('sqlite:///{}'.format(db_file), echo=True)\n# autocommit=True - it's to make you see data in 3rd party DB view tool\nsession = scoped_session(sessionmaker(bind=engine))\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\n# setup base model: inject session so it can be accessed from model\nBaseModel.set_session(session)\n#################### CRUD demo ######################\n# ['id', 'body', 'user_id', 'archived', # normal columns", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "engine = create_engine('sqlite:///{}'.format(db_file), echo=True)\n# autocommit=True - it's to make you see data in 3rd party DB view tool\nsession = scoped_session(sessionmaker(bind=engine))\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\n# setup base model: inject session so it can be accessed from model\nBaseModel.set_session(session)\n#################### CRUD demo ######################\n# ['id', 'body', 'user_id', 'archived', # normal columns\n# 'user', 'comments', # relations", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "session", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\n# setup base model: inject session so it can be accessed from model\nBaseModel.set_session(session)\n#################### CRUD demo ######################\n# ['id', 'body', 'user_id', 'archived', # normal columns\n# 'user', 'comments', # relations\n# 'public'] # hybrid attributes\nprint(Post.settable_attributes)", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "user1", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "user1 = User()\n# equal to\n# user1.name = 'Billy'\n# user1.age = 1\n# session.flush()\nuser1.fill(name='Billy', age=1)\n# you can use kwargs as above or, in real-world apps, unpack dict as below\ndata = {'name': 'Bill', 'age': 21}\nuser1.fill(**data)\n# equal to", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "data", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "data = {'name': 'Bill', 'age': 21}\nuser1.fill(**data)\n# equal to\n# session.add(user1)\n# session.flush()\nuser1.save()\n#### 2. ActiveRecordMixin.create(): ####\n# equal to\n# user2 = User(name='Bob')\n# session.add(user2)", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "user2", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "user2 = User.create(name='Bob')\npost1 = Post.create(body='post1', user=user2)\n#### 3. ActiveRecordMixin.update(): ####\n# equal to\n# post1.fill(...)\n# post1.save()\npost1.update(body='new body', public=True, user=user1)\n#### 4. ActiveRecordMixin.delete(): ####\n# equal to\n# session.delete(post_to_be_deleted)", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "post1", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "post1 = Post.create(body='post1', user=user2)\n#### 3. ActiveRecordMixin.update(): ####\n# equal to\n# post1.fill(...)\n# post1.save()\npost1.update(body='new body', public=True, user=user1)\n#### 4. ActiveRecordMixin.delete(): ####\n# equal to\n# session.delete(post_to_be_deleted)\n# session.flush()", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "post_to_be_deleted", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "post_to_be_deleted = Post.create()\npost_to_be_deleted.delete()\n#### 5. ActiveRecordMixin.destroy() ####\n# equal to\n# session.delete(session.query(User).get(91))\n# session.delete(session.query(User).get(92))\n# session.flush()\n_ = User.create(id=91)\n__ = User.create(id=92)\nUser.destroy(91, 92)", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "_", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "_ = User.create(id=91)\n__ = User.create(id=92)\nUser.destroy(91, 92)\n#################### Query demo ######################\n#### 1. ActiveRecordMixin.all() ####\n# equal to\n# session.query(User).all()\nlog('all users: ' + str(User.all()))\n#### 2. ActiveRecordMixin.first() ####\n# equal to", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "__", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "__ = User.create(id=92)\nUser.destroy(91, 92)\n#################### Query demo ######################\n#### 1. ActiveRecordMixin.all() ####\n# equal to\n# session.query(User).all()\nlog('all users: ' + str(User.all()))\n#### 2. ActiveRecordMixin.first() ####\n# equal to\n# session.query(User).first()", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "user3", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "user3 = User.create(name='Bishop', id=3)\nlog('user with id=3: ' + str(User.find(3)))\n#### 4. ActiveRecordMixin.find_or_fail() ####\n# closest code on raw sqlalchemy will be\n# session.query(User).filter_by(id=).one()\n# but one() method throws common error without describing which ID was not\n# found, which is inconvenient: http://www.qopy.me/c5Csw1vWTCuOMKuP07J7iA\ntry:\n print(User.find_or_fail(123987))\nexcept ModelNotFoundError as e:", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "examples.all_features", - "description": "examples.all_features", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nclass BaseModel(Base, AllFeaturesMixin, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", - "detail": "examples.all_features", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "examples.all_features", - "description": "examples.all_features", - "peekOfCode": "class BaseModel(Base, AllFeaturesMixin, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'", - "detail": "examples.all_features", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "examples.all_features", - "description": "examples.all_features", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)", - "detail": "examples.all_features", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "examples.all_features", - "description": "examples.all_features", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n rating = sa.Column(sa.Integer)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n # we use this relation in smart_query, so it should be explicitly set\n # (not just a backref from User class)\n user = sa.orm.relationship('User', backref='posts') # but for eagerload", - "detail": "examples.all_features", - "documentation": {} - }, - { - "label": "Comment", - "kind": 6, - "importPath": "examples.all_features", - "description": "examples.all_features", - "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post = sa.orm.relationship('Post')\n user = sa.orm.relationship('User')\nengine = sa.create_engine('sqlite:///:memory:', echo=False)\nsession = scoped_session(sessionmaker(bind=engine))", - "detail": "examples.all_features", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "examples.all_features", - "description": "examples.all_features", - "peekOfCode": "engine = sa.create_engine('sqlite:///:memory:', echo=False)\nsession = scoped_session(sessionmaker(bind=engine))\nBase.metadata.create_all(engine)\nBaseModel.set_session(session)\nbob = User.create(name='Bob')\npost1 = Post.create(body='Post 1', user=bob, rating=3)\npost2 = Post.create(body='long-long-long-long-long body', rating=2,\n user=User.create(name='Bill'),\n comments=[Comment.create(body='cool!', user=bob)])\n# filter using operators like 'in' and 'contains' and relations like 'user'", - "detail": "examples.all_features", - "documentation": {} - }, - { - "label": "session", - "kind": 5, - "importPath": "examples.all_features", - "description": "examples.all_features", - "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nBase.metadata.create_all(engine)\nBaseModel.set_session(session)\nbob = User.create(name='Bob')\npost1 = Post.create(body='Post 1', user=bob, rating=3)\npost2 = Post.create(body='long-long-long-long-long body', rating=2,\n user=User.create(name='Bill'),\n comments=[Comment.create(body='cool!', user=bob)])\n# filter using operators like 'in' and 'contains' and relations like 'user'\n# will output this beauty: ", - "detail": "examples.all_features", - "documentation": {} - }, - { - "label": "bob", - "kind": 5, - "importPath": "examples.all_features", - "description": "examples.all_features", - "peekOfCode": "bob = User.create(name='Bob')\npost1 = Post.create(body='Post 1', user=bob, rating=3)\npost2 = Post.create(body='long-long-long-long-long body', rating=2,\n user=User.create(name='Bill'),\n comments=[Comment.create(body='cool!', user=bob)])\n# filter using operators like 'in' and 'contains' and relations like 'user'\n# will output this beauty: \nprint(Post.where(rating__in=[2, 3, 4], user___name__like='%Bi%').all())\n# joinedload post and user\nprint(Comment.with_joined(Comment.user, Comment.post).first())", - "detail": "examples.all_features", - "documentation": {} - }, - { - "label": "post1", - "kind": 5, - "importPath": "examples.all_features", - "description": "examples.all_features", - "peekOfCode": "post1 = Post.create(body='Post 1', user=bob, rating=3)\npost2 = Post.create(body='long-long-long-long-long body', rating=2,\n user=User.create(name='Bill'),\n comments=[Comment.create(body='cool!', user=bob)])\n# filter using operators like 'in' and 'contains' and relations like 'user'\n# will output this beauty: \nprint(Post.where(rating__in=[2, 3, 4], user___name__like='%Bi%').all())\n# joinedload post and user\nprint(Comment.with_joined(Comment.user, Comment.post).first())\n# subqueryload posts", - "detail": "examples.all_features", - "documentation": {} - }, - { - "label": "post2", - "kind": 5, - "importPath": "examples.all_features", - "description": "examples.all_features", - "peekOfCode": "post2 = Post.create(body='long-long-long-long-long body', rating=2,\n user=User.create(name='Bill'),\n comments=[Comment.create(body='cool!', user=bob)])\n# filter using operators like 'in' and 'contains' and relations like 'user'\n# will output this beauty: \nprint(Post.where(rating__in=[2, 3, 4], user___name__like='%Bi%').all())\n# joinedload post and user\nprint(Comment.with_joined(Comment.user, Comment.post).first())\n# subqueryload posts\nprint(User.with_subquery(User.posts).first())", - "detail": "examples.all_features", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, EagerLoadMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "class BaseModel(Base, EagerLoadMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\n comments = sa.orm.relationship('Comment')\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')\nclass Comment(BaseModel):\n __tablename__ = 'comment'", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "Comment", - "kind": 6, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body', 'post'] # we want to display body and post\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n user = sa.orm.relationship('User')\n post = sa.orm.relationship('Post')", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "log", - "kind": 2, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "def log(msg):\n print('\\n{}\\n'.format(msg))\n#################### setup ######################\nclass Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, EagerLoadMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "reset_session", - "kind": 2, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "def reset_session():\n session = scoped_session(sessionmaker(bind=engine))\n BaseModel.set_session(session)\n return session\n#################### setup some data ######################\nsession = reset_session()\nu1 = User(name='Bill u1', id=1)\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "db_file", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "db_file = os.path.join(os.path.dirname(__file__), 'test.sqlite')\nengine = create_engine('sqlite:///{}'.format(db_file), echo=True)\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\n# sqlalchemy caches data in session, so to not use cache, we recreate session\ndef reset_session():\n session = scoped_session(sessionmaker(bind=engine))\n BaseModel.set_session(session)\n return session\n#################### setup some data ######################", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "engine = create_engine('sqlite:///{}'.format(db_file), echo=True)\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\n# sqlalchemy caches data in session, so to not use cache, we recreate session\ndef reset_session():\n session = scoped_session(sessionmaker(bind=engine))\n BaseModel.set_session(session)\n return session\n#################### setup some data ######################\nsession = reset_session()", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "session", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "session = reset_session()\nu1 = User(name='Bill u1', id=1)\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nsession.commit()\np11 = Post(\n id=11,", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "u1", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "u1 = User(name='Bill u1', id=1)\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nsession.commit()\np11 = Post(\n id=11,\n body='1234567890123',", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "u2", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "u2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nsession.commit()\np11 = Post(\n id=11,\n body='1234567890123',\n archived=True\n)\np11.user = u1", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "p11", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "p11 = Post(\n id=11,\n body='1234567890123',\n archived=True\n)\np11.user = u1\nsession.add(p11)\nsession.commit()\np12 = Post(\n id=12,", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "p11.user", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "p11.user = u1\nsession.add(p11)\nsession.commit()\np12 = Post(\n id=12,\n body='1234567890',\n user=u1\n)\nsession.add(p12)\nsession.commit()", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "p12", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "p12 = Post(\n id=12,\n body='1234567890',\n user=u1\n)\nsession.add(p12)\nsession.commit()\ncm11 = Comment(\n id=11,\n body='cm11 to p11',", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "cm11", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "cm11 = Comment(\n id=11,\n body='cm11 to p11',\n user=u1,\n post=p11,\n rating=1\n)\nsession.add(cm11)\nsession.commit()\ncm12 = Comment(", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "cm12", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "cm12 = Comment(\n id=12,\n body='cm12 to p12',\n user=u2,\n post=p12,\n rating=2\n)\nsession.add(cm12)\nsession.commit()\n#################### Demo ######################", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "comment", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "comment = Comment.with_joined(Comment.user, Comment.post).first()\n# SQL will be like\n\"\"\"\nSELECT comment.*, user_1.*, post_1.*\nFROM comment\nLEFT OUTER JOIN user AS user_1 ON user_1.id = comment.user_id\nLEFT OUTER JOIN post AS post_1 ON post_1.id = comment.post_id\nLEFT OUTER JOIN comment AS comment_1 ON post_1.id = comment_1.post_id\nLIMIT 1 OFFSET 1\n\"\"\"", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "user", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "user = comment.user\npost = comment.post\ncomments = post.comments\nlog('NO ADDITIONAL SQL. END')\n#### 0.2 subqueryload ####\nreset_session()\nusers = User.with_subquery(User.posts).all()\n# there will be 3 queries:\n## first. on users:\n\"\"\"", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "post", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "post = comment.post\ncomments = post.comments\nlog('NO ADDITIONAL SQL. END')\n#### 0.2 subqueryload ####\nreset_session()\nusers = User.with_subquery(User.posts).all()\n# there will be 3 queries:\n## first. on users:\n\"\"\"\nSELECT user.* FROM user", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "comments", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "comments = post.comments\nlog('NO ADDITIONAL SQL. END')\n#### 0.2 subqueryload ####\nreset_session()\nusers = User.with_subquery(User.posts).all()\n# there will be 3 queries:\n## first. on users:\n\"\"\"\nSELECT user.* FROM user\n\"\"\"", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "users", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "users = User.with_subquery(User.posts).all()\n# there will be 3 queries:\n## first. on users:\n\"\"\"\nSELECT user.* FROM user\n\"\"\"\n# second. on posts:\n\"\"\"\nSELECT post.* FROM (SELECT user.id AS user_id FROM user) AS anon_1\nJOIN post ON anon_1.user_id = post.user_id", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "posts", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "posts = users[0].posts\ncomments = posts[0].comments\nlog('NO ADDITIONAL SQL. END')\n#### 1. nested joinedload ####\n# for nested eagerload, you should use dict instead of lists|\n# also make sure you use class properties\nschema = {\n User.posts: {\n Post.comments: {\n Comment.user: JOINED", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "comments", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "comments = posts[0].comments\nlog('NO ADDITIONAL SQL. END')\n#### 1. nested joinedload ####\n# for nested eagerload, you should use dict instead of lists|\n# also make sure you use class properties\nschema = {\n User.posts: {\n Post.comments: {\n Comment.user: JOINED\n }", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "schema", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "schema = {\n User.posts: {\n Post.comments: {\n Comment.user: JOINED\n }\n }\n}\nsession = reset_session()\n###### 1.1 query-level: more flexible\nuser = session.query(User).options(*eager_expr(schema)).get(1)", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "session", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "session = reset_session()\n###### 1.1 query-level: more flexible\nuser = session.query(User).options(*eager_expr(schema)).get(1)\n# SQL will be like\n# note that we select user as parent entity and as post.comments.user\n# EagerLoadMixin will make table aliases for us\n\"\"\"\nSELECT user.*, user_1.*, comment_1.*, post_1.*\nFROM user\nLEFT OUTER JOIN post AS post_1 ON user.id = post_1.user_id", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "user", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "user = session.query(User).options(*eager_expr(schema)).get(1)\n# SQL will be like\n# note that we select user as parent entity and as post.comments.user\n# EagerLoadMixin will make table aliases for us\n\"\"\"\nSELECT user.*, user_1.*, comment_1.*, post_1.*\nFROM user\nLEFT OUTER JOIN post AS post_1 ON user.id = post_1.user_id\nLEFT OUTER JOIN comment AS comment_1 ON post_1.id = comment_1.post_id\nLEFT OUTER JOIN user AS user_1 ON user_1.id = comment_1.user_id", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "user", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "user = User.with_(schema).get(1)\n# now, to get relationships, NO additional query is needed\nlog('NO ADDITIONAL SQL. BEGIN')\npost = user.posts[0]\ncomment = post.comments[0]\ncomment_user = comment.user\nlog('NO ADDITIONAL SQL. END')\n#### 2. combination of joinedload and subqueryload ####\n# sometimes we want to load relations in separate query.\n# i.g. when we load posts, to each post we want to have user and all comments.", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "post", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "post = user.posts[0]\ncomment = post.comments[0]\ncomment_user = comment.user\nlog('NO ADDITIONAL SQL. END')\n#### 2. combination of joinedload and subqueryload ####\n# sometimes we want to load relations in separate query.\n# i.g. when we load posts, to each post we want to have user and all comments.\n# when we load many posts, join comments and comments to each user\nschema = {\n Post.comments: (SUBQUERY, { # load comments in separate query", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "comment", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "comment = post.comments[0]\ncomment_user = comment.user\nlog('NO ADDITIONAL SQL. END')\n#### 2. combination of joinedload and subqueryload ####\n# sometimes we want to load relations in separate query.\n# i.g. when we load posts, to each post we want to have user and all comments.\n# when we load many posts, join comments and comments to each user\nschema = {\n Post.comments: (SUBQUERY, { # load comments in separate query\n Comment.user: JOINED # but, in this separate query, join comments", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "comment_user", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "comment_user = comment.user\nlog('NO ADDITIONAL SQL. END')\n#### 2. combination of joinedload and subqueryload ####\n# sometimes we want to load relations in separate query.\n# i.g. when we load posts, to each post we want to have user and all comments.\n# when we load many posts, join comments and comments to each user\nschema = {\n Post.comments: (SUBQUERY, { # load comments in separate query\n Comment.user: JOINED # but, in this separate query, join comments\n })", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "schema", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "schema = {\n Post.comments: (SUBQUERY, { # load comments in separate query\n Comment.user: JOINED # but, in this separate query, join comments\n })\n}\n###### 2.1 query-level: more flexible\nreset_session()\nposts = session.query(Post).options(*eager_expr(schema)).all()\n###### 2.2 ORM-level: more convenient\nreset_session()", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "posts", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "posts = session.query(Post).options(*eager_expr(schema)).all()\n###### 2.2 ORM-level: more convenient\nreset_session()\nposts = Post.with_(schema).all()\n# there will be 2 queries:\n## first:\n\"\"\"\nSELECT post.* FROM post\n\"\"\"\n# second query loads comments with joined comment users", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "posts", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "posts = Post.with_(schema).all()\n# there will be 2 queries:\n## first:\n\"\"\"\nSELECT post.* FROM post\n\"\"\"\n# second query loads comments with joined comment users\n# it uses first query to get comments for specific posts\n\"\"\"\nSELECT comment.*, user_1.*", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "comments1", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "comments1 = posts[0].comments\ncomments2 = posts[1].comments\nuser1 = posts[0].comments[0].user\nuser2 = posts[1].comments[0].user\nlog('NO ADDITIONAL SQL. END')", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "comments2", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "comments2 = posts[1].comments\nuser1 = posts[0].comments[0].user\nuser2 = posts[1].comments[0].user\nlog('NO ADDITIONAL SQL. END')", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "user1", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "user1 = posts[0].comments[0].user\nuser2 = posts[1].comments[0].user\nlog('NO ADDITIONAL SQL. END')", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "user2", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "user2 = posts[1].comments[0].user\nlog('NO ADDITIONAL SQL. END')", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "examples.repr", - "description": "examples.repr", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = sa.create_engine('sqlite:///:memory:')\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'", - "detail": "examples.repr", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "examples.repr", - "description": "examples.repr", - "peekOfCode": "class BaseModel(Base, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')", - "detail": "examples.repr", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "examples.repr", - "description": "examples.repr", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\nclass Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n __repr_max_length__ = 25", - "detail": "examples.repr", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "examples.repr", - "description": "examples.repr", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n __repr_max_length__ = 25\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\nBase.metadata.create_all(engine)\nbob = User(name='Bob')\nsession.add(bob)", - "detail": "examples.repr", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "examples.repr", - "description": "examples.repr", - "peekOfCode": "engine = sa.create_engine('sqlite:///:memory:')\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "examples.repr", - "documentation": {} - }, - { - "label": "session", - "kind": 5, - "importPath": "examples.repr", - "description": "examples.repr", - "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", - "detail": "examples.repr", - "documentation": {} - }, - { - "label": "bob", - "kind": 5, - "importPath": "examples.repr", - "description": "examples.repr", - "peekOfCode": "bob = User(name='Bob')\nsession.add(bob)\nsession.flush()\npost1 = Post(body='Post 1', user=bob)\nsession.add(post1)\nsession.flush()\npost2 = Post(body='Post 2 long-long body', user=bob)\nsession.add(post2)\nsession.flush()\n# ", - "detail": "examples.repr", - "documentation": {} - }, - { - "label": "post1", - "kind": 5, - "importPath": "examples.repr", - "description": "examples.repr", - "peekOfCode": "post1 = Post(body='Post 1', user=bob)\nsession.add(post1)\nsession.flush()\npost2 = Post(body='Post 2 long-long body', user=bob)\nsession.add(post2)\nsession.flush()\n# \nprint(bob)\n# \nprint(post1)", - "detail": "examples.repr", - "documentation": {} - }, - { - "label": "post2", - "kind": 5, - "importPath": "examples.repr", - "description": "examples.repr", - "peekOfCode": "post2 = Post(body='Post 2 long-long body', user=bob)\nsession.add(post2)\nsession.flush()\n# \nprint(bob)\n# \nprint(post1)\n# \nprint(post2)", - "detail": "examples.repr", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "examples.serialize", - "description": "examples.serialize", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = sa.create_engine('sqlite:///:memory:')\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "examples.serialize", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "examples.serialize", - "description": "examples.serialize", - "peekOfCode": "class BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n password = sa.Column(sa.String)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\nclass Post(BaseModel):", - "detail": "examples.serialize", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "examples.serialize", - "description": "examples.serialize", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n password = sa.Column(sa.String)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)", - "detail": "examples.serialize", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "examples.serialize", - "description": "examples.serialize", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\nBase.metadata.create_all(engine)\nbob = User(name='Bob' , password = \"pass123\")\nsession.add(bob)\nsession.flush()\npost1 = Post(body='Post 1', user=bob)", - "detail": "examples.serialize", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "examples.serialize", - "description": "examples.serialize", - "peekOfCode": "engine = sa.create_engine('sqlite:///:memory:')\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n password = sa.Column(sa.String)\n name = sa.Column(sa.String)", - "detail": "examples.serialize", - "documentation": {} - }, - { - "label": "session", - "kind": 5, - "importPath": "examples.serialize", - "description": "examples.serialize", - "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n password = sa.Column(sa.String)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')", - "detail": "examples.serialize", - "documentation": {} - }, - { - "label": "bob", - "kind": 5, - "importPath": "examples.serialize", - "description": "examples.serialize", - "peekOfCode": "bob = User(name='Bob' , password = \"pass123\")\nsession.add(bob)\nsession.flush()\npost1 = Post(body='Post 1', user=bob)\nsession.add(post1)\nsession.flush()\npost2 = Post(body='Post 2', user=bob)\nsession.add(post2)\nsession.flush()\n# {'id': 1, 'name': 'Bob' , 'password' : 'pass123'}", - "detail": "examples.serialize", - "documentation": {} - }, - { - "label": "post1", - "kind": 5, - "importPath": "examples.serialize", - "description": "examples.serialize", - "peekOfCode": "post1 = Post(body='Post 1', user=bob)\nsession.add(post1)\nsession.flush()\npost2 = Post(body='Post 2', user=bob)\nsession.add(post2)\nsession.flush()\n# {'id': 1, 'name': 'Bob' , 'password' : 'pass123'}\nprint(bob.to_dict())\n# {'id': 1,\n# 'name': 'Bob',", - "detail": "examples.serialize", - "documentation": {} - }, - { - "label": "post2", - "kind": 5, - "importPath": "examples.serialize", - "description": "examples.serialize", - "peekOfCode": "post2 = Post(body='Post 2', user=bob)\nsession.add(post2)\nsession.flush()\n# {'id': 1, 'name': 'Bob' , 'password' : 'pass123'}\nprint(bob.to_dict())\n# {'id': 1,\n# 'name': 'Bob',\n# 'posts': [{'body': 'Post 1', 'id': 1, 'user_id': 1},\n# {'body': 'Post 2', 'id': 2, 'user_id': 1}]}\nprint(bob.to_dict(nested=True , exclude = ['password']))", - "detail": "examples.serialize", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, SmartQueryMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "class BaseModel(Base, SmartQueryMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n # to smart query relationship, it should be explicitly set,", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n # to smart query relationship, it should be explicitly set,\n # not to be a backref\n posts = sa.orm.relationship('Post')\n comments = sa.orm.relationship('Comment')\n # below relationship will just return query (without executing)", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n # to smart query relationship, it should be explicitly set,\n # not to be a backref\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "Comment", - "kind": 6, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n created_at = sa.Column(sa.DateTime)\n # to smart query relationship, it should be explicitly set,", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "log", - "kind": 2, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "def log(msg):\n print('\\n{}\\n'.format(msg))\n#################### setup ######################\nclass Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, SmartQueryMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "db_file", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "db_file = os.path.join(os.path.dirname(__file__), 'test.sqlite')\nengine = create_engine('sqlite:///{}'.format(db_file), echo=True)\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\nsession = scoped_session(sessionmaker(bind=engine))\nBaseModel.set_session(session)\n#################### setup some data ######################\nu1 = User(name='Bill u1')\nsession.add(u1)\nsession.commit()", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "engine = create_engine('sqlite:///{}'.format(db_file), echo=True)\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\nsession = scoped_session(sessionmaker(bind=engine))\nBaseModel.set_session(session)\n#################### setup some data ######################\nu1 = User(name='Bill u1')\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "session", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nBaseModel.set_session(session)\n#################### setup some data ######################\nu1 = User(name='Bill u1')\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nu3 = User(name='Bishop u3')", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "u1", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "u1 = User(name='Bill u1')\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nu3 = User(name='Bishop u3')\nsession.add(u3)\nsession.commit()\nsession.commit()", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "u2", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "u2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nu3 = User(name='Bishop u3')\nsession.add(u3)\nsession.commit()\nsession.commit()\np11 = Post(\n id=11,\n body='1234567890123',", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "u3", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "u3 = User(name='Bishop u3')\nsession.add(u3)\nsession.commit()\nsession.commit()\np11 = Post(\n id=11,\n body='1234567890123',\n archived=True,\n user=u1\n)", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "p11", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "p11 = Post(\n id=11,\n body='1234567890123',\n archived=True,\n user=u1\n)\nsession.add(p11)\nsession.commit()\np12 = Post(\n id=12,", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "p12", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "p12 = Post(\n id=12,\n body='1234567890',\n user=u1\n)\nsession.add(p12)\nsession.commit()\np21 = Post(\n id=21,\n body='p21',", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "p21", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "p21 = Post(\n id=21,\n body='p21',\n user=u2\n)\nsession.add(p21)\nsession.commit()\np22 = Post(\n id=22,\n body='p22',", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "p22", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "p22 = Post(\n id=22,\n body='p22',\n user=u2\n)\nsession.add(p22)\nsession.commit()\ncm11 = Comment(\n id=11,\n body='cm11',", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "cm11", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "cm11 = Comment(\n id=11,\n body='cm11',\n user=u1,\n post=p11,\n rating=1,\n created_at=datetime.datetime(2014, 1, 1)\n)\nsession.add(cm11)\nsession.commit()", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "cm12", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "cm12 = Comment(\n id=12,\n body='cm12',\n user=u2,\n post=p12,\n rating=2,\n created_at=datetime.datetime(2015, 10, 20)\n)\nsession.add(cm12)\nsession.commit()", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "cm21", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "cm21 = Comment(\n id=21,\n body='cm21',\n user=u1,\n post=p21,\n rating=1,\n created_at=datetime.datetime(2015, 11, 21)\n)\nsession.add(cm21)\nsession.commit()", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "cm22", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "cm22 = Comment(\n id=22,\n body='cm22',\n user=u3,\n post=p22,\n rating=3,\n created_at=datetime.datetime(2016, 11, 20)\n)\nsession.add(cm22)\nsession.commit()", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "cm_empty", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "cm_empty = Comment(\n id=29,\n # no body\n # no user\n # no post\n # no rating\n)\nsession.add(cm_empty)\nsession.commit()\n#################### Demo ######################", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "filters", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "filters = {'user': u1, 'public': True}\nlog(Post.where(**filters).all())\n##### 1.2 filter by hybrid_method 'is_commented_by_user' #####\n# low-level filter_expr()\nlog(session.query(Post).filter(\n *Post.filter_expr(is_commented_by_user=u1)).all())\n# high-level SmartQueryMixin.where() method\nlog(Post.where(is_commented_by_user=u1).all())\n##### 1.3 operators #####\n# rating == None", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "sort_attrs", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "sort_attrs = ['-rating', 'created_at']\nlog(Comment.sort(*sort_attrs))\n##### 2.1.3 hybrid properties\nlog(session.query(Post).order_by(*Post.order_expr('-public')).all())\nlog(Post.sort('-public').all())\n#### 2.2 sort() with auto-joined relations ####\n# sort by name of user ASC (user relation will be auto-joined), then by\n# created_at DESC\nlog(Comment.sort('user___name', '-created_at').all())\n# get comments on public posts first, then order by post user name", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "schema", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "schema = {\n Comment.post: {\n Post.user: JOINED\n }\n}\n##### 3.1 high-level smart_query() class method #####\nres = Comment.smart_query(\n filters={\n 'post___public': True,\n 'user__isnull': False", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "res", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "res = Comment.smart_query(\n filters={\n 'post___public': True,\n 'user__isnull': False\n },\n sort_attrs=['user___name', '-created_at'],\n schema=schema).all()\nlog(res) # cm12, cm21, cm22\n##### 3.2 more flexible smart_query() function #####\n##### 3.2.1. The same as 3.1", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "query", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "query = Comment.query # could be any query you want\nres = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False\n },\n sort_attrs=['user___name', '-created_at'],\n schema=schema).all()\nlog(res) # cm12, cm21, cm22\n##### 3.2.2. Real-life example with lazy='dynamic' relationship", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "res", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "res = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False\n },\n sort_attrs=['user___name', '-created_at'],\n schema=schema).all()\nlog(res) # cm12, cm21, cm22\n##### 3.2.2. Real-life example with lazy='dynamic' relationship\n# let's imagine we want to display some user relations", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "user", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "user = session.query(User).first()\n# and we have initial query for his/her comments\n# (see User.comments_ relationship)\nquery = user.comments_\n# now we just smartly apply all filters, sorts and eagerload. Perfect!\nres = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False\n },", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "query", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "query = user.comments_\n# now we just smartly apply all filters, sorts and eagerload. Perfect!\nres = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False\n },\n sort_attrs=['user___name', '-created_at'],\n schema=schema).all()\nlog(res) # cm21", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "res", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "res = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False\n },\n sort_attrs=['user___name', '-created_at'],\n schema=schema).all()\nlog(res) # cm21\n##### 3.2.3 Logical operators and arbitrary expressions in filters\n# If we want to use OR, NOT or other logical operators in our queries", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "res", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "res = Post.smart_query(filters={\n sa.or_: {'archived': True, 'is_commented_by_user': u3}\n})\nlog(res) # p11, p22\n# Some logic cannot be expressed without using a list instead, e.g.\n# (X OR Y) AND (W OR Z)\n# E.g. (somewhat contrived example):\n# (non-archived OR has comments) AND \n# (user_name like 'B%' or user_name like 'C%')\nres = Post.smart_query(filters=[", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "res", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "res = Post.smart_query(filters=[\n {sa.or_: {'archived': False, 'comments__isnull': False }},\n {sa.or_: [\n {'user___name__like': 'B%'},\n {'user___name__like': 'C%'}\n ]}\n])\n# !! NOTE !! This cannot be used with the where method, e.g. \n# Post.where(**{sa.or: {...}})\n# TypeError!! (only strings are allowed as keyword arguments)", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "res", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "res = Comment.where(post___public=True, post___user___name__like='Bi%').all()\nlog(res)\n# no additional query needed: we used 'post' and 'post__user'\n# relations in smart_query()\nlog(res[0].post)\nlog(res[0].post.user)\n# we didn't use post___comments in filters, so additional query is needed\nlog(res[0].post.comments)\n##### 3.3.2 sort()\nres = Comment.sort('-post___public', 'post___user___name').all()", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "res", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "res = Comment.sort('-post___public', 'post___user___name').all()\nlog(res)\n# no additional query needed: we used 'post' and 'post__user'\n# relations in smart_query()\nlog(res[0].post)\nlog(res[0].post.user)\n# we didn't use post___comments in filters, so additional query is needed\nlog(res[0].post.comments)", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "examples.timestamp", - "description": "examples.timestamp", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = sa.create_engine(\"sqlite:///:memory:\")\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n \"\"\"User Model to example.\"\"\"\n __tablename__ = \"users\"", - "detail": "examples.timestamp", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "examples.timestamp", - "description": "examples.timestamp", - "peekOfCode": "class BaseModel(Base, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n \"\"\"User Model to example.\"\"\"\n __tablename__ = \"users\"\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nBase.metadata.create_all(engine)\nprint(\"Current time: \", datetime.utcnow())", - "detail": "examples.timestamp", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "examples.timestamp", - "description": "examples.timestamp", - "peekOfCode": "class User(BaseModel):\n \"\"\"User Model to example.\"\"\"\n __tablename__ = \"users\"\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nBase.metadata.create_all(engine)\nprint(\"Current time: \", datetime.utcnow())\n# Current time: 2019-03-04 03:53:53.605602\nbob = User(name=\"Bob\")\nsession.add(bob)", - "detail": "examples.timestamp", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "examples.timestamp", - "description": "examples.timestamp", - "peekOfCode": "engine = sa.create_engine(\"sqlite:///:memory:\")\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n \"\"\"User Model to example.\"\"\"\n __tablename__ = \"users\"\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", - "detail": "examples.timestamp", - "documentation": {} - }, - { - "label": "session", - "kind": 5, - "importPath": "examples.timestamp", - "description": "examples.timestamp", - "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n \"\"\"User Model to example.\"\"\"\n __tablename__ = \"users\"\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nBase.metadata.create_all(engine)", - "detail": "examples.timestamp", - "documentation": {} - }, - { - "label": "bob", - "kind": 5, - "importPath": "examples.timestamp", - "description": "examples.timestamp", - "peekOfCode": "bob = User(name=\"Bob\")\nsession.add(bob)\nsession.flush()\nprint(\"Created Bob: \", bob.created_at)\n# Created Bob: 2019-03-04 03:53:53.606765\nprint(\"Pre-update Bob: \", bob.updated_at)\n# Pre-update Bob: 2019-03-04 03:53:53.606769\ntime.sleep(2)\nbob.name = \"Robert\"\nsession.commit()", - "detail": "examples.timestamp", - "documentation": {} - }, - { - "label": "bob.name", - "kind": 5, - "importPath": "examples.timestamp", - "description": "examples.timestamp", - "peekOfCode": "bob.name = \"Robert\"\nsession.commit()\nprint(\"Updated Bob: \", bob.updated_at)\n# Updated Bob: 2019-03-04 03:53:55.613044", - "detail": "examples.timestamp", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nAlternativeBase = declarative_base()\nengine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ActiveRecordMixin):\n __abstract__ = True\n pass\nclass BaseModelAlternative(AlternativeBase, ActiveRecordMixin):", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "class BaseModel(Base, ActiveRecordMixin):\n __abstract__ = True\n pass\nclass BaseModelAlternative(AlternativeBase, ActiveRecordMixin):\n __abstract__ = True\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "BaseModelAlternative", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "class BaseModelAlternative(AlternativeBase, ActiveRecordMixin):\n __abstract__ = True\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\n posts_viewonly = sa.orm.relationship('Post', viewonly=True)\nclass UserAlternative(BaseModelAlternative):", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\n posts_viewonly = sa.orm.relationship('Post', viewonly=True)\nclass UserAlternative(BaseModelAlternative):\n __tablename__ = 'user_alt'\n __repr_attrs__ = ['name']", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "UserAlternative", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "class UserAlternative(BaseModelAlternative):\n __tablename__ = 'user_alt'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n # user = backref from User.post\n comments = sa.orm.relationship('Comment', backref='post')\n @hybrid_property\n def public(self):", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "Comment", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n user = sa.orm.relationship('User', backref='comments')\n # post = backref from Post.comments\nclass TestActiveRecord(unittest.TestCase):", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "TestActiveRecord", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "class TestActiveRecord(unittest.TestCase):\n def setUp(self):\n sess.rollback()\n BaseModel.set_session(None)\n Base.metadata.drop_all(engine)\n Base.metadata.create_all(engine)\n BaseModel.set_session(sess)\n def test_settable_attributes(self):\n self.assertEqual(set(User.settable_attributes),\n {'id', 'name', # normal columns", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "TestActiveRecordAlternative", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "class TestActiveRecordAlternative(unittest.TestCase):\n def setUp(self):\n sess.rollback()\n BaseModelAlternative.set_session(None)\n AlternativeBase.metadata.drop_all(engine)\n AlternativeBase.metadata.create_all(engine)\n BaseModelAlternative.set_session(sess)\n def test_create(self):\n u1 = UserAlternative.create(name='Bill u1')\n self.assertEqual(u1, sess.query(UserAlternative).first())", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "AlternativeBase", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "AlternativeBase = declarative_base()\nengine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ActiveRecordMixin):\n __abstract__ = True\n pass\nclass BaseModelAlternative(AlternativeBase, ActiveRecordMixin):\n __abstract__ = True\nclass User(BaseModel):", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ActiveRecordMixin):\n __abstract__ = True\n pass\nclass BaseModelAlternative(AlternativeBase, ActiveRecordMixin):\n __abstract__ = True\nclass User(BaseModel):\n __tablename__ = 'user'", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "sess", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "sess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ActiveRecordMixin):\n __abstract__ = True\n pass\nclass BaseModelAlternative(AlternativeBase, ActiveRecordMixin):\n __abstract__ = True\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "AsyncBaseModel", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", - "description": "sqlalchemy_mixins.tests.test_activerecordasync", - "peekOfCode": "class AsyncBaseModel(Base, ActiveRecordMixinAsync, SmartQueryMixin):\n __abstract__ = True\nclass User(AsyncBaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = relationship('Post', backref='user', lazy=\"selectin\")\n posts_viewonly = relationship('Post', viewonly=True)\nclass Post(AsyncBaseModel):", - "detail": "sqlalchemy_mixins.tests.test_activerecordasync", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", - "description": "sqlalchemy_mixins.tests.test_activerecordasync", - "peekOfCode": "class User(AsyncBaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = relationship('Post', backref='user', lazy=\"selectin\")\n posts_viewonly = relationship('Post', viewonly=True)\nclass Post(AsyncBaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "sqlalchemy_mixins.tests.test_activerecordasync", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", - "description": "sqlalchemy_mixins.tests.test_activerecordasync", - "peekOfCode": "class Post(AsyncBaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n comments = relationship('Comment', backref='post', lazy=\"selectin\")\n @hybrid_property\n def public(self):\n return not self.archived", - "detail": "sqlalchemy_mixins.tests.test_activerecordasync", - "documentation": {} - }, - { - "label": "Comment", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", - "description": "sqlalchemy_mixins.tests.test_activerecordasync", - "peekOfCode": "class Comment(AsyncBaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n user = relationship('User', backref='comments', lazy=\"selectin\")\nclass TestAsyncActiveRecord(unittest.IsolatedAsyncioTestCase):\n async def asyncSetUp(self):", - "detail": "sqlalchemy_mixins.tests.test_activerecordasync", - "documentation": {} - }, - { - "label": "TestAsyncActiveRecord", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", - "description": "sqlalchemy_mixins.tests.test_activerecordasync", - "peekOfCode": "class TestAsyncActiveRecord(unittest.IsolatedAsyncioTestCase):\n async def asyncSetUp(self):\n self.engine = create_async_engine('sqlite+aiosqlite:///:memory:', echo=False)\n self.async_session = sessionmaker(self.engine, class_=AsyncSession, expire_on_commit=False)\n async with self.engine.begin() as conn:\n await conn.run_sync(Base.metadata.drop_all)\n await conn.run_sync(Base.metadata.create_all)\n AsyncBaseModel.set_session(self.async_session)\n async def asyncTearDown(self):\n await self.engine.dispose()", - "detail": "sqlalchemy_mixins.tests.test_activerecordasync", - "documentation": {} - }, - { - "label": "Base", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", - "description": "sqlalchemy_mixins.tests.test_activerecordasync", - "peekOfCode": "Base = declarative_base()\nclass AsyncBaseModel(Base, ActiveRecordMixinAsync, SmartQueryMixin):\n __abstract__ = True\nclass User(AsyncBaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = relationship('Post', backref='user', lazy=\"selectin\")\n posts_viewonly = relationship('Post', viewonly=True)", - "detail": "sqlalchemy_mixins.tests.test_activerecordasync", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, EagerLoadMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class BaseModel(Base, EagerLoadMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\nclass Post(BaseModel):", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')\nclass Comment(BaseModel):\n __tablename__ = 'comment'", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "Comment", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n user = sa.orm.relationship('User')\n post = sa.orm.relationship('Post')", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "TestEagerLoad", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class TestEagerLoad(unittest.TestCase):\n def setUp(self):\n Base.metadata.drop_all(engine)\n Base.metadata.create_all(engine)\n BaseModel.set_session(sess)\n u1 = User(name='Bill u1')\n sess.add(u1)\n sess.commit()\n u2 = User(name='Alex u2')\n sess.add(u2)", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "TestNoEagerLoad", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class TestNoEagerLoad(TestEagerLoad):\n def test_no_eagerload(self):\n self.assertEqual(self.query_count, 0)\n post = Post.query.get(11)\n self.assertEqual(self.query_count, 1)\n # to get relationship, ADDITIONAL query is needed\n comment = post.comments[0]\n self.assertEqual(self.query_count, 2)\n # to get relationship, ADDITIONAL query is needed\n _ = comment.user", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "TestEagerExpr", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class TestEagerExpr(TestEagerLoad):\n \"\"\"test of low-level eager_expr function\"\"\"\n def _test_ok(self, schema):\n self.assertEqual(self.query_count, 0)\n user = sess.query(User).options(*eager_expr(schema)).get(1)\n self.assertEqual(self.query_count, 2)\n # now, to get relationships, NO additional query is needed\n post = user.posts[0]\n _ = post.comments[0]\n self.assertEqual(self.query_count, 2)", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "TestOrmWithJoinedClassProperties", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class TestOrmWithJoinedClassProperties(TestEagerLoad):\n def _test(self):\n self.assertEqual(self.query_count, 0)\n post = Post.with_joined(Post.comments, Post.user).get(11)\n self.assertEqual(self.query_count, 1)\n # now, to get relationship, NO additional query is needed\n _ = post.comments[0]\n _ = post.user\n self.assertEqual(self.query_count, 1)\nclass TestOrmWithSubquery(TestEagerLoad):", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "TestOrmWithSubquery", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class TestOrmWithSubquery(TestEagerLoad):\n def test(self):\n self.assertEqual(self.query_count, 0)\n # take post with user and comments (including comment author)\n # NOTE: you can separate relations with dot.\n # Its due to SQLAlchemy: https://goo.gl/yM2DLX\n post = Post.with_subquery(Post.user, Post.comments).get(11)\n # 3 queries were executed:\n # 1 - on posts\n # 2 - on user (eagerload subquery)", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "TestOrmWithSubqueryClassProperties", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class TestOrmWithSubqueryClassProperties(TestEagerLoad):\n def test(self):\n self.assertEqual(self.query_count, 0)\n post = Post.with_subquery(Post.comments, Post.user).get(11)\n # 3 queries were executed:\n # 1 - on posts\n # 2 - on comments (eagerload subquery)\n # 3 - on user (eagerload subquery)\n self.assertEqual(self.query_count, 3)\n # now, to get relationship, NO additional query is needed", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "TestOrmWithDict", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class TestOrmWithDict(TestEagerLoad):\n def _test_joinedload(self, schema):\n self.assertEqual(self.query_count, 0)\n post = Post.with_(schema).get(11)\n self.assertEqual(self.query_count, 1)\n # now, to get relationship, NO additional query is needed\n _ = post.comments[0]\n self.assertEqual(self.query_count, 1)\n def test_joinedload_class_properties(self):\n schema = {Post.comments: JOINED}", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, EagerLoadMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "sess", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "sess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, EagerLoadMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_inspection", - "description": "sqlalchemy_mixins.tests.test_inspection", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = create_engine('sqlite:///:memory:', echo=False)\nclass BaseModel(Base, InspectionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n first_name = sa.Column(sa.String)", - "detail": "sqlalchemy_mixins.tests.test_inspection", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_inspection", - "description": "sqlalchemy_mixins.tests.test_inspection", - "peekOfCode": "class BaseModel(Base, InspectionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n first_name = sa.Column(sa.String)\n last_name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\n posts_viewonly = sa.orm.relationship('Post', viewonly=True)", - "detail": "sqlalchemy_mixins.tests.test_inspection", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_inspection", - "description": "sqlalchemy_mixins.tests.test_inspection", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n first_name = sa.Column(sa.String)\n last_name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\n posts_viewonly = sa.orm.relationship('Post', viewonly=True)\n @hybrid_property\n def surname(self):\n return self.last_name", - "detail": "sqlalchemy_mixins.tests.test_inspection", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_inspection", - "description": "sqlalchemy_mixins.tests.test_inspection", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\nclass Parent(BaseModel):\n __tablename__ = 'parent'\n id = sa.Column(sa.Integer, primary_key=True)\nclass Child(Parent):\n some_prop = sa.Column(sa.String)", - "detail": "sqlalchemy_mixins.tests.test_inspection", - "documentation": {} - }, - { - "label": "Parent", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_inspection", - "description": "sqlalchemy_mixins.tests.test_inspection", - "peekOfCode": "class Parent(BaseModel):\n __tablename__ = 'parent'\n id = sa.Column(sa.Integer, primary_key=True)\nclass Child(Parent):\n some_prop = sa.Column(sa.String)\nclass ModelWithTwoPks(BaseModel):\n __tablename__ = 'two_pks'\n pk1 = sa.Column(sa.Integer, primary_key=True)\n pk2 = sa.Column(sa.Integer, primary_key=True)\nclass TestSessionMixin(unittest.TestCase):", - "detail": "sqlalchemy_mixins.tests.test_inspection", - "documentation": {} - }, - { - "label": "Child", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_inspection", - "description": "sqlalchemy_mixins.tests.test_inspection", - "peekOfCode": "class Child(Parent):\n some_prop = sa.Column(sa.String)\nclass ModelWithTwoPks(BaseModel):\n __tablename__ = 'two_pks'\n pk1 = sa.Column(sa.Integer, primary_key=True)\n pk2 = sa.Column(sa.Integer, primary_key=True)\nclass TestSessionMixin(unittest.TestCase):\n def setUp(self):\n Base.metadata.create_all(engine)\n def test_columns(self):", - "detail": "sqlalchemy_mixins.tests.test_inspection", - "documentation": {} - }, - { - "label": "ModelWithTwoPks", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_inspection", - "description": "sqlalchemy_mixins.tests.test_inspection", - "peekOfCode": "class ModelWithTwoPks(BaseModel):\n __tablename__ = 'two_pks'\n pk1 = sa.Column(sa.Integer, primary_key=True)\n pk2 = sa.Column(sa.Integer, primary_key=True)\nclass TestSessionMixin(unittest.TestCase):\n def setUp(self):\n Base.metadata.create_all(engine)\n def test_columns(self):\n self.assertEqual(set(User.columns), {'id', 'first_name', 'last_name'})\n self.assertEqual(set(Post.columns), {'id', 'body', 'user_id'})", - "detail": "sqlalchemy_mixins.tests.test_inspection", - "documentation": {} - }, - { - "label": "TestSessionMixin", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_inspection", - "description": "sqlalchemy_mixins.tests.test_inspection", - "peekOfCode": "class TestSessionMixin(unittest.TestCase):\n def setUp(self):\n Base.metadata.create_all(engine)\n def test_columns(self):\n self.assertEqual(set(User.columns), {'id', 'first_name', 'last_name'})\n self.assertEqual(set(Post.columns), {'id', 'body', 'user_id'})\n def test_nested_columns(self):\n self.assertEqual(set(Parent.columns), {'id'})\n self.assertEqual(set(Child.columns), {'id', 'some_prop'})\n def test_primary_keys(self):", - "detail": "sqlalchemy_mixins.tests.test_inspection", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_inspection", - "description": "sqlalchemy_mixins.tests.test_inspection", - "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nclass BaseModel(Base, InspectionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n first_name = sa.Column(sa.String)\n last_name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')", - "detail": "sqlalchemy_mixins.tests.test_inspection", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_repr", - "description": "sqlalchemy_mixins.tests.test_repr", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n # !!! IMPORTANT !!!\n # include below string to make mixin work\n __repr__ = ReprMixin.__repr__", - "detail": "sqlalchemy_mixins.tests.test_repr", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_repr", - "description": "sqlalchemy_mixins.tests.test_repr", - "peekOfCode": "class BaseModel(Base, ReprMixin):\n __abstract__ = True\n # !!! IMPORTANT !!!\n # include below string to make mixin work\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "sqlalchemy_mixins.tests.test_repr", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_repr", - "description": "sqlalchemy_mixins.tests.test_repr", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\nclass Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "sqlalchemy_mixins.tests.test_repr", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_repr", - "description": "sqlalchemy_mixins.tests.test_repr", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')\nclass Comment(BaseModel):", - "detail": "sqlalchemy_mixins.tests.test_repr", - "documentation": {} - }, - { - "label": "Comment", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_repr", - "description": "sqlalchemy_mixins.tests.test_repr", - "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body', 'post', 'user']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n user = sa.orm.relationship('User')\n post = sa.orm.relationship('Post')", - "detail": "sqlalchemy_mixins.tests.test_repr", - "documentation": {} - }, - { - "label": "TestEagerLoad", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_repr", - "description": "sqlalchemy_mixins.tests.test_repr", - "peekOfCode": "class TestEagerLoad(unittest.TestCase):\n def test(self):\n Base.metadata.drop_all(engine)\n Base.metadata.create_all(engine)\n u1 = User(name='Bill u1', id=1)\n sess.add(u1)\n sess.commit()\n u2 = User(name='Alex u2', id=2)\n sess.add(u2)\n sess.commit()", - "detail": "sqlalchemy_mixins.tests.test_repr", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_repr", - "description": "sqlalchemy_mixins.tests.test_repr", - "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n # !!! IMPORTANT !!!\n # include below string to make mixin work\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):", - "detail": "sqlalchemy_mixins.tests.test_repr", - "documentation": {} - }, - { - "label": "sess", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_repr", - "description": "sqlalchemy_mixins.tests.test_repr", - "peekOfCode": "sess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n # !!! IMPORTANT !!!\n # include below string to make mixin work\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'", - "detail": "sqlalchemy_mixins.tests.test_repr", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_serialize", - "description": "sqlalchemy_mixins.tests.test_serialize", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nclass BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')", - "detail": "sqlalchemy_mixins.tests.test_serialize", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_serialize", - "description": "sqlalchemy_mixins.tests.test_serialize", - "peekOfCode": "class BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\n password = sa.Column(sa.String)\n @hybrid_property", - "detail": "sqlalchemy_mixins.tests.test_serialize", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_serialize", - "description": "sqlalchemy_mixins.tests.test_serialize", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\n password = sa.Column(sa.String)\n @hybrid_property\n def posts_count(self):\n return len(self.posts)\nclass Post(BaseModel):", - "detail": "sqlalchemy_mixins.tests.test_serialize", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_serialize", - "description": "sqlalchemy_mixins.tests.test_serialize", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')\nclass Comment(BaseModel):\n __tablename__ = 'comment'", - "detail": "sqlalchemy_mixins.tests.test_serialize", - "documentation": {} - }, - { - "label": "Comment", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_serialize", - "description": "sqlalchemy_mixins.tests.test_serialize", - "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n user = sa.orm.relationship('User')\n post = sa.orm.relationship('Post')\nclass TestSerialize(unittest.TestCase):", - "detail": "sqlalchemy_mixins.tests.test_serialize", - "documentation": {} - }, - { - "label": "TestSerialize", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_serialize", - "description": "sqlalchemy_mixins.tests.test_serialize", - "peekOfCode": "class TestSerialize(unittest.TestCase):\n @classmethod\n def setUpClass(cls):\n cls.engine = create_engine('sqlite:///:memory:', echo=False)\n def setUp(self):\n self.session = Session(self.engine)\n Base.metadata.create_all(self.engine)\n user_1 = User(name='Bill u1', id=1 , password = 'pass1')\n self.session.add(user_1)\n self.session.commit()", - "detail": "sqlalchemy_mixins.tests.test_serialize", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_session", - "description": "sqlalchemy_mixins.tests.test_session", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = create_engine('sqlite:///:memory:', echo=False)\nsession = Session(engine)\nclass BaseModel(Base, SessionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "sqlalchemy_mixins.tests.test_session", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_session", - "description": "sqlalchemy_mixins.tests.test_session", - "peekOfCode": "class BaseModel(Base, SessionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "sqlalchemy_mixins.tests.test_session", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_session", - "description": "sqlalchemy_mixins.tests.test_session", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\nclass TestSessionMixin(unittest.TestCase):\n def setUp(self):", - "detail": "sqlalchemy_mixins.tests.test_session", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_session", - "description": "sqlalchemy_mixins.tests.test_session", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\nclass TestSessionMixin(unittest.TestCase):\n def setUp(self):\n Base.metadata.create_all(engine)\n def test_set_session(self):\n # before setting session, error is raised\n with self.assertRaises(NoSessionError):", - "detail": "sqlalchemy_mixins.tests.test_session", - "documentation": {} - }, - { - "label": "TestSessionMixin", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_session", - "description": "sqlalchemy_mixins.tests.test_session", - "peekOfCode": "class TestSessionMixin(unittest.TestCase):\n def setUp(self):\n Base.metadata.create_all(engine)\n def test_set_session(self):\n # before setting session, error is raised\n with self.assertRaises(NoSessionError):\n _ = BaseModel.session\n with self.assertRaises(NoSessionError):\n _ = User.session\n with self.assertRaises(NoSessionError):", - "detail": "sqlalchemy_mixins.tests.test_session", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_session", - "description": "sqlalchemy_mixins.tests.test_session", - "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nsession = Session(engine)\nclass BaseModel(Base, SessionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):", - "detail": "sqlalchemy_mixins.tests.test_session", - "documentation": {} - }, - { - "label": "session", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_session", - "description": "sqlalchemy_mixins.tests.test_session", - "peekOfCode": "session = Session(engine)\nclass BaseModel(Base, SessionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'", - "detail": "sqlalchemy_mixins.tests.test_session", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SmartQueryMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class BaseModel(Base, SmartQueryMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n # to smart query relationship, it should be explicitly set,\n # not to be a backref", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n # to smart query relationship, it should be explicitly set,\n # not to be a backref\n posts = sa.orm.relationship('Post')\n comments = sa.orm.relationship('Comment')\n # below relationship will just return query (without executing)", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n # to smart query relationship, it should be explicitly set,\n # not to be a backref\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "Comment", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n created_at = sa.Column(sa.DateTime)\n # to smart query relationship, it should be explicitly set,", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "BaseTest", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class BaseTest(unittest.TestCase):\n def setUp(self):\n sess.rollback()\n BaseModel.set_session(None)\n Base.metadata.drop_all(engine)\n Base.metadata.create_all(engine)\n BaseModel.set_session(sess)\n def _seed(self):\n u1 = User(name='Bill u1')\n sess.add(u1)", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "TestFilterExpr", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class TestFilterExpr(BaseTest):\n # def setUp(self):\n # Base.metadata.create_all(engine)\n def test_filterable_attributes(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n self.assertEqual(set(User.filterable_attributes),\n {'id', 'name', # normal columns\n 'posts', 'comments', 'comments_' # relations\n })", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "TestOrderExpr", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class TestOrderExpr(BaseTest):\n def test_incorrect_expr(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n with self.assertRaises(KeyError):\n _ = sess.query(Post).filter(\n *Post.order_expr('INCORRECT_ATTR')).all()\n with self.assertRaises(KeyError):\n _ = sess.query(Post).filter(\n *Post.order_expr('*body')).all()", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "TestSmartQueryFilters", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class TestSmartQueryFilters(BaseTest):\n def test_incorrect_expr(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n with self.assertRaises(KeyError):\n _ = User.where(INCORRECT_ATTR='nomatter').all()\n def test_is_a_shortcut_to_filter_expr_in_simple_cases(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n \"\"\"when have no joins, where() is a shortcut for filter_expr \"\"\"", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "TestSmartQuerySort", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class TestSmartQuerySort(BaseTest):\n def test_incorrect_expr(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n with self.assertRaises(KeyError):\n _ = Post.sort('INCORRECT_ATTR').all()\n with self.assertRaises(KeyError):\n _ = Post.sort('*body').all()\n def test_is_a_shortcut_to_order_expr_in_simple_cases(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "TestFullSmartQuery", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class TestFullSmartQuery(BaseTest):\n def test_schema_with_strings(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n # standalone function\n query = Comment.query\n res = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "TestSmartQueryAutoEagerLoad", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class TestSmartQueryAutoEagerLoad(BaseTest):\n \"\"\"\n Smart_query does auto-joins for filtering/sorting,\n so there's a sense to tell sqlalchemy that we alreeady joined that relation\n So we test that relations are set to be joinedload\n if they were used in smart_query()\n \"\"\"\n def _seed(self):\n result = BaseTest._seed(self)\n self.query_count = 0", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SmartQueryMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "sess", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "sess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SmartQueryMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_timestamp", - "description": "sqlalchemy_mixins.tests.test_timestamp", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nclass BaseModel(Base, TimestampsMixin):\n \"\"\"Model to use as base.\"\"\"\n __abstract__ = True\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass User(BaseModel):\n \"\"\"User model exemple.\"\"\"\n __tablename__ = 'user'", - "detail": "sqlalchemy_mixins.tests.test_timestamp", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_timestamp", - "description": "sqlalchemy_mixins.tests.test_timestamp", - "peekOfCode": "class BaseModel(Base, TimestampsMixin):\n \"\"\"Model to use as base.\"\"\"\n __abstract__ = True\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass User(BaseModel):\n \"\"\"User model exemple.\"\"\"\n __tablename__ = 'user'\nclass TestTimestamps(unittest.TestCase):\n \"\"\"Test case for Timestamp mixin.\"\"\"", - "detail": "sqlalchemy_mixins.tests.test_timestamp", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_timestamp", - "description": "sqlalchemy_mixins.tests.test_timestamp", - "peekOfCode": "class User(BaseModel):\n \"\"\"User model exemple.\"\"\"\n __tablename__ = 'user'\nclass TestTimestamps(unittest.TestCase):\n \"\"\"Test case for Timestamp mixin.\"\"\"\n @classmethod\n def setUpClass(cls):\n cls.engine = create_engine('sqlite:///:memory:', echo=False)\n def setUp(self):\n self.session = Session(self.engine)", - "detail": "sqlalchemy_mixins.tests.test_timestamp", - "documentation": {} - }, - { - "label": "TestTimestamps", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_timestamp", - "description": "sqlalchemy_mixins.tests.test_timestamp", - "peekOfCode": "class TestTimestamps(unittest.TestCase):\n \"\"\"Test case for Timestamp mixin.\"\"\"\n @classmethod\n def setUpClass(cls):\n cls.engine = create_engine('sqlite:///:memory:', echo=False)\n def setUp(self):\n self.session = Session(self.engine)\n Base.metadata.create_all(self.engine)\n user_1 = User(name='User')\n self.session.add(user_1)", - "detail": "sqlalchemy_mixins.tests.test_timestamp", - "documentation": {} - }, - { - "label": "ModelNotFoundError", - "kind": 6, - "importPath": "sqlalchemy_mixins.activerecord", - "description": "sqlalchemy_mixins.activerecord", - "peekOfCode": "class ModelNotFoundError(ValueError):\n pass\nclass ActiveRecordMixin(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classproperty\n def settable_attributes(cls):\n return cls.columns + cls.hybrid_properties + cls.settable_relations\n def fill(self, **kwargs):\n for name in kwargs.keys():\n if name in self.settable_attributes:", - "detail": "sqlalchemy_mixins.activerecord", - "documentation": {} - }, - { - "label": "ActiveRecordMixin", - "kind": 6, - "importPath": "sqlalchemy_mixins.activerecord", - "description": "sqlalchemy_mixins.activerecord", - "peekOfCode": "class ActiveRecordMixin(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classproperty\n def settable_attributes(cls):\n return cls.columns + cls.hybrid_properties + cls.settable_relations\n def fill(self, **kwargs):\n for name in kwargs.keys():\n if name in self.settable_attributes:\n setattr(self, name, kwargs[name])\n else:", - "detail": "sqlalchemy_mixins.activerecord", - "documentation": {} - }, - { - "label": "ActiveRecordMixinAsync", - "kind": 6, - "importPath": "sqlalchemy_mixins.activerecordasync", - "description": "sqlalchemy_mixins.activerecordasync", - "peekOfCode": "class ActiveRecordMixinAsync(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classmethod\n def _get_primary_key_name(cls) -> str:\n \"\"\"\n Gets the primary key of the model.\n Note: This method can only be used if the model has a single primary key.\n :return: The name of the primary key.\n :raises InvalidRequestError: If the model does not have a primary key or \n has a composite primary key.", - "detail": "sqlalchemy_mixins.activerecordasync", - "documentation": {} - }, - { - "label": "async_root_cls", - "kind": 2, - "importPath": "sqlalchemy_mixins.activerecordasync", - "description": "sqlalchemy_mixins.activerecordasync", - "peekOfCode": "def async_root_cls(query: Query):\n \"\"\"Monkey patch SmaryQuery to handle async queries.\"\"\"\n try:\n return get_root_cls(query)\n except ValueError:\n # Handle async queries\n if query.__dict__[\"_propagate_attrs\"][\"plugin_subject\"].class_:\n return query.__dict__[\"_propagate_attrs\"][\"plugin_subject\"].class_\n raise\nSmaryQuery._get_root_cls = lambda query: async_root_cls(query)", - "detail": "sqlalchemy_mixins.activerecordasync", - "documentation": {} - }, - { - "label": "get_root_cls", - "kind": 5, - "importPath": "sqlalchemy_mixins.activerecordasync", - "description": "sqlalchemy_mixins.activerecordasync", - "peekOfCode": "get_root_cls = SmaryQuery._get_root_cls\ndef async_root_cls(query: Query):\n \"\"\"Monkey patch SmaryQuery to handle async queries.\"\"\"\n try:\n return get_root_cls(query)\n except ValueError:\n # Handle async queries\n if query.__dict__[\"_propagate_attrs\"][\"plugin_subject\"].class_:\n return query.__dict__[\"_propagate_attrs\"][\"plugin_subject\"].class_\n raise", - "detail": "sqlalchemy_mixins.activerecordasync", - "documentation": {} - }, - { - "label": "SmaryQuery._get_root_cls", - "kind": 5, - "importPath": "sqlalchemy_mixins.activerecordasync", - "description": "sqlalchemy_mixins.activerecordasync", - "peekOfCode": "SmaryQuery._get_root_cls = lambda query: async_root_cls(query)\nclass ActiveRecordMixinAsync(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classmethod\n def _get_primary_key_name(cls) -> str:\n \"\"\"\n Gets the primary key of the model.\n Note: This method can only be used if the model has a single primary key.\n :return: The name of the primary key.\n :raises InvalidRequestError: If the model does not have a primary key or ", - "detail": "sqlalchemy_mixins.activerecordasync", - "documentation": {} - }, - { - "label": "EagerLoadMixin", - "kind": 6, - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "peekOfCode": "class EagerLoadMixin(SessionMixin):\n __abstract__ = True\n @classmethod\n def with_(cls, schema):\n \"\"\"\n Query class and eager load schema at once.\n :type schema: dict\n Example:\n schema = {\n Post.user: JOINED, # joinedload user", - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "eager_expr", - "kind": 2, - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "peekOfCode": "def eager_expr(schema):\n \"\"\"\n :type schema: dict\n \"\"\"\n return _eager_expr_from_schema(schema)\ndef _flatten_schema(schema):\n \"\"\"\n :type schema: dict\n \"\"\"\n def _flatten(schema, parent_path, result):", - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "JOINED", - "kind": 5, - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "peekOfCode": "JOINED = 'joined'\nSUBQUERY = 'subquery'\ndef eager_expr(schema):\n \"\"\"\n :type schema: dict\n \"\"\"\n return _eager_expr_from_schema(schema)\ndef _flatten_schema(schema):\n \"\"\"\n :type schema: dict", - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "SUBQUERY", - "kind": 5, - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "peekOfCode": "SUBQUERY = 'subquery'\ndef eager_expr(schema):\n \"\"\"\n :type schema: dict\n \"\"\"\n return _eager_expr_from_schema(schema)\ndef _flatten_schema(schema):\n \"\"\"\n :type schema: dict\n \"\"\"", - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "InspectionMixin", - "kind": 6, - "importPath": "sqlalchemy_mixins.inspection", - "description": "sqlalchemy_mixins.inspection", - "peekOfCode": "class InspectionMixin:\n @classproperty\n def columns(cls):\n return inspect(cls).columns.keys()\n @classproperty\n def primary_keys_full(cls):\n \"\"\"Get primary key properties for a SQLAlchemy cls.\n Taken from marshmallow_sqlalchemy\n \"\"\"\n mapper = cls.__mapper__", - "detail": "sqlalchemy_mixins.inspection", - "documentation": {} - }, - { - "label": "ReprMixin", - "kind": 6, - "importPath": "sqlalchemy_mixins.repr", - "description": "sqlalchemy_mixins.repr", - "peekOfCode": "class ReprMixin:\n __abstract__ = True\n __repr_attrs__ = []\n __repr_max_length__ = 15\n @property\n def _id_str(self):\n ids = inspect(self).identity\n if ids:\n return '-'.join([str(x) for x in ids]) if len(ids) > 1 \\\n else str(ids[0])", - "detail": "sqlalchemy_mixins.repr", - "documentation": {} - }, - { - "label": "SerializeMixin", - "kind": 6, - "importPath": "sqlalchemy_mixins.serialize", - "description": "sqlalchemy_mixins.serialize", - "peekOfCode": "class SerializeMixin(InspectionMixin):\n \"\"\"Mixin to make model serializable.\"\"\"\n __abstract__ = True\n def to_dict(self,nested = False, hybrid_attributes = False, exclude = None):\n \"\"\"Return dict object with model's data.\n :param nested: flag to return nested relationships' data if true\n :type: bool\n :param hybrid_attributes: flag to include hybrid attributes if true\n :type: bool\n :return: dict", - "detail": "sqlalchemy_mixins.serialize", - "documentation": {} - }, - { - "label": "NoSessionError", - "kind": 6, - "importPath": "sqlalchemy_mixins.session", - "description": "sqlalchemy_mixins.session", - "peekOfCode": "class NoSessionError(RuntimeError):\n pass\nclass SessionMixin:\n _session = None\n @classmethod\n def set_session(cls, session):\n \"\"\"\n :type session: scoped_session | Session\n \"\"\"\n cls._session = session", - "detail": "sqlalchemy_mixins.session", - "documentation": {} - }, - { - "label": "SessionMixin", - "kind": 6, - "importPath": "sqlalchemy_mixins.session", - "description": "sqlalchemy_mixins.session", - "peekOfCode": "class SessionMixin:\n _session = None\n @classmethod\n def set_session(cls, session):\n \"\"\"\n :type session: scoped_session | Session\n \"\"\"\n cls._session = session\n @classproperty\n def session(cls):", - "detail": "sqlalchemy_mixins.session", - "documentation": {} - }, - { - "label": "SmartQueryMixin", - "kind": 6, - "importPath": "sqlalchemy_mixins.smartquery", - "description": "sqlalchemy_mixins.smartquery", - "peekOfCode": "class SmartQueryMixin(InspectionMixin, EagerLoadMixin):\n __abstract__ = True\n _operators = {\n 'isnull': lambda c, v: (c == None) if v else (c != None),\n 'exact': operators.eq,\n 'ne': operators.ne, # not equal or is not (for None)\n 'gt': operators.gt, # greater than , >\n 'ge': operators.ge, # greater than or equal, >=\n 'lt': operators.lt, # lower than, <\n 'le': operators.le, # lower than or equal, <=", - "detail": "sqlalchemy_mixins.smartquery", - "documentation": {} - }, - { - "label": "smart_query", - "kind": 2, - "importPath": "sqlalchemy_mixins.smartquery", - "description": "sqlalchemy_mixins.smartquery", - "peekOfCode": "def smart_query(query, filters=None, sort_attrs=None, schema=None):\n \"\"\"\n Does magic Django-ish joins like post___user___name__startswith='Bob'\n (see https://goo.gl/jAgCyM)\n Does filtering, sorting and eager loading at the same time.\n And if, say, filters and sorting need the same joinm it will be done\n only one. That's why all stuff is combined in single method\n :param query: sqlalchemy.orm.query.Query\n :param filters: dict\n :param sort_attrs: List[basestring]", - "detail": "sqlalchemy_mixins.smartquery", - "documentation": {} - }, - { - "label": "RELATION_SPLITTER", - "kind": 5, - "importPath": "sqlalchemy_mixins.smartquery", - "description": "sqlalchemy_mixins.smartquery", - "peekOfCode": "RELATION_SPLITTER = '___'\nOPERATOR_SPLITTER = '__'\nDESC_PREFIX = '-'\ndef _flatten_filter_keys(filters):\n \"\"\"\n :type filters: dict|list\n Flatten the nested filters, extracting keys where they correspond \n to smart_query paths, e.g. \n {or_: {'id__gt': 1000, and_ : {\n 'id__lt': 500,", - "detail": "sqlalchemy_mixins.smartquery", - "documentation": {} - }, - { - "label": "OPERATOR_SPLITTER", - "kind": 5, - "importPath": "sqlalchemy_mixins.smartquery", - "description": "sqlalchemy_mixins.smartquery", - "peekOfCode": "OPERATOR_SPLITTER = '__'\nDESC_PREFIX = '-'\ndef _flatten_filter_keys(filters):\n \"\"\"\n :type filters: dict|list\n Flatten the nested filters, extracting keys where they correspond \n to smart_query paths, e.g. \n {or_: {'id__gt': 1000, and_ : {\n 'id__lt': 500,\n 'related___property__in': (1,2,3) ", - "detail": "sqlalchemy_mixins.smartquery", - "documentation": {} - }, - { - "label": "DESC_PREFIX", - "kind": 5, - "importPath": "sqlalchemy_mixins.smartquery", - "description": "sqlalchemy_mixins.smartquery", - "peekOfCode": "DESC_PREFIX = '-'\ndef _flatten_filter_keys(filters):\n \"\"\"\n :type filters: dict|list\n Flatten the nested filters, extracting keys where they correspond \n to smart_query paths, e.g. \n {or_: {'id__gt': 1000, and_ : {\n 'id__lt': 500,\n 'related___property__in': (1,2,3) \n }}}", - "detail": "sqlalchemy_mixins.smartquery", - "documentation": {} - }, - { - "label": "TimestampsMixin", - "kind": 6, - "importPath": "sqlalchemy_mixins.timestamp", - "description": "sqlalchemy_mixins.timestamp", - "peekOfCode": "class TimestampsMixin:\n \"\"\"Mixin that define timestamp columns.\"\"\"\n __abstract__ = True\n __created_at_name__ = 'created_at'\n __updated_at_name__ = 'updated_at'\n __datetime_func__ = sa.func.now()\n created_at = sa.Column(__created_at_name__,\n sa.TIMESTAMP(timezone=False),\n default=__datetime_func__,\n nullable=False)", - "detail": "sqlalchemy_mixins.timestamp", - "documentation": {} - }, - { - "label": "classproperty", - "kind": 6, - "importPath": "sqlalchemy_mixins.utils", - "description": "sqlalchemy_mixins.utils", - "peekOfCode": "class classproperty(object):\n \"\"\"\n @property for @classmethod\n taken from http://stackoverflow.com/a/13624858\n \"\"\"\n def __init__(self, fget):\n self.fget = fget\n def __get__(self, owner_self, owner_cls):\n return self.fget(owner_cls)\ndef get_relations(cls):", - "detail": "sqlalchemy_mixins.utils", - "documentation": {} - }, - { - "label": "get_relations", - "kind": 2, - "importPath": "sqlalchemy_mixins.utils", - "description": "sqlalchemy_mixins.utils", - "peekOfCode": "def get_relations(cls):\n if isinstance(cls, Mapper):\n mapper = cls\n else:\n mapper = cls.__mapper__\n return [c for c in mapper.attrs\n if isinstance(c, RelationshipProperty)]\ndef path_to_relations_list(cls, path):\n path_as_list = path.split('.')\n relations = get_relations(cls)", - "detail": "sqlalchemy_mixins.utils", - "documentation": {} - }, - { - "label": "path_to_relations_list", - "kind": 2, - "importPath": "sqlalchemy_mixins.utils", - "description": "sqlalchemy_mixins.utils", - "peekOfCode": "def path_to_relations_list(cls, path):\n path_as_list = path.split('.')\n relations = get_relations(cls)\n relations_list = []\n for item in path_as_list:\n for rel in relations:\n if rel.key == item:\n relations_list.append(rel)\n relations = get_relations(rel.entity)\n break", - "detail": "sqlalchemy_mixins.utils", - "documentation": {} - }, - { - "label": "requirements", - "kind": 2, - "importPath": "setup", - "description": "setup", - "peekOfCode": "def requirements():\n import os\n filename = os.path.join(os.path.dirname(__file__), 'requirements.txt')\n return [line.rstrip('\\n') for line in open(filename).readlines()]\nsetup(name='sqlalchemy_mixins',\n version='2.0.5',\n description='Active Record, Django-like queries, nested eager load '\n 'and beauty __repr__ for SQLAlchemy',\n url='https://github.com/absent1706/sqlalchemy-mixins',\n download_url='https://github.com/absent1706/sqlalchemy-mixins/archive/master.tar.gz',", - "detail": "setup", - "documentation": {} - } -] \ No newline at end of file From 65bcb99bc23c5252c1c231d8a5718f4a8ebca008 Mon Sep 17 00:00:00 2001 From: Aurthur Musendame Date: Sun, 1 Sep 2024 16:00:19 +0200 Subject: [PATCH 4/6] added async support --- .vscode/PythonImportHelper-v2-Completion.json | 3149 +++++++++++++++++ sqlalchemy_mixins/__init__.py | 2 + sqlalchemy_mixins/activerecordasync.py | 201 ++ sqlalchemy_mixins/activerecordasync.pyi | 59 + 4 files changed, 3411 insertions(+) create mode 100644 .vscode/PythonImportHelper-v2-Completion.json create mode 100644 sqlalchemy_mixins/activerecordasync.py create mode 100644 sqlalchemy_mixins/activerecordasync.pyi diff --git a/.vscode/PythonImportHelper-v2-Completion.json b/.vscode/PythonImportHelper-v2-Completion.json new file mode 100644 index 0000000..83f2f09 --- /dev/null +++ b/.vscode/PythonImportHelper-v2-Completion.json @@ -0,0 +1,3149 @@ +[ + { + "label": "print_function", + "importPath": "__future__", + "description": "__future__", + "isExtraImport": true, + "detail": "__future__", + "documentation": {} + }, + { + "label": "print_function", + "importPath": "__future__", + "description": "__future__", + "isExtraImport": true, + "detail": "__future__", + "documentation": {} + }, + { + "label": "print_function", + "importPath": "__future__", + "description": "__future__", + "isExtraImport": true, + "detail": "__future__", + "documentation": {} + }, + { + "label": "print_function", + "importPath": "__future__", + "description": "__future__", + "isExtraImport": true, + "detail": "__future__", + "documentation": {} + }, + { + "label": "print_function", + "importPath": "__future__", + "description": "__future__", + "isExtraImport": true, + "detail": "__future__", + "documentation": {} + }, + { + "label": "print_function", + "importPath": "__future__", + "description": "__future__", + "isExtraImport": true, + "detail": "__future__", + "documentation": {} + }, + { + "label": "print_function", + "importPath": "__future__", + "description": "__future__", + "isExtraImport": true, + "detail": "__future__", + "documentation": {} + }, + { + "label": "print_function", + "importPath": "__future__", + "description": "__future__", + "isExtraImport": true, + "detail": "__future__", + "documentation": {} + }, + { + "label": "os", + "kind": 6, + "isExtraImport": true, + "importPath": "os", + "description": "os", + "detail": "os", + "documentation": {} + }, + { + "label": "sqlalchemy", + "kind": 6, + "isExtraImport": true, + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "event", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "event", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "create_engine", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "select", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "inspect", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "inspect", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "asc", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "desc", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "inspect", + "importPath": "sqlalchemy", + "description": "sqlalchemy", + "isExtraImport": true, + "detail": "sqlalchemy", + "documentation": {} + }, + { + "label": "hybrid_property", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "hybrid_method", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "hybrid_property", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "hybrid_property", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "hybrid_property", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "hybrid_method", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "hybrid_property", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "hybrid_property", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "hybrid_method", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "hybrid_property", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "hybrid_method", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, + { + "label": "scoped_session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "sessionmaker", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "scoped_session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "sessionmaker", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Query", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "scoped_session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "sessionmaker", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "scoped_session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "sessionmaker", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "scoped_session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "sessionmaker", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Query", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "scoped_session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "sessionmaker", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "scoped_session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "sessionmaker", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Query", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "declarative_base", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Query", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "sessionmaker", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Query", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Query", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "joinedload", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Load", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "subqueryload", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "RelationshipProperty", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "DeclarativeBase", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "scoped_session", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Query", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "aliased", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "contains_eager", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "RelationshipProperty", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "Mapper", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "ActiveRecordMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "ReprMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "ModelNotFoundError", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "AllFeaturesMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "TimestampsMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "EagerLoadMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "ReprMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "ReprMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "SerializeMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "SmartQueryMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "ReprMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "JOINED", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "smart_query", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "TimestampsMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "ActiveRecordMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "EagerLoadMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "InspectionMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "ReprMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "SerializeMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "SmartQueryMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "smart_query", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "TimestampsMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "JOINED", + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "SUBQUERY", + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "eager_expr", + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "JOINED", + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "SUBQUERY", + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "eager_expr", + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "JOINED", + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "SUBQUERY", + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "datetime", + "kind": 6, + "isExtraImport": true, + "importPath": "datetime", + "description": "datetime", + "detail": "datetime", + "documentation": {} + }, + { + "label": "datetime", + "importPath": "datetime", + "description": "datetime", + "isExtraImport": true, + "detail": "datetime", + "documentation": {} + }, + { + "label": "datetime", + "importPath": "datetime", + "description": "datetime", + "isExtraImport": true, + "detail": "datetime", + "documentation": {} + }, + { + "label": "time", + "kind": 6, + "isExtraImport": true, + "importPath": "time", + "description": "time", + "detail": "time", + "documentation": {} + }, + { + "label": "unittest", + "kind": 6, + "isExtraImport": true, + "importPath": "unittest", + "description": "unittest", + "detail": "unittest", + "documentation": {} + }, + { + "label": "ModelNotFoundError", + "importPath": "sqlalchemy_mixins.activerecord", + "description": "sqlalchemy_mixins.activerecord", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.activerecord", + "documentation": {} + }, + { + "label": "SessionMixin", + "importPath": "sqlalchemy_mixins.session", + "description": "sqlalchemy_mixins.session", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.session", + "documentation": {} + }, + { + "label": "NoSessionError", + "importPath": "sqlalchemy_mixins.session", + "description": "sqlalchemy_mixins.session", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.session", + "documentation": {} + }, + { + "label": "_AbstractLoad", + "importPath": "sqlalchemy.orm.strategy_options", + "description": "sqlalchemy.orm.strategy_options", + "isExtraImport": true, + "detail": "sqlalchemy.orm.strategy_options", + "documentation": {} + }, + { + "label": "string_types", + "importPath": "six", + "description": "six", + "isExtraImport": true, + "detail": "six", + "documentation": {} + }, + { + "label": "Iterable", + "importPath": "collections.abc", + "description": "collections.abc", + "isExtraImport": true, + "detail": "collections.abc", + "documentation": {} + }, + { + "label": "abc", + "importPath": "collections", + "description": "collections", + "isExtraImport": true, + "detail": "collections", + "documentation": {} + }, + { + "label": "OrderedDict", + "importPath": "collections", + "description": "collections", + "isExtraImport": true, + "detail": "collections", + "documentation": {} + }, + { + "label": "AliasedClass", + "importPath": "sqlalchemy.orm.util", + "description": "sqlalchemy.orm.util", + "isExtraImport": true, + "detail": "sqlalchemy.orm.util", + "documentation": {} + }, + { + "label": "operators", + "importPath": "sqlalchemy.sql", + "description": "sqlalchemy.sql", + "isExtraImport": true, + "detail": "sqlalchemy.sql", + "documentation": {} + }, + { + "label": "extract", + "importPath": "sqlalchemy.sql", + "description": "sqlalchemy.sql", + "isExtraImport": true, + "detail": "sqlalchemy.sql", + "documentation": {} + }, + { + "label": "setup", + "importPath": "setuptools", + "description": "setuptools", + "isExtraImport": true, + "detail": "setuptools", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, ActiveRecordMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "class BaseModel(Base, ActiveRecordMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n age = sa.Column(sa.Integer)", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n age = sa.Column(sa.Integer)\n posts = sa.orm.relationship('Post', backref='user')\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n # user = backref from User.post\n @hybrid_property\n def public(self):\n return not self.archived", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "log", + "kind": 2, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "def log(msg):\n print('\\n{}\\n'.format(msg))\n#################### setup ######################\nclass Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, ActiveRecordMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "db_file", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "db_file = os.path.join(os.path.dirname(__file__), 'test.sqlite')\nengine = create_engine('sqlite:///{}'.format(db_file), echo=True)\n# autocommit=True - it's to make you see data in 3rd party DB view tool\nsession = scoped_session(sessionmaker(bind=engine))\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\n# setup base model: inject session so it can be accessed from model\nBaseModel.set_session(session)\n#################### CRUD demo ######################\n# ['id', 'body', 'user_id', 'archived', # normal columns", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "engine = create_engine('sqlite:///{}'.format(db_file), echo=True)\n# autocommit=True - it's to make you see data in 3rd party DB view tool\nsession = scoped_session(sessionmaker(bind=engine))\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\n# setup base model: inject session so it can be accessed from model\nBaseModel.set_session(session)\n#################### CRUD demo ######################\n# ['id', 'body', 'user_id', 'archived', # normal columns\n# 'user', 'comments', # relations", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "session", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\n# setup base model: inject session so it can be accessed from model\nBaseModel.set_session(session)\n#################### CRUD demo ######################\n# ['id', 'body', 'user_id', 'archived', # normal columns\n# 'user', 'comments', # relations\n# 'public'] # hybrid attributes\nprint(Post.settable_attributes)", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "user1", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "user1 = User()\n# equal to\n# user1.name = 'Billy'\n# user1.age = 1\n# session.flush()\nuser1.fill(name='Billy', age=1)\n# you can use kwargs as above or, in real-world apps, unpack dict as below\ndata = {'name': 'Bill', 'age': 21}\nuser1.fill(**data)\n# equal to", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "data", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "data = {'name': 'Bill', 'age': 21}\nuser1.fill(**data)\n# equal to\n# session.add(user1)\n# session.flush()\nuser1.save()\n#### 2. ActiveRecordMixin.create(): ####\n# equal to\n# user2 = User(name='Bob')\n# session.add(user2)", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "user2", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "user2 = User.create(name='Bob')\npost1 = Post.create(body='post1', user=user2)\n#### 3. ActiveRecordMixin.update(): ####\n# equal to\n# post1.fill(...)\n# post1.save()\npost1.update(body='new body', public=True, user=user1)\n#### 4. ActiveRecordMixin.delete(): ####\n# equal to\n# session.delete(post_to_be_deleted)", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "post1", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "post1 = Post.create(body='post1', user=user2)\n#### 3. ActiveRecordMixin.update(): ####\n# equal to\n# post1.fill(...)\n# post1.save()\npost1.update(body='new body', public=True, user=user1)\n#### 4. ActiveRecordMixin.delete(): ####\n# equal to\n# session.delete(post_to_be_deleted)\n# session.flush()", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "post_to_be_deleted", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "post_to_be_deleted = Post.create()\npost_to_be_deleted.delete()\n#### 5. ActiveRecordMixin.destroy() ####\n# equal to\n# session.delete(session.query(User).get(91))\n# session.delete(session.query(User).get(92))\n# session.flush()\n_ = User.create(id=91)\n__ = User.create(id=92)\nUser.destroy(91, 92)", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "_", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "_ = User.create(id=91)\n__ = User.create(id=92)\nUser.destroy(91, 92)\n#################### Query demo ######################\n#### 1. ActiveRecordMixin.all() ####\n# equal to\n# session.query(User).all()\nlog('all users: ' + str(User.all()))\n#### 2. ActiveRecordMixin.first() ####\n# equal to", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "__", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "__ = User.create(id=92)\nUser.destroy(91, 92)\n#################### Query demo ######################\n#### 1. ActiveRecordMixin.all() ####\n# equal to\n# session.query(User).all()\nlog('all users: ' + str(User.all()))\n#### 2. ActiveRecordMixin.first() ####\n# equal to\n# session.query(User).first()", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "user3", + "kind": 5, + "importPath": "examples.activerecord", + "description": "examples.activerecord", + "peekOfCode": "user3 = User.create(name='Bishop', id=3)\nlog('user with id=3: ' + str(User.find(3)))\n#### 4. ActiveRecordMixin.find_or_fail() ####\n# closest code on raw sqlalchemy will be\n# session.query(User).filter_by(id=).one()\n# but one() method throws common error without describing which ID was not\n# found, which is inconvenient: http://www.qopy.me/c5Csw1vWTCuOMKuP07J7iA\ntry:\n print(User.find_or_fail(123987))\nexcept ModelNotFoundError as e:", + "detail": "examples.activerecord", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "examples.all_features", + "description": "examples.all_features", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nclass BaseModel(Base, AllFeaturesMixin, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", + "detail": "examples.all_features", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "examples.all_features", + "description": "examples.all_features", + "peekOfCode": "class BaseModel(Base, AllFeaturesMixin, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'", + "detail": "examples.all_features", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "examples.all_features", + "description": "examples.all_features", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)", + "detail": "examples.all_features", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "examples.all_features", + "description": "examples.all_features", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n rating = sa.Column(sa.Integer)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n # we use this relation in smart_query, so it should be explicitly set\n # (not just a backref from User class)\n user = sa.orm.relationship('User', backref='posts') # but for eagerload", + "detail": "examples.all_features", + "documentation": {} + }, + { + "label": "Comment", + "kind": 6, + "importPath": "examples.all_features", + "description": "examples.all_features", + "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post = sa.orm.relationship('Post')\n user = sa.orm.relationship('User')\nengine = sa.create_engine('sqlite:///:memory:', echo=False)\nsession = scoped_session(sessionmaker(bind=engine))", + "detail": "examples.all_features", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "examples.all_features", + "description": "examples.all_features", + "peekOfCode": "engine = sa.create_engine('sqlite:///:memory:', echo=False)\nsession = scoped_session(sessionmaker(bind=engine))\nBase.metadata.create_all(engine)\nBaseModel.set_session(session)\nbob = User.create(name='Bob')\npost1 = Post.create(body='Post 1', user=bob, rating=3)\npost2 = Post.create(body='long-long-long-long-long body', rating=2,\n user=User.create(name='Bill'),\n comments=[Comment.create(body='cool!', user=bob)])\n# filter using operators like 'in' and 'contains' and relations like 'user'", + "detail": "examples.all_features", + "documentation": {} + }, + { + "label": "session", + "kind": 5, + "importPath": "examples.all_features", + "description": "examples.all_features", + "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nBase.metadata.create_all(engine)\nBaseModel.set_session(session)\nbob = User.create(name='Bob')\npost1 = Post.create(body='Post 1', user=bob, rating=3)\npost2 = Post.create(body='long-long-long-long-long body', rating=2,\n user=User.create(name='Bill'),\n comments=[Comment.create(body='cool!', user=bob)])\n# filter using operators like 'in' and 'contains' and relations like 'user'\n# will output this beauty: ", + "detail": "examples.all_features", + "documentation": {} + }, + { + "label": "bob", + "kind": 5, + "importPath": "examples.all_features", + "description": "examples.all_features", + "peekOfCode": "bob = User.create(name='Bob')\npost1 = Post.create(body='Post 1', user=bob, rating=3)\npost2 = Post.create(body='long-long-long-long-long body', rating=2,\n user=User.create(name='Bill'),\n comments=[Comment.create(body='cool!', user=bob)])\n# filter using operators like 'in' and 'contains' and relations like 'user'\n# will output this beauty: \nprint(Post.where(rating__in=[2, 3, 4], user___name__like='%Bi%').all())\n# joinedload post and user\nprint(Comment.with_joined(Comment.user, Comment.post).first())", + "detail": "examples.all_features", + "documentation": {} + }, + { + "label": "post1", + "kind": 5, + "importPath": "examples.all_features", + "description": "examples.all_features", + "peekOfCode": "post1 = Post.create(body='Post 1', user=bob, rating=3)\npost2 = Post.create(body='long-long-long-long-long body', rating=2,\n user=User.create(name='Bill'),\n comments=[Comment.create(body='cool!', user=bob)])\n# filter using operators like 'in' and 'contains' and relations like 'user'\n# will output this beauty: \nprint(Post.where(rating__in=[2, 3, 4], user___name__like='%Bi%').all())\n# joinedload post and user\nprint(Comment.with_joined(Comment.user, Comment.post).first())\n# subqueryload posts", + "detail": "examples.all_features", + "documentation": {} + }, + { + "label": "post2", + "kind": 5, + "importPath": "examples.all_features", + "description": "examples.all_features", + "peekOfCode": "post2 = Post.create(body='long-long-long-long-long body', rating=2,\n user=User.create(name='Bill'),\n comments=[Comment.create(body='cool!', user=bob)])\n# filter using operators like 'in' and 'contains' and relations like 'user'\n# will output this beauty: \nprint(Post.where(rating__in=[2, 3, 4], user___name__like='%Bi%').all())\n# joinedload post and user\nprint(Comment.with_joined(Comment.user, Comment.post).first())\n# subqueryload posts\nprint(User.with_subquery(User.posts).first())", + "detail": "examples.all_features", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, EagerLoadMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "class BaseModel(Base, EagerLoadMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\n comments = sa.orm.relationship('Comment')\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')\nclass Comment(BaseModel):\n __tablename__ = 'comment'", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "Comment", + "kind": 6, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body', 'post'] # we want to display body and post\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n user = sa.orm.relationship('User')\n post = sa.orm.relationship('Post')", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "log", + "kind": 2, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "def log(msg):\n print('\\n{}\\n'.format(msg))\n#################### setup ######################\nclass Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, EagerLoadMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "reset_session", + "kind": 2, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "def reset_session():\n session = scoped_session(sessionmaker(bind=engine))\n BaseModel.set_session(session)\n return session\n#################### setup some data ######################\nsession = reset_session()\nu1 = User(name='Bill u1', id=1)\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "db_file", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "db_file = os.path.join(os.path.dirname(__file__), 'test.sqlite')\nengine = create_engine('sqlite:///{}'.format(db_file), echo=True)\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\n# sqlalchemy caches data in session, so to not use cache, we recreate session\ndef reset_session():\n session = scoped_session(sessionmaker(bind=engine))\n BaseModel.set_session(session)\n return session\n#################### setup some data ######################", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "engine = create_engine('sqlite:///{}'.format(db_file), echo=True)\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\n# sqlalchemy caches data in session, so to not use cache, we recreate session\ndef reset_session():\n session = scoped_session(sessionmaker(bind=engine))\n BaseModel.set_session(session)\n return session\n#################### setup some data ######################\nsession = reset_session()", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "session", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "session = reset_session()\nu1 = User(name='Bill u1', id=1)\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nsession.commit()\np11 = Post(\n id=11,", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "u1", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "u1 = User(name='Bill u1', id=1)\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nsession.commit()\np11 = Post(\n id=11,\n body='1234567890123',", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "u2", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "u2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nsession.commit()\np11 = Post(\n id=11,\n body='1234567890123',\n archived=True\n)\np11.user = u1", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "p11", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "p11 = Post(\n id=11,\n body='1234567890123',\n archived=True\n)\np11.user = u1\nsession.add(p11)\nsession.commit()\np12 = Post(\n id=12,", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "p11.user", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "p11.user = u1\nsession.add(p11)\nsession.commit()\np12 = Post(\n id=12,\n body='1234567890',\n user=u1\n)\nsession.add(p12)\nsession.commit()", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "p12", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "p12 = Post(\n id=12,\n body='1234567890',\n user=u1\n)\nsession.add(p12)\nsession.commit()\ncm11 = Comment(\n id=11,\n body='cm11 to p11',", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "cm11", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "cm11 = Comment(\n id=11,\n body='cm11 to p11',\n user=u1,\n post=p11,\n rating=1\n)\nsession.add(cm11)\nsession.commit()\ncm12 = Comment(", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "cm12", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "cm12 = Comment(\n id=12,\n body='cm12 to p12',\n user=u2,\n post=p12,\n rating=2\n)\nsession.add(cm12)\nsession.commit()\n#################### Demo ######################", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "comment", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "comment = Comment.with_joined(Comment.user, Comment.post).first()\n# SQL will be like\n\"\"\"\nSELECT comment.*, user_1.*, post_1.*\nFROM comment\nLEFT OUTER JOIN user AS user_1 ON user_1.id = comment.user_id\nLEFT OUTER JOIN post AS post_1 ON post_1.id = comment.post_id\nLEFT OUTER JOIN comment AS comment_1 ON post_1.id = comment_1.post_id\nLIMIT 1 OFFSET 1\n\"\"\"", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "user", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "user = comment.user\npost = comment.post\ncomments = post.comments\nlog('NO ADDITIONAL SQL. END')\n#### 0.2 subqueryload ####\nreset_session()\nusers = User.with_subquery(User.posts).all()\n# there will be 3 queries:\n## first. on users:\n\"\"\"", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "post", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "post = comment.post\ncomments = post.comments\nlog('NO ADDITIONAL SQL. END')\n#### 0.2 subqueryload ####\nreset_session()\nusers = User.with_subquery(User.posts).all()\n# there will be 3 queries:\n## first. on users:\n\"\"\"\nSELECT user.* FROM user", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "comments", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "comments = post.comments\nlog('NO ADDITIONAL SQL. END')\n#### 0.2 subqueryload ####\nreset_session()\nusers = User.with_subquery(User.posts).all()\n# there will be 3 queries:\n## first. on users:\n\"\"\"\nSELECT user.* FROM user\n\"\"\"", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "users", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "users = User.with_subquery(User.posts).all()\n# there will be 3 queries:\n## first. on users:\n\"\"\"\nSELECT user.* FROM user\n\"\"\"\n# second. on posts:\n\"\"\"\nSELECT post.* FROM (SELECT user.id AS user_id FROM user) AS anon_1\nJOIN post ON anon_1.user_id = post.user_id", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "posts", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "posts = users[0].posts\ncomments = posts[0].comments\nlog('NO ADDITIONAL SQL. END')\n#### 1. nested joinedload ####\n# for nested eagerload, you should use dict instead of lists|\n# also make sure you use class properties\nschema = {\n User.posts: {\n Post.comments: {\n Comment.user: JOINED", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "comments", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "comments = posts[0].comments\nlog('NO ADDITIONAL SQL. END')\n#### 1. nested joinedload ####\n# for nested eagerload, you should use dict instead of lists|\n# also make sure you use class properties\nschema = {\n User.posts: {\n Post.comments: {\n Comment.user: JOINED\n }", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "schema", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "schema = {\n User.posts: {\n Post.comments: {\n Comment.user: JOINED\n }\n }\n}\nsession = reset_session()\n###### 1.1 query-level: more flexible\nuser = session.query(User).options(*eager_expr(schema)).get(1)", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "session", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "session = reset_session()\n###### 1.1 query-level: more flexible\nuser = session.query(User).options(*eager_expr(schema)).get(1)\n# SQL will be like\n# note that we select user as parent entity and as post.comments.user\n# EagerLoadMixin will make table aliases for us\n\"\"\"\nSELECT user.*, user_1.*, comment_1.*, post_1.*\nFROM user\nLEFT OUTER JOIN post AS post_1 ON user.id = post_1.user_id", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "user", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "user = session.query(User).options(*eager_expr(schema)).get(1)\n# SQL will be like\n# note that we select user as parent entity and as post.comments.user\n# EagerLoadMixin will make table aliases for us\n\"\"\"\nSELECT user.*, user_1.*, comment_1.*, post_1.*\nFROM user\nLEFT OUTER JOIN post AS post_1 ON user.id = post_1.user_id\nLEFT OUTER JOIN comment AS comment_1 ON post_1.id = comment_1.post_id\nLEFT OUTER JOIN user AS user_1 ON user_1.id = comment_1.user_id", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "user", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "user = User.with_(schema).get(1)\n# now, to get relationships, NO additional query is needed\nlog('NO ADDITIONAL SQL. BEGIN')\npost = user.posts[0]\ncomment = post.comments[0]\ncomment_user = comment.user\nlog('NO ADDITIONAL SQL. END')\n#### 2. combination of joinedload and subqueryload ####\n# sometimes we want to load relations in separate query.\n# i.g. when we load posts, to each post we want to have user and all comments.", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "post", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "post = user.posts[0]\ncomment = post.comments[0]\ncomment_user = comment.user\nlog('NO ADDITIONAL SQL. END')\n#### 2. combination of joinedload and subqueryload ####\n# sometimes we want to load relations in separate query.\n# i.g. when we load posts, to each post we want to have user and all comments.\n# when we load many posts, join comments and comments to each user\nschema = {\n Post.comments: (SUBQUERY, { # load comments in separate query", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "comment", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "comment = post.comments[0]\ncomment_user = comment.user\nlog('NO ADDITIONAL SQL. END')\n#### 2. combination of joinedload and subqueryload ####\n# sometimes we want to load relations in separate query.\n# i.g. when we load posts, to each post we want to have user and all comments.\n# when we load many posts, join comments and comments to each user\nschema = {\n Post.comments: (SUBQUERY, { # load comments in separate query\n Comment.user: JOINED # but, in this separate query, join comments", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "comment_user", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "comment_user = comment.user\nlog('NO ADDITIONAL SQL. END')\n#### 2. combination of joinedload and subqueryload ####\n# sometimes we want to load relations in separate query.\n# i.g. when we load posts, to each post we want to have user and all comments.\n# when we load many posts, join comments and comments to each user\nschema = {\n Post.comments: (SUBQUERY, { # load comments in separate query\n Comment.user: JOINED # but, in this separate query, join comments\n })", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "schema", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "schema = {\n Post.comments: (SUBQUERY, { # load comments in separate query\n Comment.user: JOINED # but, in this separate query, join comments\n })\n}\n###### 2.1 query-level: more flexible\nreset_session()\nposts = session.query(Post).options(*eager_expr(schema)).all()\n###### 2.2 ORM-level: more convenient\nreset_session()", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "posts", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "posts = session.query(Post).options(*eager_expr(schema)).all()\n###### 2.2 ORM-level: more convenient\nreset_session()\nposts = Post.with_(schema).all()\n# there will be 2 queries:\n## first:\n\"\"\"\nSELECT post.* FROM post\n\"\"\"\n# second query loads comments with joined comment users", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "posts", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "posts = Post.with_(schema).all()\n# there will be 2 queries:\n## first:\n\"\"\"\nSELECT post.* FROM post\n\"\"\"\n# second query loads comments with joined comment users\n# it uses first query to get comments for specific posts\n\"\"\"\nSELECT comment.*, user_1.*", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "comments1", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "comments1 = posts[0].comments\ncomments2 = posts[1].comments\nuser1 = posts[0].comments[0].user\nuser2 = posts[1].comments[0].user\nlog('NO ADDITIONAL SQL. END')", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "comments2", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "comments2 = posts[1].comments\nuser1 = posts[0].comments[0].user\nuser2 = posts[1].comments[0].user\nlog('NO ADDITIONAL SQL. END')", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "user1", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "user1 = posts[0].comments[0].user\nuser2 = posts[1].comments[0].user\nlog('NO ADDITIONAL SQL. END')", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "user2", + "kind": 5, + "importPath": "examples.eagerload", + "description": "examples.eagerload", + "peekOfCode": "user2 = posts[1].comments[0].user\nlog('NO ADDITIONAL SQL. END')", + "detail": "examples.eagerload", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "examples.repr", + "description": "examples.repr", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = sa.create_engine('sqlite:///:memory:')\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'", + "detail": "examples.repr", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "examples.repr", + "description": "examples.repr", + "peekOfCode": "class BaseModel(Base, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')", + "detail": "examples.repr", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "examples.repr", + "description": "examples.repr", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\nclass Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n __repr_max_length__ = 25", + "detail": "examples.repr", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "examples.repr", + "description": "examples.repr", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n __repr_max_length__ = 25\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\nBase.metadata.create_all(engine)\nbob = User(name='Bob')\nsession.add(bob)", + "detail": "examples.repr", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "examples.repr", + "description": "examples.repr", + "peekOfCode": "engine = sa.create_engine('sqlite:///:memory:')\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "examples.repr", + "documentation": {} + }, + { + "label": "session", + "kind": 5, + "importPath": "examples.repr", + "description": "examples.repr", + "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", + "detail": "examples.repr", + "documentation": {} + }, + { + "label": "bob", + "kind": 5, + "importPath": "examples.repr", + "description": "examples.repr", + "peekOfCode": "bob = User(name='Bob')\nsession.add(bob)\nsession.flush()\npost1 = Post(body='Post 1', user=bob)\nsession.add(post1)\nsession.flush()\npost2 = Post(body='Post 2 long-long body', user=bob)\nsession.add(post2)\nsession.flush()\n# ", + "detail": "examples.repr", + "documentation": {} + }, + { + "label": "post1", + "kind": 5, + "importPath": "examples.repr", + "description": "examples.repr", + "peekOfCode": "post1 = Post(body='Post 1', user=bob)\nsession.add(post1)\nsession.flush()\npost2 = Post(body='Post 2 long-long body', user=bob)\nsession.add(post2)\nsession.flush()\n# \nprint(bob)\n# \nprint(post1)", + "detail": "examples.repr", + "documentation": {} + }, + { + "label": "post2", + "kind": 5, + "importPath": "examples.repr", + "description": "examples.repr", + "peekOfCode": "post2 = Post(body='Post 2 long-long body', user=bob)\nsession.add(post2)\nsession.flush()\n# \nprint(bob)\n# \nprint(post1)\n# \nprint(post2)", + "detail": "examples.repr", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "examples.serialize", + "description": "examples.serialize", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = sa.create_engine('sqlite:///:memory:')\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "examples.serialize", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "examples.serialize", + "description": "examples.serialize", + "peekOfCode": "class BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n password = sa.Column(sa.String)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\nclass Post(BaseModel):", + "detail": "examples.serialize", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "examples.serialize", + "description": "examples.serialize", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n password = sa.Column(sa.String)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)", + "detail": "examples.serialize", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "examples.serialize", + "description": "examples.serialize", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\nBase.metadata.create_all(engine)\nbob = User(name='Bob' , password = \"pass123\")\nsession.add(bob)\nsession.flush()\npost1 = Post(body='Post 1', user=bob)", + "detail": "examples.serialize", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "examples.serialize", + "description": "examples.serialize", + "peekOfCode": "engine = sa.create_engine('sqlite:///:memory:')\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n password = sa.Column(sa.String)\n name = sa.Column(sa.String)", + "detail": "examples.serialize", + "documentation": {} + }, + { + "label": "session", + "kind": 5, + "importPath": "examples.serialize", + "description": "examples.serialize", + "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n password = sa.Column(sa.String)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')", + "detail": "examples.serialize", + "documentation": {} + }, + { + "label": "bob", + "kind": 5, + "importPath": "examples.serialize", + "description": "examples.serialize", + "peekOfCode": "bob = User(name='Bob' , password = \"pass123\")\nsession.add(bob)\nsession.flush()\npost1 = Post(body='Post 1', user=bob)\nsession.add(post1)\nsession.flush()\npost2 = Post(body='Post 2', user=bob)\nsession.add(post2)\nsession.flush()\n# {'id': 1, 'name': 'Bob' , 'password' : 'pass123'}", + "detail": "examples.serialize", + "documentation": {} + }, + { + "label": "post1", + "kind": 5, + "importPath": "examples.serialize", + "description": "examples.serialize", + "peekOfCode": "post1 = Post(body='Post 1', user=bob)\nsession.add(post1)\nsession.flush()\npost2 = Post(body='Post 2', user=bob)\nsession.add(post2)\nsession.flush()\n# {'id': 1, 'name': 'Bob' , 'password' : 'pass123'}\nprint(bob.to_dict())\n# {'id': 1,\n# 'name': 'Bob',", + "detail": "examples.serialize", + "documentation": {} + }, + { + "label": "post2", + "kind": 5, + "importPath": "examples.serialize", + "description": "examples.serialize", + "peekOfCode": "post2 = Post(body='Post 2', user=bob)\nsession.add(post2)\nsession.flush()\n# {'id': 1, 'name': 'Bob' , 'password' : 'pass123'}\nprint(bob.to_dict())\n# {'id': 1,\n# 'name': 'Bob',\n# 'posts': [{'body': 'Post 1', 'id': 1, 'user_id': 1},\n# {'body': 'Post 2', 'id': 2, 'user_id': 1}]}\nprint(bob.to_dict(nested=True , exclude = ['password']))", + "detail": "examples.serialize", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, SmartQueryMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "class BaseModel(Base, SmartQueryMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n # to smart query relationship, it should be explicitly set,", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n # to smart query relationship, it should be explicitly set,\n # not to be a backref\n posts = sa.orm.relationship('Post')\n comments = sa.orm.relationship('Comment')\n # below relationship will just return query (without executing)", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n # to smart query relationship, it should be explicitly set,\n # not to be a backref\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "Comment", + "kind": 6, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n created_at = sa.Column(sa.DateTime)\n # to smart query relationship, it should be explicitly set,", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "log", + "kind": 2, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "def log(msg):\n print('\\n{}\\n'.format(msg))\n#################### setup ######################\nclass Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, SmartQueryMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "db_file", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "db_file = os.path.join(os.path.dirname(__file__), 'test.sqlite')\nengine = create_engine('sqlite:///{}'.format(db_file), echo=True)\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\nsession = scoped_session(sessionmaker(bind=engine))\nBaseModel.set_session(session)\n#################### setup some data ######################\nu1 = User(name='Bill u1')\nsession.add(u1)\nsession.commit()", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "engine = create_engine('sqlite:///{}'.format(db_file), echo=True)\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\nsession = scoped_session(sessionmaker(bind=engine))\nBaseModel.set_session(session)\n#################### setup some data ######################\nu1 = User(name='Bill u1')\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "session", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nBaseModel.set_session(session)\n#################### setup some data ######################\nu1 = User(name='Bill u1')\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nu3 = User(name='Bishop u3')", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "u1", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "u1 = User(name='Bill u1')\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nu3 = User(name='Bishop u3')\nsession.add(u3)\nsession.commit()\nsession.commit()", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "u2", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "u2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nu3 = User(name='Bishop u3')\nsession.add(u3)\nsession.commit()\nsession.commit()\np11 = Post(\n id=11,\n body='1234567890123',", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "u3", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "u3 = User(name='Bishop u3')\nsession.add(u3)\nsession.commit()\nsession.commit()\np11 = Post(\n id=11,\n body='1234567890123',\n archived=True,\n user=u1\n)", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "p11", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "p11 = Post(\n id=11,\n body='1234567890123',\n archived=True,\n user=u1\n)\nsession.add(p11)\nsession.commit()\np12 = Post(\n id=12,", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "p12", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "p12 = Post(\n id=12,\n body='1234567890',\n user=u1\n)\nsession.add(p12)\nsession.commit()\np21 = Post(\n id=21,\n body='p21',", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "p21", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "p21 = Post(\n id=21,\n body='p21',\n user=u2\n)\nsession.add(p21)\nsession.commit()\np22 = Post(\n id=22,\n body='p22',", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "p22", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "p22 = Post(\n id=22,\n body='p22',\n user=u2\n)\nsession.add(p22)\nsession.commit()\ncm11 = Comment(\n id=11,\n body='cm11',", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "cm11", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "cm11 = Comment(\n id=11,\n body='cm11',\n user=u1,\n post=p11,\n rating=1,\n created_at=datetime.datetime(2014, 1, 1)\n)\nsession.add(cm11)\nsession.commit()", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "cm12", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "cm12 = Comment(\n id=12,\n body='cm12',\n user=u2,\n post=p12,\n rating=2,\n created_at=datetime.datetime(2015, 10, 20)\n)\nsession.add(cm12)\nsession.commit()", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "cm21", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "cm21 = Comment(\n id=21,\n body='cm21',\n user=u1,\n post=p21,\n rating=1,\n created_at=datetime.datetime(2015, 11, 21)\n)\nsession.add(cm21)\nsession.commit()", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "cm22", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "cm22 = Comment(\n id=22,\n body='cm22',\n user=u3,\n post=p22,\n rating=3,\n created_at=datetime.datetime(2016, 11, 20)\n)\nsession.add(cm22)\nsession.commit()", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "cm_empty", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "cm_empty = Comment(\n id=29,\n # no body\n # no user\n # no post\n # no rating\n)\nsession.add(cm_empty)\nsession.commit()\n#################### Demo ######################", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "filters", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "filters = {'user': u1, 'public': True}\nlog(Post.where(**filters).all())\n##### 1.2 filter by hybrid_method 'is_commented_by_user' #####\n# low-level filter_expr()\nlog(session.query(Post).filter(\n *Post.filter_expr(is_commented_by_user=u1)).all())\n# high-level SmartQueryMixin.where() method\nlog(Post.where(is_commented_by_user=u1).all())\n##### 1.3 operators #####\n# rating == None", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "sort_attrs", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "sort_attrs = ['-rating', 'created_at']\nlog(Comment.sort(*sort_attrs))\n##### 2.1.3 hybrid properties\nlog(session.query(Post).order_by(*Post.order_expr('-public')).all())\nlog(Post.sort('-public').all())\n#### 2.2 sort() with auto-joined relations ####\n# sort by name of user ASC (user relation will be auto-joined), then by\n# created_at DESC\nlog(Comment.sort('user___name', '-created_at').all())\n# get comments on public posts first, then order by post user name", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "schema", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "schema = {\n Comment.post: {\n Post.user: JOINED\n }\n}\n##### 3.1 high-level smart_query() class method #####\nres = Comment.smart_query(\n filters={\n 'post___public': True,\n 'user__isnull': False", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "res", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "res = Comment.smart_query(\n filters={\n 'post___public': True,\n 'user__isnull': False\n },\n sort_attrs=['user___name', '-created_at'],\n schema=schema).all()\nlog(res) # cm12, cm21, cm22\n##### 3.2 more flexible smart_query() function #####\n##### 3.2.1. The same as 3.1", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "query", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "query = Comment.query # could be any query you want\nres = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False\n },\n sort_attrs=['user___name', '-created_at'],\n schema=schema).all()\nlog(res) # cm12, cm21, cm22\n##### 3.2.2. Real-life example with lazy='dynamic' relationship", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "res", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "res = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False\n },\n sort_attrs=['user___name', '-created_at'],\n schema=schema).all()\nlog(res) # cm12, cm21, cm22\n##### 3.2.2. Real-life example with lazy='dynamic' relationship\n# let's imagine we want to display some user relations", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "user", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "user = session.query(User).first()\n# and we have initial query for his/her comments\n# (see User.comments_ relationship)\nquery = user.comments_\n# now we just smartly apply all filters, sorts and eagerload. Perfect!\nres = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False\n },", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "query", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "query = user.comments_\n# now we just smartly apply all filters, sorts and eagerload. Perfect!\nres = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False\n },\n sort_attrs=['user___name', '-created_at'],\n schema=schema).all()\nlog(res) # cm21", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "res", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "res = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False\n },\n sort_attrs=['user___name', '-created_at'],\n schema=schema).all()\nlog(res) # cm21\n##### 3.2.3 Logical operators and arbitrary expressions in filters\n# If we want to use OR, NOT or other logical operators in our queries", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "res", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "res = Post.smart_query(filters={\n sa.or_: {'archived': True, 'is_commented_by_user': u3}\n})\nlog(res) # p11, p22\n# Some logic cannot be expressed without using a list instead, e.g.\n# (X OR Y) AND (W OR Z)\n# E.g. (somewhat contrived example):\n# (non-archived OR has comments) AND \n# (user_name like 'B%' or user_name like 'C%')\nres = Post.smart_query(filters=[", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "res", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "res = Post.smart_query(filters=[\n {sa.or_: {'archived': False, 'comments__isnull': False }},\n {sa.or_: [\n {'user___name__like': 'B%'},\n {'user___name__like': 'C%'}\n ]}\n])\n# !! NOTE !! This cannot be used with the where method, e.g. \n# Post.where(**{sa.or: {...}})\n# TypeError!! (only strings are allowed as keyword arguments)", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "res", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "res = Comment.where(post___public=True, post___user___name__like='Bi%').all()\nlog(res)\n# no additional query needed: we used 'post' and 'post__user'\n# relations in smart_query()\nlog(res[0].post)\nlog(res[0].post.user)\n# we didn't use post___comments in filters, so additional query is needed\nlog(res[0].post.comments)\n##### 3.3.2 sort()\nres = Comment.sort('-post___public', 'post___user___name').all()", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "res", + "kind": 5, + "importPath": "examples.smartquery", + "description": "examples.smartquery", + "peekOfCode": "res = Comment.sort('-post___public', 'post___user___name').all()\nlog(res)\n# no additional query needed: we used 'post' and 'post__user'\n# relations in smart_query()\nlog(res[0].post)\nlog(res[0].post.user)\n# we didn't use post___comments in filters, so additional query is needed\nlog(res[0].post.comments)", + "detail": "examples.smartquery", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "examples.timestamp", + "description": "examples.timestamp", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = sa.create_engine(\"sqlite:///:memory:\")\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n \"\"\"User Model to example.\"\"\"\n __tablename__ = \"users\"", + "detail": "examples.timestamp", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "examples.timestamp", + "description": "examples.timestamp", + "peekOfCode": "class BaseModel(Base, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n \"\"\"User Model to example.\"\"\"\n __tablename__ = \"users\"\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nBase.metadata.create_all(engine)\nprint(\"Current time: \", datetime.utcnow())", + "detail": "examples.timestamp", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "examples.timestamp", + "description": "examples.timestamp", + "peekOfCode": "class User(BaseModel):\n \"\"\"User Model to example.\"\"\"\n __tablename__ = \"users\"\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nBase.metadata.create_all(engine)\nprint(\"Current time: \", datetime.utcnow())\n# Current time: 2019-03-04 03:53:53.605602\nbob = User(name=\"Bob\")\nsession.add(bob)", + "detail": "examples.timestamp", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "examples.timestamp", + "description": "examples.timestamp", + "peekOfCode": "engine = sa.create_engine(\"sqlite:///:memory:\")\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n \"\"\"User Model to example.\"\"\"\n __tablename__ = \"users\"\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", + "detail": "examples.timestamp", + "documentation": {} + }, + { + "label": "session", + "kind": 5, + "importPath": "examples.timestamp", + "description": "examples.timestamp", + "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n \"\"\"User Model to example.\"\"\"\n __tablename__ = \"users\"\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nBase.metadata.create_all(engine)", + "detail": "examples.timestamp", + "documentation": {} + }, + { + "label": "bob", + "kind": 5, + "importPath": "examples.timestamp", + "description": "examples.timestamp", + "peekOfCode": "bob = User(name=\"Bob\")\nsession.add(bob)\nsession.flush()\nprint(\"Created Bob: \", bob.created_at)\n# Created Bob: 2019-03-04 03:53:53.606765\nprint(\"Pre-update Bob: \", bob.updated_at)\n# Pre-update Bob: 2019-03-04 03:53:53.606769\ntime.sleep(2)\nbob.name = \"Robert\"\nsession.commit()", + "detail": "examples.timestamp", + "documentation": {} + }, + { + "label": "bob.name", + "kind": 5, + "importPath": "examples.timestamp", + "description": "examples.timestamp", + "peekOfCode": "bob.name = \"Robert\"\nsession.commit()\nprint(\"Updated Bob: \", bob.updated_at)\n# Updated Bob: 2019-03-04 03:53:55.613044", + "detail": "examples.timestamp", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nAlternativeBase = declarative_base()\nengine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ActiveRecordMixin):\n __abstract__ = True\n pass\nclass BaseModelAlternative(AlternativeBase, ActiveRecordMixin):", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "class BaseModel(Base, ActiveRecordMixin):\n __abstract__ = True\n pass\nclass BaseModelAlternative(AlternativeBase, ActiveRecordMixin):\n __abstract__ = True\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "BaseModelAlternative", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "class BaseModelAlternative(AlternativeBase, ActiveRecordMixin):\n __abstract__ = True\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\n posts_viewonly = sa.orm.relationship('Post', viewonly=True)\nclass UserAlternative(BaseModelAlternative):", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\n posts_viewonly = sa.orm.relationship('Post', viewonly=True)\nclass UserAlternative(BaseModelAlternative):\n __tablename__ = 'user_alt'\n __repr_attrs__ = ['name']", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "UserAlternative", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "class UserAlternative(BaseModelAlternative):\n __tablename__ = 'user_alt'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n # user = backref from User.post\n comments = sa.orm.relationship('Comment', backref='post')\n @hybrid_property\n def public(self):", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "Comment", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n user = sa.orm.relationship('User', backref='comments')\n # post = backref from Post.comments\nclass TestActiveRecord(unittest.TestCase):", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "TestActiveRecord", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "class TestActiveRecord(unittest.TestCase):\n def setUp(self):\n sess.rollback()\n BaseModel.set_session(None)\n Base.metadata.drop_all(engine)\n Base.metadata.create_all(engine)\n BaseModel.set_session(sess)\n def test_settable_attributes(self):\n self.assertEqual(set(User.settable_attributes),\n {'id', 'name', # normal columns", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "TestActiveRecordAlternative", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "class TestActiveRecordAlternative(unittest.TestCase):\n def setUp(self):\n sess.rollback()\n BaseModelAlternative.set_session(None)\n AlternativeBase.metadata.drop_all(engine)\n AlternativeBase.metadata.create_all(engine)\n BaseModelAlternative.set_session(sess)\n def test_create(self):\n u1 = UserAlternative.create(name='Bill u1')\n self.assertEqual(u1, sess.query(UserAlternative).first())", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "AlternativeBase", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "AlternativeBase = declarative_base()\nengine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ActiveRecordMixin):\n __abstract__ = True\n pass\nclass BaseModelAlternative(AlternativeBase, ActiveRecordMixin):\n __abstract__ = True\nclass User(BaseModel):", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ActiveRecordMixin):\n __abstract__ = True\n pass\nclass BaseModelAlternative(AlternativeBase, ActiveRecordMixin):\n __abstract__ = True\nclass User(BaseModel):\n __tablename__ = 'user'", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "sess", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_activerecord", + "description": "sqlalchemy_mixins.tests.test_activerecord", + "peekOfCode": "sess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ActiveRecordMixin):\n __abstract__ = True\n pass\nclass BaseModelAlternative(AlternativeBase, ActiveRecordMixin):\n __abstract__ = True\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']", + "detail": "sqlalchemy_mixins.tests.test_activerecord", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, EagerLoadMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class BaseModel(Base, EagerLoadMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\nclass Post(BaseModel):", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')\nclass Comment(BaseModel):\n __tablename__ = 'comment'", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "Comment", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n user = sa.orm.relationship('User')\n post = sa.orm.relationship('Post')", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "TestEagerLoad", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class TestEagerLoad(unittest.TestCase):\n def setUp(self):\n Base.metadata.drop_all(engine)\n Base.metadata.create_all(engine)\n BaseModel.set_session(sess)\n u1 = User(name='Bill u1')\n sess.add(u1)\n sess.commit()\n u2 = User(name='Alex u2')\n sess.add(u2)", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "TestNoEagerLoad", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class TestNoEagerLoad(TestEagerLoad):\n def test_no_eagerload(self):\n self.assertEqual(self.query_count, 0)\n post = Post.query.get(11)\n self.assertEqual(self.query_count, 1)\n # to get relationship, ADDITIONAL query is needed\n comment = post.comments[0]\n self.assertEqual(self.query_count, 2)\n # to get relationship, ADDITIONAL query is needed\n _ = comment.user", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "TestEagerExpr", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class TestEagerExpr(TestEagerLoad):\n \"\"\"test of low-level eager_expr function\"\"\"\n def _test_ok(self, schema):\n self.assertEqual(self.query_count, 0)\n user = sess.query(User).options(*eager_expr(schema)).get(1)\n self.assertEqual(self.query_count, 2)\n # now, to get relationships, NO additional query is needed\n post = user.posts[0]\n _ = post.comments[0]\n self.assertEqual(self.query_count, 2)", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "TestOrmWithJoinedClassProperties", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class TestOrmWithJoinedClassProperties(TestEagerLoad):\n def _test(self):\n self.assertEqual(self.query_count, 0)\n post = Post.with_joined(Post.comments, Post.user).get(11)\n self.assertEqual(self.query_count, 1)\n # now, to get relationship, NO additional query is needed\n _ = post.comments[0]\n _ = post.user\n self.assertEqual(self.query_count, 1)\nclass TestOrmWithSubquery(TestEagerLoad):", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "TestOrmWithSubquery", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class TestOrmWithSubquery(TestEagerLoad):\n def test(self):\n self.assertEqual(self.query_count, 0)\n # take post with user and comments (including comment author)\n # NOTE: you can separate relations with dot.\n # Its due to SQLAlchemy: https://goo.gl/yM2DLX\n post = Post.with_subquery(Post.user, Post.comments).get(11)\n # 3 queries were executed:\n # 1 - on posts\n # 2 - on user (eagerload subquery)", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "TestOrmWithSubqueryClassProperties", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class TestOrmWithSubqueryClassProperties(TestEagerLoad):\n def test(self):\n self.assertEqual(self.query_count, 0)\n post = Post.with_subquery(Post.comments, Post.user).get(11)\n # 3 queries were executed:\n # 1 - on posts\n # 2 - on comments (eagerload subquery)\n # 3 - on user (eagerload subquery)\n self.assertEqual(self.query_count, 3)\n # now, to get relationship, NO additional query is needed", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "TestOrmWithDict", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "class TestOrmWithDict(TestEagerLoad):\n def _test_joinedload(self, schema):\n self.assertEqual(self.query_count, 0)\n post = Post.with_(schema).get(11)\n self.assertEqual(self.query_count, 1)\n # now, to get relationship, NO additional query is needed\n _ = post.comments[0]\n self.assertEqual(self.query_count, 1)\n def test_joinedload_class_properties(self):\n schema = {Post.comments: JOINED}", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, EagerLoadMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "sess", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_eagerload", + "description": "sqlalchemy_mixins.tests.test_eagerload", + "peekOfCode": "sess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, EagerLoadMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", + "detail": "sqlalchemy_mixins.tests.test_eagerload", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_inspection", + "description": "sqlalchemy_mixins.tests.test_inspection", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = create_engine('sqlite:///:memory:', echo=False)\nclass BaseModel(Base, InspectionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n first_name = sa.Column(sa.String)", + "detail": "sqlalchemy_mixins.tests.test_inspection", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_inspection", + "description": "sqlalchemy_mixins.tests.test_inspection", + "peekOfCode": "class BaseModel(Base, InspectionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n first_name = sa.Column(sa.String)\n last_name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\n posts_viewonly = sa.orm.relationship('Post', viewonly=True)", + "detail": "sqlalchemy_mixins.tests.test_inspection", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_inspection", + "description": "sqlalchemy_mixins.tests.test_inspection", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n first_name = sa.Column(sa.String)\n last_name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\n posts_viewonly = sa.orm.relationship('Post', viewonly=True)\n @hybrid_property\n def surname(self):\n return self.last_name", + "detail": "sqlalchemy_mixins.tests.test_inspection", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_inspection", + "description": "sqlalchemy_mixins.tests.test_inspection", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\nclass Parent(BaseModel):\n __tablename__ = 'parent'\n id = sa.Column(sa.Integer, primary_key=True)\nclass Child(Parent):\n some_prop = sa.Column(sa.String)", + "detail": "sqlalchemy_mixins.tests.test_inspection", + "documentation": {} + }, + { + "label": "Parent", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_inspection", + "description": "sqlalchemy_mixins.tests.test_inspection", + "peekOfCode": "class Parent(BaseModel):\n __tablename__ = 'parent'\n id = sa.Column(sa.Integer, primary_key=True)\nclass Child(Parent):\n some_prop = sa.Column(sa.String)\nclass ModelWithTwoPks(BaseModel):\n __tablename__ = 'two_pks'\n pk1 = sa.Column(sa.Integer, primary_key=True)\n pk2 = sa.Column(sa.Integer, primary_key=True)\nclass TestSessionMixin(unittest.TestCase):", + "detail": "sqlalchemy_mixins.tests.test_inspection", + "documentation": {} + }, + { + "label": "Child", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_inspection", + "description": "sqlalchemy_mixins.tests.test_inspection", + "peekOfCode": "class Child(Parent):\n some_prop = sa.Column(sa.String)\nclass ModelWithTwoPks(BaseModel):\n __tablename__ = 'two_pks'\n pk1 = sa.Column(sa.Integer, primary_key=True)\n pk2 = sa.Column(sa.Integer, primary_key=True)\nclass TestSessionMixin(unittest.TestCase):\n def setUp(self):\n Base.metadata.create_all(engine)\n def test_columns(self):", + "detail": "sqlalchemy_mixins.tests.test_inspection", + "documentation": {} + }, + { + "label": "ModelWithTwoPks", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_inspection", + "description": "sqlalchemy_mixins.tests.test_inspection", + "peekOfCode": "class ModelWithTwoPks(BaseModel):\n __tablename__ = 'two_pks'\n pk1 = sa.Column(sa.Integer, primary_key=True)\n pk2 = sa.Column(sa.Integer, primary_key=True)\nclass TestSessionMixin(unittest.TestCase):\n def setUp(self):\n Base.metadata.create_all(engine)\n def test_columns(self):\n self.assertEqual(set(User.columns), {'id', 'first_name', 'last_name'})\n self.assertEqual(set(Post.columns), {'id', 'body', 'user_id'})", + "detail": "sqlalchemy_mixins.tests.test_inspection", + "documentation": {} + }, + { + "label": "TestSessionMixin", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_inspection", + "description": "sqlalchemy_mixins.tests.test_inspection", + "peekOfCode": "class TestSessionMixin(unittest.TestCase):\n def setUp(self):\n Base.metadata.create_all(engine)\n def test_columns(self):\n self.assertEqual(set(User.columns), {'id', 'first_name', 'last_name'})\n self.assertEqual(set(Post.columns), {'id', 'body', 'user_id'})\n def test_nested_columns(self):\n self.assertEqual(set(Parent.columns), {'id'})\n self.assertEqual(set(Child.columns), {'id', 'some_prop'})\n def test_primary_keys(self):", + "detail": "sqlalchemy_mixins.tests.test_inspection", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_inspection", + "description": "sqlalchemy_mixins.tests.test_inspection", + "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nclass BaseModel(Base, InspectionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n first_name = sa.Column(sa.String)\n last_name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')", + "detail": "sqlalchemy_mixins.tests.test_inspection", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_repr", + "description": "sqlalchemy_mixins.tests.test_repr", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n # !!! IMPORTANT !!!\n # include below string to make mixin work\n __repr__ = ReprMixin.__repr__", + "detail": "sqlalchemy_mixins.tests.test_repr", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_repr", + "description": "sqlalchemy_mixins.tests.test_repr", + "peekOfCode": "class BaseModel(Base, ReprMixin):\n __abstract__ = True\n # !!! IMPORTANT !!!\n # include below string to make mixin work\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "sqlalchemy_mixins.tests.test_repr", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_repr", + "description": "sqlalchemy_mixins.tests.test_repr", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\nclass Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "sqlalchemy_mixins.tests.test_repr", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_repr", + "description": "sqlalchemy_mixins.tests.test_repr", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')\nclass Comment(BaseModel):", + "detail": "sqlalchemy_mixins.tests.test_repr", + "documentation": {} + }, + { + "label": "Comment", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_repr", + "description": "sqlalchemy_mixins.tests.test_repr", + "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body', 'post', 'user']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n user = sa.orm.relationship('User')\n post = sa.orm.relationship('Post')", + "detail": "sqlalchemy_mixins.tests.test_repr", + "documentation": {} + }, + { + "label": "TestEagerLoad", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_repr", + "description": "sqlalchemy_mixins.tests.test_repr", + "peekOfCode": "class TestEagerLoad(unittest.TestCase):\n def test(self):\n Base.metadata.drop_all(engine)\n Base.metadata.create_all(engine)\n u1 = User(name='Bill u1', id=1)\n sess.add(u1)\n sess.commit()\n u2 = User(name='Alex u2', id=2)\n sess.add(u2)\n sess.commit()", + "detail": "sqlalchemy_mixins.tests.test_repr", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_repr", + "description": "sqlalchemy_mixins.tests.test_repr", + "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n # !!! IMPORTANT !!!\n # include below string to make mixin work\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):", + "detail": "sqlalchemy_mixins.tests.test_repr", + "documentation": {} + }, + { + "label": "sess", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_repr", + "description": "sqlalchemy_mixins.tests.test_repr", + "peekOfCode": "sess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n # !!! IMPORTANT !!!\n # include below string to make mixin work\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'", + "detail": "sqlalchemy_mixins.tests.test_repr", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_serialize", + "description": "sqlalchemy_mixins.tests.test_serialize", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nclass BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')", + "detail": "sqlalchemy_mixins.tests.test_serialize", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_serialize", + "description": "sqlalchemy_mixins.tests.test_serialize", + "peekOfCode": "class BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\n password = sa.Column(sa.String)\n @hybrid_property", + "detail": "sqlalchemy_mixins.tests.test_serialize", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_serialize", + "description": "sqlalchemy_mixins.tests.test_serialize", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\n password = sa.Column(sa.String)\n @hybrid_property\n def posts_count(self):\n return len(self.posts)\nclass Post(BaseModel):", + "detail": "sqlalchemy_mixins.tests.test_serialize", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_serialize", + "description": "sqlalchemy_mixins.tests.test_serialize", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')\nclass Comment(BaseModel):\n __tablename__ = 'comment'", + "detail": "sqlalchemy_mixins.tests.test_serialize", + "documentation": {} + }, + { + "label": "Comment", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_serialize", + "description": "sqlalchemy_mixins.tests.test_serialize", + "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n user = sa.orm.relationship('User')\n post = sa.orm.relationship('Post')\nclass TestSerialize(unittest.TestCase):", + "detail": "sqlalchemy_mixins.tests.test_serialize", + "documentation": {} + }, + { + "label": "TestSerialize", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_serialize", + "description": "sqlalchemy_mixins.tests.test_serialize", + "peekOfCode": "class TestSerialize(unittest.TestCase):\n @classmethod\n def setUpClass(cls):\n cls.engine = create_engine('sqlite:///:memory:', echo=False)\n def setUp(self):\n self.session = Session(self.engine)\n Base.metadata.create_all(self.engine)\n user_1 = User(name='Bill u1', id=1 , password = 'pass1')\n self.session.add(user_1)\n self.session.commit()", + "detail": "sqlalchemy_mixins.tests.test_serialize", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_session", + "description": "sqlalchemy_mixins.tests.test_session", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = create_engine('sqlite:///:memory:', echo=False)\nsession = Session(engine)\nclass BaseModel(Base, SessionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "sqlalchemy_mixins.tests.test_session", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_session", + "description": "sqlalchemy_mixins.tests.test_session", + "peekOfCode": "class BaseModel(Base, SessionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "sqlalchemy_mixins.tests.test_session", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_session", + "description": "sqlalchemy_mixins.tests.test_session", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\nclass TestSessionMixin(unittest.TestCase):\n def setUp(self):", + "detail": "sqlalchemy_mixins.tests.test_session", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_session", + "description": "sqlalchemy_mixins.tests.test_session", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\nclass TestSessionMixin(unittest.TestCase):\n def setUp(self):\n Base.metadata.create_all(engine)\n def test_set_session(self):\n # before setting session, error is raised\n with self.assertRaises(NoSessionError):", + "detail": "sqlalchemy_mixins.tests.test_session", + "documentation": {} + }, + { + "label": "TestSessionMixin", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_session", + "description": "sqlalchemy_mixins.tests.test_session", + "peekOfCode": "class TestSessionMixin(unittest.TestCase):\n def setUp(self):\n Base.metadata.create_all(engine)\n def test_set_session(self):\n # before setting session, error is raised\n with self.assertRaises(NoSessionError):\n _ = BaseModel.session\n with self.assertRaises(NoSessionError):\n _ = User.session\n with self.assertRaises(NoSessionError):", + "detail": "sqlalchemy_mixins.tests.test_session", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_session", + "description": "sqlalchemy_mixins.tests.test_session", + "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nsession = Session(engine)\nclass BaseModel(Base, SessionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):", + "detail": "sqlalchemy_mixins.tests.test_session", + "documentation": {} + }, + { + "label": "session", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_session", + "description": "sqlalchemy_mixins.tests.test_session", + "peekOfCode": "session = Session(engine)\nclass BaseModel(Base, SessionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'", + "detail": "sqlalchemy_mixins.tests.test_session", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SmartQueryMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class BaseModel(Base, SmartQueryMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n # to smart query relationship, it should be explicitly set,\n # not to be a backref", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n # to smart query relationship, it should be explicitly set,\n # not to be a backref\n posts = sa.orm.relationship('Post')\n comments = sa.orm.relationship('Comment')\n # below relationship will just return query (without executing)", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n # to smart query relationship, it should be explicitly set,\n # not to be a backref\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "Comment", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n created_at = sa.Column(sa.DateTime)\n # to smart query relationship, it should be explicitly set,", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "BaseTest", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class BaseTest(unittest.TestCase):\n def setUp(self):\n sess.rollback()\n BaseModel.set_session(None)\n Base.metadata.drop_all(engine)\n Base.metadata.create_all(engine)\n BaseModel.set_session(sess)\n def _seed(self):\n u1 = User(name='Bill u1')\n sess.add(u1)", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "TestFilterExpr", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class TestFilterExpr(BaseTest):\n # def setUp(self):\n # Base.metadata.create_all(engine)\n def test_filterable_attributes(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n self.assertEqual(set(User.filterable_attributes),\n {'id', 'name', # normal columns\n 'posts', 'comments', 'comments_' # relations\n })", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "TestOrderExpr", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class TestOrderExpr(BaseTest):\n def test_incorrect_expr(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n with self.assertRaises(KeyError):\n _ = sess.query(Post).filter(\n *Post.order_expr('INCORRECT_ATTR')).all()\n with self.assertRaises(KeyError):\n _ = sess.query(Post).filter(\n *Post.order_expr('*body')).all()", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "TestSmartQueryFilters", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class TestSmartQueryFilters(BaseTest):\n def test_incorrect_expr(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n with self.assertRaises(KeyError):\n _ = User.where(INCORRECT_ATTR='nomatter').all()\n def test_is_a_shortcut_to_filter_expr_in_simple_cases(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n \"\"\"when have no joins, where() is a shortcut for filter_expr \"\"\"", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "TestSmartQuerySort", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class TestSmartQuerySort(BaseTest):\n def test_incorrect_expr(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n with self.assertRaises(KeyError):\n _ = Post.sort('INCORRECT_ATTR').all()\n with self.assertRaises(KeyError):\n _ = Post.sort('*body').all()\n def test_is_a_shortcut_to_order_expr_in_simple_cases(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "TestFullSmartQuery", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class TestFullSmartQuery(BaseTest):\n def test_schema_with_strings(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n # standalone function\n query = Comment.query\n res = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "TestSmartQueryAutoEagerLoad", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "class TestSmartQueryAutoEagerLoad(BaseTest):\n \"\"\"\n Smart_query does auto-joins for filtering/sorting,\n so there's a sense to tell sqlalchemy that we alreeady joined that relation\n So we test that relations are set to be joinedload\n if they were used in smart_query()\n \"\"\"\n def _seed(self):\n result = BaseTest._seed(self)\n self.query_count = 0", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "engine", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SmartQueryMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "sess", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_smartquery", + "description": "sqlalchemy_mixins.tests.test_smartquery", + "peekOfCode": "sess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SmartQueryMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", + "detail": "sqlalchemy_mixins.tests.test_smartquery", + "documentation": {} + }, + { + "label": "Base", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_timestamp", + "description": "sqlalchemy_mixins.tests.test_timestamp", + "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nclass BaseModel(Base, TimestampsMixin):\n \"\"\"Model to use as base.\"\"\"\n __abstract__ = True\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass User(BaseModel):\n \"\"\"User model exemple.\"\"\"\n __tablename__ = 'user'", + "detail": "sqlalchemy_mixins.tests.test_timestamp", + "documentation": {} + }, + { + "label": "BaseModel", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_timestamp", + "description": "sqlalchemy_mixins.tests.test_timestamp", + "peekOfCode": "class BaseModel(Base, TimestampsMixin):\n \"\"\"Model to use as base.\"\"\"\n __abstract__ = True\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass User(BaseModel):\n \"\"\"User model exemple.\"\"\"\n __tablename__ = 'user'\nclass TestTimestamps(unittest.TestCase):\n \"\"\"Test case for Timestamp mixin.\"\"\"", + "detail": "sqlalchemy_mixins.tests.test_timestamp", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_timestamp", + "description": "sqlalchemy_mixins.tests.test_timestamp", + "peekOfCode": "class User(BaseModel):\n \"\"\"User model exemple.\"\"\"\n __tablename__ = 'user'\nclass TestTimestamps(unittest.TestCase):\n \"\"\"Test case for Timestamp mixin.\"\"\"\n @classmethod\n def setUpClass(cls):\n cls.engine = create_engine('sqlite:///:memory:', echo=False)\n def setUp(self):\n self.session = Session(self.engine)", + "detail": "sqlalchemy_mixins.tests.test_timestamp", + "documentation": {} + }, + { + "label": "TestTimestamps", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_timestamp", + "description": "sqlalchemy_mixins.tests.test_timestamp", + "peekOfCode": "class TestTimestamps(unittest.TestCase):\n \"\"\"Test case for Timestamp mixin.\"\"\"\n @classmethod\n def setUpClass(cls):\n cls.engine = create_engine('sqlite:///:memory:', echo=False)\n def setUp(self):\n self.session = Session(self.engine)\n Base.metadata.create_all(self.engine)\n user_1 = User(name='User')\n self.session.add(user_1)", + "detail": "sqlalchemy_mixins.tests.test_timestamp", + "documentation": {} + }, + { + "label": "ModelNotFoundError", + "kind": 6, + "importPath": "sqlalchemy_mixins.activerecord", + "description": "sqlalchemy_mixins.activerecord", + "peekOfCode": "class ModelNotFoundError(ValueError):\n pass\nclass ActiveRecordMixin(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classproperty\n def settable_attributes(cls):\n return cls.columns + cls.hybrid_properties + cls.settable_relations\n def fill(self, **kwargs):\n for name in kwargs.keys():\n if name in self.settable_attributes:", + "detail": "sqlalchemy_mixins.activerecord", + "documentation": {} + }, + { + "label": "ActiveRecordMixin", + "kind": 6, + "importPath": "sqlalchemy_mixins.activerecord", + "description": "sqlalchemy_mixins.activerecord", + "peekOfCode": "class ActiveRecordMixin(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classproperty\n def settable_attributes(cls):\n return cls.columns + cls.hybrid_properties + cls.settable_relations\n def fill(self, **kwargs):\n for name in kwargs.keys():\n if name in self.settable_attributes:\n setattr(self, name, kwargs[name])\n else:", + "detail": "sqlalchemy_mixins.activerecord", + "documentation": {} + }, + { + "label": "ActiveRecordMixinAsync", + "kind": 6, + "importPath": "sqlalchemy_mixins.activerecordasync", + "description": "sqlalchemy_mixins.activerecordasync", + "peekOfCode": "class ActiveRecordMixinAsync(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classproperty\n def query(cls):\n \"\"\"\n Override the default query property to handle async session.\n \"\"\"\n if not hasattr(cls.session, \"query\"):\n return select(cls)\n return cls.session.query(cls)", + "detail": "sqlalchemy_mixins.activerecordasync", + "documentation": {} + }, + { + "label": "async_root_cls", + "kind": 2, + "importPath": "sqlalchemy_mixins.activerecordasync", + "description": "sqlalchemy_mixins.activerecordasync", + "peekOfCode": "def async_root_cls(query: Query):\n \"\"\"Monkey patch SmaryQuery to handle async queries.\"\"\"\n try:\n return get_root_cls(query)\n except ValueError:\n # Handle async queries\n if query.__dict__[\"_propagate_attrs\"][\"plugin_subject\"].class_:\n return query.__dict__[\"_propagate_attrs\"][\"plugin_subject\"].class_\n raise\nSmaryQuery._get_root_cls = lambda query: async_root_cls(query)", + "detail": "sqlalchemy_mixins.activerecordasync", + "documentation": {} + }, + { + "label": "get_root_cls", + "kind": 5, + "importPath": "sqlalchemy_mixins.activerecordasync", + "description": "sqlalchemy_mixins.activerecordasync", + "peekOfCode": "get_root_cls = SmaryQuery._get_root_cls\ndef async_root_cls(query: Query):\n \"\"\"Monkey patch SmaryQuery to handle async queries.\"\"\"\n try:\n return get_root_cls(query)\n except ValueError:\n # Handle async queries\n if query.__dict__[\"_propagate_attrs\"][\"plugin_subject\"].class_:\n return query.__dict__[\"_propagate_attrs\"][\"plugin_subject\"].class_\n raise", + "detail": "sqlalchemy_mixins.activerecordasync", + "documentation": {} + }, + { + "label": "SmaryQuery._get_root_cls", + "kind": 5, + "importPath": "sqlalchemy_mixins.activerecordasync", + "description": "sqlalchemy_mixins.activerecordasync", + "peekOfCode": "SmaryQuery._get_root_cls = lambda query: async_root_cls(query)\nclass ActiveRecordMixinAsync(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classproperty\n def query(cls):\n \"\"\"\n Override the default query property to handle async session.\n \"\"\"\n if not hasattr(cls.session, \"query\"):\n return select(cls)", + "detail": "sqlalchemy_mixins.activerecordasync", + "documentation": {} + }, + { + "label": "EagerLoadMixin", + "kind": 6, + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "peekOfCode": "class EagerLoadMixin(SessionMixin):\n __abstract__ = True\n @classmethod\n def with_(cls, schema):\n \"\"\"\n Query class and eager load schema at once.\n :type schema: dict\n Example:\n schema = {\n Post.user: JOINED, # joinedload user", + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "eager_expr", + "kind": 2, + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "peekOfCode": "def eager_expr(schema):\n \"\"\"\n :type schema: dict\n \"\"\"\n return _eager_expr_from_schema(schema)\ndef _flatten_schema(schema):\n \"\"\"\n :type schema: dict\n \"\"\"\n def _flatten(schema, parent_path, result):", + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "JOINED", + "kind": 5, + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "peekOfCode": "JOINED = 'joined'\nSUBQUERY = 'subquery'\ndef eager_expr(schema):\n \"\"\"\n :type schema: dict\n \"\"\"\n return _eager_expr_from_schema(schema)\ndef _flatten_schema(schema):\n \"\"\"\n :type schema: dict", + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "SUBQUERY", + "kind": 5, + "importPath": "sqlalchemy_mixins.eagerload", + "description": "sqlalchemy_mixins.eagerload", + "peekOfCode": "SUBQUERY = 'subquery'\ndef eager_expr(schema):\n \"\"\"\n :type schema: dict\n \"\"\"\n return _eager_expr_from_schema(schema)\ndef _flatten_schema(schema):\n \"\"\"\n :type schema: dict\n \"\"\"", + "detail": "sqlalchemy_mixins.eagerload", + "documentation": {} + }, + { + "label": "InspectionMixin", + "kind": 6, + "importPath": "sqlalchemy_mixins.inspection", + "description": "sqlalchemy_mixins.inspection", + "peekOfCode": "class InspectionMixin:\n @classproperty\n def columns(cls):\n return inspect(cls).columns.keys()\n @classproperty\n def primary_keys_full(cls):\n \"\"\"Get primary key properties for a SQLAlchemy cls.\n Taken from marshmallow_sqlalchemy\n \"\"\"\n mapper = cls.__mapper__", + "detail": "sqlalchemy_mixins.inspection", + "documentation": {} + }, + { + "label": "ReprMixin", + "kind": 6, + "importPath": "sqlalchemy_mixins.repr", + "description": "sqlalchemy_mixins.repr", + "peekOfCode": "class ReprMixin:\n __abstract__ = True\n __repr_attrs__ = []\n __repr_max_length__ = 15\n @property\n def _id_str(self):\n ids = inspect(self).identity\n if ids:\n return '-'.join([str(x) for x in ids]) if len(ids) > 1 \\\n else str(ids[0])", + "detail": "sqlalchemy_mixins.repr", + "documentation": {} + }, + { + "label": "SerializeMixin", + "kind": 6, + "importPath": "sqlalchemy_mixins.serialize", + "description": "sqlalchemy_mixins.serialize", + "peekOfCode": "class SerializeMixin(InspectionMixin):\n \"\"\"Mixin to make model serializable.\"\"\"\n __abstract__ = True\n def to_dict(self,nested = False, hybrid_attributes = False, exclude = None):\n \"\"\"Return dict object with model's data.\n :param nested: flag to return nested relationships' data if true\n :type: bool\n :param hybrid_attributes: flag to include hybrid attributes if true\n :type: bool\n :return: dict", + "detail": "sqlalchemy_mixins.serialize", + "documentation": {} + }, + { + "label": "NoSessionError", + "kind": 6, + "importPath": "sqlalchemy_mixins.session", + "description": "sqlalchemy_mixins.session", + "peekOfCode": "class NoSessionError(RuntimeError):\n pass\nclass SessionMixin:\n _session = None\n @classmethod\n def set_session(cls, session):\n \"\"\"\n :type session: scoped_session | Session\n \"\"\"\n cls._session = session", + "detail": "sqlalchemy_mixins.session", + "documentation": {} + }, + { + "label": "SessionMixin", + "kind": 6, + "importPath": "sqlalchemy_mixins.session", + "description": "sqlalchemy_mixins.session", + "peekOfCode": "class SessionMixin:\n _session = None\n @classmethod\n def set_session(cls, session):\n \"\"\"\n :type session: scoped_session | Session\n \"\"\"\n cls._session = session\n @classproperty\n def session(cls):", + "detail": "sqlalchemy_mixins.session", + "documentation": {} + }, + { + "label": "SmartQueryMixin", + "kind": 6, + "importPath": "sqlalchemy_mixins.smartquery", + "description": "sqlalchemy_mixins.smartquery", + "peekOfCode": "class SmartQueryMixin(InspectionMixin, EagerLoadMixin):\n __abstract__ = True\n _operators = {\n 'isnull': lambda c, v: (c == None) if v else (c != None),\n 'exact': operators.eq,\n 'ne': operators.ne, # not equal or is not (for None)\n 'gt': operators.gt, # greater than , >\n 'ge': operators.ge, # greater than or equal, >=\n 'lt': operators.lt, # lower than, <\n 'le': operators.le, # lower than or equal, <=", + "detail": "sqlalchemy_mixins.smartquery", + "documentation": {} + }, + { + "label": "smart_query", + "kind": 2, + "importPath": "sqlalchemy_mixins.smartquery", + "description": "sqlalchemy_mixins.smartquery", + "peekOfCode": "def smart_query(query, filters=None, sort_attrs=None, schema=None):\n \"\"\"\n Does magic Django-ish joins like post___user___name__startswith='Bob'\n (see https://goo.gl/jAgCyM)\n Does filtering, sorting and eager loading at the same time.\n And if, say, filters and sorting need the same joinm it will be done\n only one. That's why all stuff is combined in single method\n :param query: sqlalchemy.orm.query.Query\n :param filters: dict\n :param sort_attrs: List[basestring]", + "detail": "sqlalchemy_mixins.smartquery", + "documentation": {} + }, + { + "label": "RELATION_SPLITTER", + "kind": 5, + "importPath": "sqlalchemy_mixins.smartquery", + "description": "sqlalchemy_mixins.smartquery", + "peekOfCode": "RELATION_SPLITTER = '___'\nOPERATOR_SPLITTER = '__'\nDESC_PREFIX = '-'\ndef _flatten_filter_keys(filters):\n \"\"\"\n :type filters: dict|list\n Flatten the nested filters, extracting keys where they correspond \n to smart_query paths, e.g. \n {or_: {'id__gt': 1000, and_ : {\n 'id__lt': 500,", + "detail": "sqlalchemy_mixins.smartquery", + "documentation": {} + }, + { + "label": "OPERATOR_SPLITTER", + "kind": 5, + "importPath": "sqlalchemy_mixins.smartquery", + "description": "sqlalchemy_mixins.smartquery", + "peekOfCode": "OPERATOR_SPLITTER = '__'\nDESC_PREFIX = '-'\ndef _flatten_filter_keys(filters):\n \"\"\"\n :type filters: dict|list\n Flatten the nested filters, extracting keys where they correspond \n to smart_query paths, e.g. \n {or_: {'id__gt': 1000, and_ : {\n 'id__lt': 500,\n 'related___property__in': (1,2,3) ", + "detail": "sqlalchemy_mixins.smartquery", + "documentation": {} + }, + { + "label": "DESC_PREFIX", + "kind": 5, + "importPath": "sqlalchemy_mixins.smartquery", + "description": "sqlalchemy_mixins.smartquery", + "peekOfCode": "DESC_PREFIX = '-'\ndef _flatten_filter_keys(filters):\n \"\"\"\n :type filters: dict|list\n Flatten the nested filters, extracting keys where they correspond \n to smart_query paths, e.g. \n {or_: {'id__gt': 1000, and_ : {\n 'id__lt': 500,\n 'related___property__in': (1,2,3) \n }}}", + "detail": "sqlalchemy_mixins.smartquery", + "documentation": {} + }, + { + "label": "TimestampsMixin", + "kind": 6, + "importPath": "sqlalchemy_mixins.timestamp", + "description": "sqlalchemy_mixins.timestamp", + "peekOfCode": "class TimestampsMixin:\n \"\"\"Mixin that define timestamp columns.\"\"\"\n __abstract__ = True\n __created_at_name__ = 'created_at'\n __updated_at_name__ = 'updated_at'\n __datetime_func__ = sa.func.now()\n created_at = sa.Column(__created_at_name__,\n sa.TIMESTAMP(timezone=False),\n default=__datetime_func__,\n nullable=False)", + "detail": "sqlalchemy_mixins.timestamp", + "documentation": {} + }, + { + "label": "classproperty", + "kind": 6, + "importPath": "sqlalchemy_mixins.utils", + "description": "sqlalchemy_mixins.utils", + "peekOfCode": "class classproperty(object):\n \"\"\"\n @property for @classmethod\n taken from http://stackoverflow.com/a/13624858\n \"\"\"\n def __init__(self, fget):\n self.fget = fget\n def __get__(self, owner_self, owner_cls):\n return self.fget(owner_cls)\ndef get_relations(cls):", + "detail": "sqlalchemy_mixins.utils", + "documentation": {} + }, + { + "label": "get_relations", + "kind": 2, + "importPath": "sqlalchemy_mixins.utils", + "description": "sqlalchemy_mixins.utils", + "peekOfCode": "def get_relations(cls):\n if isinstance(cls, Mapper):\n mapper = cls\n else:\n mapper = cls.__mapper__\n return [c for c in mapper.attrs\n if isinstance(c, RelationshipProperty)]\ndef path_to_relations_list(cls, path):\n path_as_list = path.split('.')\n relations = get_relations(cls)", + "detail": "sqlalchemy_mixins.utils", + "documentation": {} + }, + { + "label": "path_to_relations_list", + "kind": 2, + "importPath": "sqlalchemy_mixins.utils", + "description": "sqlalchemy_mixins.utils", + "peekOfCode": "def path_to_relations_list(cls, path):\n path_as_list = path.split('.')\n relations = get_relations(cls)\n relations_list = []\n for item in path_as_list:\n for rel in relations:\n if rel.key == item:\n relations_list.append(rel)\n relations = get_relations(rel.entity)\n break", + "detail": "sqlalchemy_mixins.utils", + "documentation": {} + }, + { + "label": "requirements", + "kind": 2, + "importPath": "setup", + "description": "setup", + "peekOfCode": "def requirements():\n import os\n filename = os.path.join(os.path.dirname(__file__), 'requirements.txt')\n return [line.rstrip('\\n') for line in open(filename).readlines()]\nsetup(name='sqlalchemy_mixins',\n version='2.0.5',\n description='Active Record, Django-like queries, nested eager load '\n 'and beauty __repr__ for SQLAlchemy',\n url='https://github.com/absent1706/sqlalchemy-mixins',\n download_url='https://github.com/absent1706/sqlalchemy-mixins/archive/master.tar.gz',", + "detail": "setup", + "documentation": {} + } +] \ No newline at end of file diff --git a/sqlalchemy_mixins/__init__.py b/sqlalchemy_mixins/__init__.py index 42814dc..051ce4c 100644 --- a/sqlalchemy_mixins/__init__.py +++ b/sqlalchemy_mixins/__init__.py @@ -4,6 +4,7 @@ # high-level mixins from .activerecord import ActiveRecordMixin, ModelNotFoundError +from .activerecordasync import ActiveRecordMixinAsync from .smartquery import SmartQueryMixin, smart_query from .eagerload import EagerLoadMixin, JOINED, SUBQUERY from .repr import ReprMixin @@ -19,6 +20,7 @@ class AllFeaturesMixin(ActiveRecordMixin, SmartQueryMixin, ReprMixin, SerializeM __all__ = [ "ActiveRecordMixin", + "ActiveRecordMixinAsync", "AllFeaturesMixin", "EagerLoadMixin", "InspectionMixin", diff --git a/sqlalchemy_mixins/activerecordasync.py b/sqlalchemy_mixins/activerecordasync.py new file mode 100644 index 0000000..b01ef28 --- /dev/null +++ b/sqlalchemy_mixins/activerecordasync.py @@ -0,0 +1,201 @@ +from sqlalchemy import select +from sqlalchemy.orm import Query +from .utils import classproperty +from .session import SessionMixin +from .inspection import InspectionMixin +from .activerecord import ModelNotFoundError +from . import smartquery as SmaryQuery + +get_root_cls = SmaryQuery._get_root_cls +def async_root_cls(query: Query): + """Monkey patch SmaryQuery to handle async queries.""" + try: + return get_root_cls(query) + except ValueError: + # Handle async queries + if query.__dict__["_propagate_attrs"]["plugin_subject"].class_: + return query.__dict__["_propagate_attrs"]["plugin_subject"].class_ + raise + +SmaryQuery._get_root_cls = lambda query: async_root_cls(query) + + +class ActiveRecordMixinAsync(InspectionMixin, SessionMixin): + __abstract__ = True + + @classproperty + def query(cls): + """ + Override the default query property to handle async session. + """ + if not hasattr(cls.session, "query"): + return select(cls) + + return cls.session.query(cls) + + async def save_async(self): + """ + Async version of :meth:`save` method. + + :see: :meth:`save` method for more information. + """ + async with self.session() as session: + try: + session.add(self) + await session.commit() + return self + except: + await session.rollback() + raise + + @classmethod + async def create_async(cls, **kwargs): + """ + Async version of :meth:`create` method. + + :see: :meth:`create` + """ + return await cls().fill(**kwargs).save_async() + + async def update_async(self, **kwargs): + """ + Async version of :meth:`update` method. + + :see: :meth:`update` + """ + return await self.fill(**kwargs).save_async() + + async def delete_async(self): + """ + Async version of :meth:`delete` method. + + :see: :meth:`delete` + """ + async with self.session() as session: + try: + session.sync_session.delete(self) + await session.commit() + return self + except: + await session.rollback() + raise + finally: + await session.flush() + + @classmethod + async def destroy_async(cls, *ids): + """ + Async version of :meth:`destroy` method. + + :see: :meth:`destroy` + """ + primary_key = cls._get_primary_key_name() + if primary_key: + async with cls.session() as session: + try: + for row in await cls.where_async(**{f"{primary_key}__in": ids}): + session.sync_session.delete(row) + await session.commit() + except: + await session.rollback() + raise + await session.flush() + + @classmethod + async def select_async(cls, stmt=None, filters=None, sort_attrs=None, schema=None): + async with cls.session() as session: + if stmt is None: + stmt = cls.smart_query( + filters=filters, sort_attrs=sort_attrs, schema=schema) + return (await session.execute(stmt)).scalars() + + @classmethod + async def where_async(cls, **filters): + """ + Aync version of where method. + + :see: :meth:`where` method for more details. + """ + return await cls.select_async(filters=filters) + + @classmethod + async def sort_async(cls, *columns): + """ + Async version of sort method. + + :see: :meth:`sort` method for more details. + """ + return await cls.select_async(sort_attrs=columns) + + @classmethod + async def all_async(cls): + """ + Async version of all method. + This is same as calling ``(await select_async()).all()``. + + :see: :meth:`all` method for more details. + """ + return (await cls.select_async()).all() + + @classmethod + async def first_async(cls): + """ + Async version of first method. + This is same as calling ``(await select_async()).first()``. + + :see: :meth:`first` method for more details. + """ + return (await cls.select_async()).first() + + @classmethod + async def find_async(cls, id_): + """ + Async version of find method. + + :see: :meth:`find` method for more details. + """ + primary_key = cls._get_primary_key_name() + if primary_key: + return (await cls.where_async(**{primary_key: id_})).first() + return None + + @classmethod + async def find_or_fail_async(cls, id_): + """ + Async version of find_or_fail method. + + :see: :meth:`find_or_fail` method for more details. + """ + cursor = await cls.find_async(id_) + if cursor: + return cursor + else: + raise ModelNotFoundError("{} with id '{}' was not found" + .format(cls.__name__, id_)) + + @classmethod + async def with_async(cls, schema): + """ + Async version of with method. + + :see: :meth:`with` method for more details. + """ + return await cls.select_async(cls.with_(schema)) + + @classmethod + async def with_joined_async(cls, *paths): + """ + Async version of with_joined method. + + :see: :meth:`with_joined` method for more details. + """ + return await cls.select_async(cls.with_joined(*paths)) + + @classmethod + async def with_subquery_async(cls, *paths): + """ + Async version of with_subquery method. + + :see: :meth:`with_subquery` method for more details. + """ + return await cls.select_async(cls.with_subquery(*paths)) diff --git a/sqlalchemy_mixins/activerecordasync.pyi b/sqlalchemy_mixins/activerecordasync.pyi new file mode 100644 index 0000000..de80ce2 --- /dev/null +++ b/sqlalchemy_mixins/activerecordasync.pyi @@ -0,0 +1,59 @@ +from typing import Dict, Iterable, List, Any, Optional + +from sqlalchemy_mixins.inspection import InspectionMixin +from sqlalchemy_mixins.session import SessionMixin +from sqlalchemy_mixins.utils import classproperty +from sqlalchemy.orm import Query, QueryableAttribute + + +class ActiveRecordMixinAsync(InspectionMixin, SessionMixin): + + @classproperty + def settable_attributes(cls) -> List[str]: ... + + async def save_async(self) -> "ActiveRecordMixinAsync": ... + + @classmethod + async def create_async(cls, **kwargs: Any) -> "ActiveRecordMixinAsync": ... + + async def update_async(self, **kwargs: dict) -> "ActiveRecordMixinAsync": ... + + async def delete_async(self) -> None: ... + + @classmethod + async def destroy_async(cls, *ids: list) -> None: ... + + @classmethod + async def all_async(cls) -> List["ActiveRecordMixinAsync"]: ... + + @classmethod + async def first_async(cls) -> Optional["ActiveRecordMixinAsync"]: ... + + @classmethod + async def find_async(cls, id_: Any) -> Optional["ActiveRecordMixinAsync"]: ... + + @classmethod + async def find_or_fail_async(cls, id_: Any) -> "ActiveRecordMixinAsync": ... + + @classmethod + async def select_async(cls, + stmt:Optional[str] = None, + filters: Optional[Dict[str, Any]] = None, + sort_attrs: Optional[Iterable[str]] = None, + schema: Optional[dict] = None + ) -> "ActiveRecordMixinAsync": ... + + @classmethod + async def where_async(cls, **filters: Any) -> Query: ... + + @classmethod + async def sort_async(cls, *columns: str) -> Query: ... + + @classmethod + async def with_async(cls, schema: dict) -> Query: ... + + @classmethod + async def with_joined_async(cls, *paths: List[QueryableAttribute]) -> Query: ... + + @classmethod + async def with_subquery_async(cls, *paths: List[QueryableAttribute]) -> Query: ... From b19f1db60b6900808d9ab78318ffa107ad66166e Mon Sep 17 00:00:00 2001 From: Aurthur Musendame Date: Sun, 1 Sep 2024 17:40:08 +0200 Subject: [PATCH 5/6] added tests for the async active record with smart query --- .vscode/PythonImportHelper-v2-Completion.json | 155 ++++++++++++- requirements-dev.txt | 3 +- sqlalchemy_mixins/activerecordasync.py | 36 ++- .../tests/test_activerecordasync.py | 210 ++++++++++++++++++ 4 files changed, 400 insertions(+), 4 deletions(-) create mode 100644 sqlalchemy_mixins/tests/test_activerecordasync.py diff --git a/.vscode/PythonImportHelper-v2-Completion.json b/.vscode/PythonImportHelper-v2-Completion.json index 83f2f09..1344ccc 100644 --- a/.vscode/PythonImportHelper-v2-Completion.json +++ b/.vscode/PythonImportHelper-v2-Completion.json @@ -273,6 +273,14 @@ "detail": "sqlalchemy.ext.hybrid", "documentation": {} }, + { + "label": "hybrid_property", + "importPath": "sqlalchemy.ext.hybrid", + "description": "sqlalchemy.ext.hybrid", + "isExtraImport": true, + "detail": "sqlalchemy.ext.hybrid", + "documentation": {} + }, { "label": "hybrid_method", "importPath": "sqlalchemy.ext.hybrid", @@ -537,6 +545,30 @@ "detail": "sqlalchemy.orm", "documentation": {} }, + { + "label": "sessionmaker", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "selectinload", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, + { + "label": "relationship", + "importPath": "sqlalchemy.orm", + "description": "sqlalchemy.orm", + "isExtraImport": true, + "detail": "sqlalchemy.orm", + "documentation": {} + }, { "label": "Query", "importPath": "sqlalchemy.orm", @@ -889,6 +921,22 @@ "detail": "sqlalchemy_mixins", "documentation": {} }, + { + "label": "ActiveRecordMixinAsync", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, + { + "label": "SmartQueryMixin", + "importPath": "sqlalchemy_mixins", + "description": "sqlalchemy_mixins", + "isExtraImport": true, + "detail": "sqlalchemy_mixins", + "documentation": {} + }, { "label": "EagerLoadMixin", "importPath": "sqlalchemy_mixins", @@ -1060,6 +1108,47 @@ "detail": "sqlalchemy_mixins.activerecord", "documentation": {} }, + { + "label": "ModelNotFoundError", + "importPath": "sqlalchemy_mixins.activerecord", + "description": "sqlalchemy_mixins.activerecord", + "isExtraImport": true, + "detail": "sqlalchemy_mixins.activerecord", + "documentation": {} + }, + { + "label": "asyncio", + "kind": 6, + "isExtraImport": true, + "importPath": "asyncio", + "description": "asyncio", + "detail": "asyncio", + "documentation": {} + }, + { + "label": "create_async_engine", + "importPath": "sqlalchemy.ext.asyncio", + "description": "sqlalchemy.ext.asyncio", + "isExtraImport": true, + "detail": "sqlalchemy.ext.asyncio", + "documentation": {} + }, + { + "label": "AsyncSession", + "importPath": "sqlalchemy.ext.asyncio", + "description": "sqlalchemy.ext.asyncio", + "isExtraImport": true, + "detail": "sqlalchemy.ext.asyncio", + "documentation": {} + }, + { + "label": "declarative_base", + "importPath": "sqlalchemy.ext.declarative", + "description": "sqlalchemy.ext.declarative", + "isExtraImport": true, + "detail": "sqlalchemy.ext.declarative", + "documentation": {} + }, { "label": "SessionMixin", "importPath": "sqlalchemy_mixins.session", @@ -1076,6 +1165,14 @@ "detail": "sqlalchemy_mixins.session", "documentation": {} }, + { + "label": "InvalidRequestError", + "importPath": "sqlalchemy.exc", + "description": "sqlalchemy.exc", + "isExtraImport": true, + "detail": "sqlalchemy.exc", + "documentation": {} + }, { "label": "_AbstractLoad", "importPath": "sqlalchemy.orm.strategy_options", @@ -2363,6 +2460,60 @@ "detail": "sqlalchemy_mixins.tests.test_activerecord", "documentation": {} }, + { + "label": "AsyncBaseModel", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", + "description": "sqlalchemy_mixins.tests.test_activerecordasync", + "peekOfCode": "class AsyncBaseModel(Base, ActiveRecordMixinAsync, SmartQueryMixin):\n __abstract__ = True\nclass User(AsyncBaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = relationship('Post', backref='user', lazy=\"selectin\")\n posts_viewonly = relationship('Post', viewonly=True)\nclass Post(AsyncBaseModel):", + "detail": "sqlalchemy_mixins.tests.test_activerecordasync", + "documentation": {} + }, + { + "label": "User", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", + "description": "sqlalchemy_mixins.tests.test_activerecordasync", + "peekOfCode": "class User(AsyncBaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = relationship('Post', backref='user', lazy=\"selectin\")\n posts_viewonly = relationship('Post', viewonly=True)\nclass Post(AsyncBaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)", + "detail": "sqlalchemy_mixins.tests.test_activerecordasync", + "documentation": {} + }, + { + "label": "Post", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", + "description": "sqlalchemy_mixins.tests.test_activerecordasync", + "peekOfCode": "class Post(AsyncBaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n comments = relationship('Comment', backref='post', lazy=\"selectin\")\n @hybrid_property\n def public(self):\n return not self.archived", + "detail": "sqlalchemy_mixins.tests.test_activerecordasync", + "documentation": {} + }, + { + "label": "Comment", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", + "description": "sqlalchemy_mixins.tests.test_activerecordasync", + "peekOfCode": "class Comment(AsyncBaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n user = relationship('User', backref='comments', lazy=\"selectin\")\nclass TestAsyncActiveRecord(unittest.IsolatedAsyncioTestCase):\n async def asyncSetUp(self):", + "detail": "sqlalchemy_mixins.tests.test_activerecordasync", + "documentation": {} + }, + { + "label": "TestAsyncActiveRecord", + "kind": 6, + "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", + "description": "sqlalchemy_mixins.tests.test_activerecordasync", + "peekOfCode": "class TestAsyncActiveRecord(unittest.IsolatedAsyncioTestCase):\n async def asyncSetUp(self):\n self.engine = create_async_engine('sqlite+aiosqlite:///:memory:', echo=False)\n self.async_session = sessionmaker(self.engine, class_=AsyncSession, expire_on_commit=False)\n async with self.engine.begin() as conn:\n await conn.run_sync(Base.metadata.drop_all)\n await conn.run_sync(Base.metadata.create_all)\n AsyncBaseModel.set_session(self.async_session)\n async def asyncTearDown(self):\n await self.engine.dispose()", + "detail": "sqlalchemy_mixins.tests.test_activerecordasync", + "documentation": {} + }, + { + "label": "Base", + "kind": 5, + "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", + "description": "sqlalchemy_mixins.tests.test_activerecordasync", + "peekOfCode": "Base = declarative_base()\nclass AsyncBaseModel(Base, ActiveRecordMixinAsync, SmartQueryMixin):\n __abstract__ = True\nclass User(AsyncBaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = relationship('Post', backref='user', lazy=\"selectin\")\n posts_viewonly = relationship('Post', viewonly=True)", + "detail": "sqlalchemy_mixins.tests.test_activerecordasync", + "documentation": {} + }, { "label": "Base", "kind": 6, @@ -2944,7 +3095,7 @@ "kind": 6, "importPath": "sqlalchemy_mixins.activerecordasync", "description": "sqlalchemy_mixins.activerecordasync", - "peekOfCode": "class ActiveRecordMixinAsync(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classproperty\n def query(cls):\n \"\"\"\n Override the default query property to handle async session.\n \"\"\"\n if not hasattr(cls.session, \"query\"):\n return select(cls)\n return cls.session.query(cls)", + "peekOfCode": "class ActiveRecordMixinAsync(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classmethod\n def _get_primary_key_name(cls) -> str:\n \"\"\"\n Gets the primary key of the model.\n Note: This method can only be used if the model has a single primary key.\n :return: The name of the primary key.\n :raises InvalidRequestError: If the model does not have a primary key or \n has a composite primary key.", "detail": "sqlalchemy_mixins.activerecordasync", "documentation": {} }, @@ -2971,7 +3122,7 @@ "kind": 5, "importPath": "sqlalchemy_mixins.activerecordasync", "description": "sqlalchemy_mixins.activerecordasync", - "peekOfCode": "SmaryQuery._get_root_cls = lambda query: async_root_cls(query)\nclass ActiveRecordMixinAsync(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classproperty\n def query(cls):\n \"\"\"\n Override the default query property to handle async session.\n \"\"\"\n if not hasattr(cls.session, \"query\"):\n return select(cls)", + "peekOfCode": "SmaryQuery._get_root_cls = lambda query: async_root_cls(query)\nclass ActiveRecordMixinAsync(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classmethod\n def _get_primary_key_name(cls) -> str:\n \"\"\"\n Gets the primary key of the model.\n Note: This method can only be used if the model has a single primary key.\n :return: The name of the primary key.\n :raises InvalidRequestError: If the model does not have a primary key or ", "detail": "sqlalchemy_mixins.activerecordasync", "documentation": {} }, diff --git a/requirements-dev.txt b/requirements-dev.txt index 35d2ad5..efeb72b 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,4 +4,5 @@ coverage codeclimate-test-reporter tox mypy==1.1.1 -sqlalchemy[mypy] >= 2.0 \ No newline at end of file +sqlalchemy[mypy] >= 2.0 +aiosqlite==0.20.0 \ No newline at end of file diff --git a/sqlalchemy_mixins/activerecordasync.py b/sqlalchemy_mixins/activerecordasync.py index b01ef28..fad5858 100644 --- a/sqlalchemy_mixins/activerecordasync.py +++ b/sqlalchemy_mixins/activerecordasync.py @@ -1,5 +1,6 @@ from sqlalchemy import select from sqlalchemy.orm import Query +from sqlalchemy.exc import InvalidRequestError from .utils import classproperty from .session import SessionMixin from .inspection import InspectionMixin @@ -22,6 +23,39 @@ def async_root_cls(query: Query): class ActiveRecordMixinAsync(InspectionMixin, SessionMixin): __abstract__ = True + + @classmethod + def _get_primary_key_name(cls) -> str: + """ + Gets the primary key of the model. + + Note: This method can only be used if the model has a single primary key. + :return: The name of the primary key. + :raises InvalidRequestError: If the model does not have a primary key or + has a composite primary key. + """ + primary_keys = cls.__table__.primary_key.columns + if primary_keys is None: + raise InvalidRequestError( + f"Model {cls.__name__} does not have a primary key.") + if len(primary_keys) > 1: + raise InvalidRequestError( + f"Model {cls.__name__} has a composite primary key.") + + return primary_keys[0].name + + @classproperty + def settable_attributes(cls): + return cls.columns + cls.hybrid_properties + cls.settable_relations + + def fill(self, **kwargs): + for name in kwargs.keys(): + if name in self.settable_attributes: + setattr(self, name, kwargs[name]) + else: + raise KeyError("Attribute '{}' doesn't exist".format(name)) + + return self @classproperty def query(cls): @@ -105,7 +139,7 @@ async def destroy_async(cls, *ids): async def select_async(cls, stmt=None, filters=None, sort_attrs=None, schema=None): async with cls.session() as session: if stmt is None: - stmt = cls.smart_query( + stmt = SmaryQuery.smart_query(query=cls.query, filters=filters, sort_attrs=sort_attrs, schema=schema) return (await session.execute(stmt)).scalars() diff --git a/sqlalchemy_mixins/tests/test_activerecordasync.py b/sqlalchemy_mixins/tests/test_activerecordasync.py new file mode 100644 index 0000000..93a22e4 --- /dev/null +++ b/sqlalchemy_mixins/tests/test_activerecordasync.py @@ -0,0 +1,210 @@ +import unittest +import asyncio +import sqlalchemy as sa +from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession +from sqlalchemy.orm import sessionmaker +from sqlalchemy.orm import selectinload +from sqlalchemy.orm import relationship +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.ext.hybrid import hybrid_property + +from sqlalchemy_mixins.activerecord import ModelNotFoundError +from sqlalchemy_mixins import ActiveRecordMixinAsync, SmartQueryMixin + + +Base = declarative_base() + +class AsyncBaseModel(Base, ActiveRecordMixinAsync, SmartQueryMixin): + __abstract__ = True + +class User(AsyncBaseModel): + __tablename__ = 'user' + __repr_attrs__ = ['name'] + id = sa.Column(sa.Integer, primary_key=True) + name = sa.Column(sa.String) + posts = relationship('Post', backref='user', lazy="selectin") + posts_viewonly = relationship('Post', viewonly=True) + + +class Post(AsyncBaseModel): + __tablename__ = 'post' + id = sa.Column(sa.Integer, primary_key=True) + body = sa.Column(sa.String) + user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id')) + archived = sa.Column(sa.Boolean, default=False) + comments = relationship('Comment', backref='post', lazy="selectin") + + @hybrid_property + def public(self): + return not self.archived + + @public.setter + def public(self, public): + self.archived = not public + +class Comment(AsyncBaseModel): + __tablename__ = 'comment' + __repr_attrs__ = ['body'] + id = sa.Column(sa.Integer, primary_key=True) + body = sa.Column(sa.String) + user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id')) + post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id')) + user = relationship('User', backref='comments', lazy="selectin") + + +class TestAsyncActiveRecord(unittest.IsolatedAsyncioTestCase): + async def asyncSetUp(self): + self.engine = create_async_engine('sqlite+aiosqlite:///:memory:', echo=False) + self.async_session = sessionmaker(self.engine, class_=AsyncSession, expire_on_commit=False) + + async with self.engine.begin() as conn: + await conn.run_sync(Base.metadata.drop_all) + await conn.run_sync(Base.metadata.create_all) + + AsyncBaseModel.set_session(self.async_session) + + async def asyncTearDown(self): + await self.engine.dispose() + + async def test_settable_attributes(self): + self.assertEqual(set(User.settable_attributes), + {'id', 'name', 'posts', 'comments'}) + self.assertNotIn('posts_viewonly', set(User.settable_attributes)) + + self.assertEqual(set(Post.settable_attributes), + {'id', 'body', 'user_id', 'archived', + 'user', 'comments', 'public'}) + + self.assertEqual(set(Comment.settable_attributes), + {'id', 'body', 'post_id', 'user_id', + 'user', 'post'}) + + async def test_create_and_save_async(self): + u1 = User(name='Bill u1') + await u1.save_async() + + async with self.async_session() as session: + result = await session.execute(sa.select(User)) + saved = result.scalars().first() + self.assertEqual(u1.id, saved.id) + + p11 = Post(body='p11', user=u1, public=False) + await p11.save_async() + + async with self.async_session() as session: + result = await session.execute(sa.select(Post)) + saved_post = result.scalars().first() + self.assertEqual(p11.body, saved_post.body) + self.assertEqual(saved_post.archived, True) + + async def test_create_async(self): + u1 = await User.create_async(name='Bill u1') + + async with self.async_session() as session: + result = await session.execute(sa.select(User)) + saved = result.scalars().first() + self.assertEqual(u1.id, saved.id) + + p11 = await Post.create_async(body='p11', user=u1, public=False) + + async with self.async_session() as session: + result = await session.execute(sa.select(Post)) + saved_post = result.scalars().first() + self.assertEqual(p11.id, saved_post.id) + self.assertEqual(saved_post.archived, True) + + async def test_update_async(self): + u1 = await User.create_async(name='Bill', id=1) + u2 = await User.create_async(name='Bishop', id=2) + p11 = await Post.create_async(body='p11', user=u1, public=False, id=11) + + async with self.async_session() as session: + result = await session.execute( + sa.select(Post).options(selectinload(Post.user)) + .filter_by(id=11) + ) + post = result.scalars().first() + self.assertEqual(post.body, 'p11') + self.assertEqual(post.public, False) + self.assertEqual(post.user.id, u1.id) + + await p11.update_async(body='new body', public=True, user=u2) + + async with self.async_session() as session: + result = await session.execute( + sa.select(Post).options(selectinload(Post.user)) + .filter_by(id=11) + ) + updated_post = result.scalars().first() + self.assertEqual(updated_post.body, 'new body') + self.assertEqual(updated_post.public, True) + self.assertEqual(updated_post.user.id, u2.id) + + async def test_delete_async(self): + u1 = await User.create_async(name='Bill', id=1) + + async with self.async_session() as session: + result = await session.execute(sa.select(User).filter_by(id=1)) + saved = result.scalars().first() + self.assertEqual(saved.id, u1.id) + + await u1.delete_async() + + async with self.async_session() as session: + result = await session.execute(sa.select(User).filter_by(id=1)) + self.assertEqual(result.scalars().first(), None) + + async def test_destroy_async(self): + u1 = await User.create_async(name='Bill', id=1) + p11 = await Post.create_async(body='p11', user=u1, id=11) + p12 = await Post.create_async(body='p12', user=u1, id=12) + p13 = await Post.create_async(body='p13', user=u1, id=13) + + async with self.async_session() as session: + result = await session.execute(sa.select(Post)) + self.assertEqual(set([u.id for u in result.scalars().all()]), {p11.id, p12.id, p13.id}) + + await Post.destroy_async(11, 12) + + async with self.async_session() as session: + result = await session.execute(sa.select(Post)) + got = result.scalars().all() + self.assertEqual(len(got), 1) + self.assertEqual(got[0].id, p13.id) + + async def test_all_async(self): + u1 = await User.create_async(name='Bill', id=1) + u2 = await User.create_async(name='Bishop', id=2) + + users = await User.all_async() + self.assertEqual(set([u.id for u in users]), {u1.id, u2.id}) + + async def test_first_async(self): + u1 = await User.create_async(name='Bill', id=1) + u2 = await User.create_async(name='Bishop', id=2) + + first_user = await User.first_async() + self.assertEqual(first_user.id, u1.id) + + async def test_find_async(self): + u1 = await User.create_async(name='Bill', id=1) + u2 = await User.create_async(name='Bishop', id=2) + + found_user = await User.find_async(1) + self.assertEqual(found_user.id, u1.id) + + not_found_user = await User.find_async(3) + self.assertEqual(not_found_user, None) + + async def test_find_or_fail_async(self): + u1 = await User.create_async(name='Bill', id=1) + u2 = await User.create_async(name='Bishop', id=2) + + found_user = await User.find_or_fail_async(1) + self.assertEqual(found_user.id, u1.id) + + with self.assertRaises(ModelNotFoundError): + await User.find_or_fail_async(3) + +if __name__ == '__main__': + asyncio.run(unittest.main()) \ No newline at end of file From feda8bb23cbc9a62447606c9f735009be074f98d Mon Sep 17 00:00:00 2001 From: Aurthur Musendame Date: Sun, 1 Sep 2024 17:46:35 +0200 Subject: [PATCH 6/6] remove vscode --- .vscode/PythonImportHelper-v2-Completion.json | 3300 ----------------- 1 file changed, 3300 deletions(-) delete mode 100644 .vscode/PythonImportHelper-v2-Completion.json diff --git a/.vscode/PythonImportHelper-v2-Completion.json b/.vscode/PythonImportHelper-v2-Completion.json deleted file mode 100644 index 1344ccc..0000000 --- a/.vscode/PythonImportHelper-v2-Completion.json +++ /dev/null @@ -1,3300 +0,0 @@ -[ - { - "label": "print_function", - "importPath": "__future__", - "description": "__future__", - "isExtraImport": true, - "detail": "__future__", - "documentation": {} - }, - { - "label": "print_function", - "importPath": "__future__", - "description": "__future__", - "isExtraImport": true, - "detail": "__future__", - "documentation": {} - }, - { - "label": "print_function", - "importPath": "__future__", - "description": "__future__", - "isExtraImport": true, - "detail": "__future__", - "documentation": {} - }, - { - "label": "print_function", - "importPath": "__future__", - "description": "__future__", - "isExtraImport": true, - "detail": "__future__", - "documentation": {} - }, - { - "label": "print_function", - "importPath": "__future__", - "description": "__future__", - "isExtraImport": true, - "detail": "__future__", - "documentation": {} - }, - { - "label": "print_function", - "importPath": "__future__", - "description": "__future__", - "isExtraImport": true, - "detail": "__future__", - "documentation": {} - }, - { - "label": "print_function", - "importPath": "__future__", - "description": "__future__", - "isExtraImport": true, - "detail": "__future__", - "documentation": {} - }, - { - "label": "print_function", - "importPath": "__future__", - "description": "__future__", - "isExtraImport": true, - "detail": "__future__", - "documentation": {} - }, - { - "label": "os", - "kind": 6, - "isExtraImport": true, - "importPath": "os", - "description": "os", - "detail": "os", - "documentation": {} - }, - { - "label": "sqlalchemy", - "kind": 6, - "isExtraImport": true, - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "event", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "event", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "create_engine", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "select", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "inspect", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "inspect", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "asc", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "desc", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "inspect", - "importPath": "sqlalchemy", - "description": "sqlalchemy", - "isExtraImport": true, - "detail": "sqlalchemy", - "documentation": {} - }, - { - "label": "hybrid_property", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_method", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_property", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_property", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_property", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_property", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_method", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_property", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_property", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_method", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_property", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "hybrid_method", - "importPath": "sqlalchemy.ext.hybrid", - "description": "sqlalchemy.ext.hybrid", - "isExtraImport": true, - "detail": "sqlalchemy.ext.hybrid", - "documentation": {} - }, - { - "label": "scoped_session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "sessionmaker", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "scoped_session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "sessionmaker", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Query", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "scoped_session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "sessionmaker", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "scoped_session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "sessionmaker", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "scoped_session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "sessionmaker", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Query", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "scoped_session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "sessionmaker", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "scoped_session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "sessionmaker", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Query", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "declarative_base", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "sessionmaker", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "selectinload", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "relationship", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Query", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "sessionmaker", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Query", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Query", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "joinedload", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Load", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "subqueryload", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "RelationshipProperty", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "DeclarativeBase", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "scoped_session", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Query", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "aliased", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "contains_eager", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "RelationshipProperty", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "Mapper", - "importPath": "sqlalchemy.orm", - "description": "sqlalchemy.orm", - "isExtraImport": true, - "detail": "sqlalchemy.orm", - "documentation": {} - }, - { - "label": "ActiveRecordMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "ReprMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "ModelNotFoundError", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "AllFeaturesMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "TimestampsMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "EagerLoadMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "ReprMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "ReprMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "SerializeMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "SmartQueryMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "ReprMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "JOINED", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "smart_query", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "TimestampsMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "ActiveRecordMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "ActiveRecordMixinAsync", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "SmartQueryMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "EagerLoadMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "InspectionMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "ReprMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "SerializeMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "SmartQueryMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "smart_query", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "TimestampsMixin", - "importPath": "sqlalchemy_mixins", - "description": "sqlalchemy_mixins", - "isExtraImport": true, - "detail": "sqlalchemy_mixins", - "documentation": {} - }, - { - "label": "JOINED", - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "SUBQUERY", - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "eager_expr", - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "JOINED", - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "SUBQUERY", - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "eager_expr", - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "JOINED", - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "SUBQUERY", - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "datetime", - "kind": 6, - "isExtraImport": true, - "importPath": "datetime", - "description": "datetime", - "detail": "datetime", - "documentation": {} - }, - { - "label": "datetime", - "importPath": "datetime", - "description": "datetime", - "isExtraImport": true, - "detail": "datetime", - "documentation": {} - }, - { - "label": "datetime", - "importPath": "datetime", - "description": "datetime", - "isExtraImport": true, - "detail": "datetime", - "documentation": {} - }, - { - "label": "time", - "kind": 6, - "isExtraImport": true, - "importPath": "time", - "description": "time", - "detail": "time", - "documentation": {} - }, - { - "label": "unittest", - "kind": 6, - "isExtraImport": true, - "importPath": "unittest", - "description": "unittest", - "detail": "unittest", - "documentation": {} - }, - { - "label": "ModelNotFoundError", - "importPath": "sqlalchemy_mixins.activerecord", - "description": "sqlalchemy_mixins.activerecord", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.activerecord", - "documentation": {} - }, - { - "label": "ModelNotFoundError", - "importPath": "sqlalchemy_mixins.activerecord", - "description": "sqlalchemy_mixins.activerecord", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.activerecord", - "documentation": {} - }, - { - "label": "asyncio", - "kind": 6, - "isExtraImport": true, - "importPath": "asyncio", - "description": "asyncio", - "detail": "asyncio", - "documentation": {} - }, - { - "label": "create_async_engine", - "importPath": "sqlalchemy.ext.asyncio", - "description": "sqlalchemy.ext.asyncio", - "isExtraImport": true, - "detail": "sqlalchemy.ext.asyncio", - "documentation": {} - }, - { - "label": "AsyncSession", - "importPath": "sqlalchemy.ext.asyncio", - "description": "sqlalchemy.ext.asyncio", - "isExtraImport": true, - "detail": "sqlalchemy.ext.asyncio", - "documentation": {} - }, - { - "label": "declarative_base", - "importPath": "sqlalchemy.ext.declarative", - "description": "sqlalchemy.ext.declarative", - "isExtraImport": true, - "detail": "sqlalchemy.ext.declarative", - "documentation": {} - }, - { - "label": "SessionMixin", - "importPath": "sqlalchemy_mixins.session", - "description": "sqlalchemy_mixins.session", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.session", - "documentation": {} - }, - { - "label": "NoSessionError", - "importPath": "sqlalchemy_mixins.session", - "description": "sqlalchemy_mixins.session", - "isExtraImport": true, - "detail": "sqlalchemy_mixins.session", - "documentation": {} - }, - { - "label": "InvalidRequestError", - "importPath": "sqlalchemy.exc", - "description": "sqlalchemy.exc", - "isExtraImport": true, - "detail": "sqlalchemy.exc", - "documentation": {} - }, - { - "label": "_AbstractLoad", - "importPath": "sqlalchemy.orm.strategy_options", - "description": "sqlalchemy.orm.strategy_options", - "isExtraImport": true, - "detail": "sqlalchemy.orm.strategy_options", - "documentation": {} - }, - { - "label": "string_types", - "importPath": "six", - "description": "six", - "isExtraImport": true, - "detail": "six", - "documentation": {} - }, - { - "label": "Iterable", - "importPath": "collections.abc", - "description": "collections.abc", - "isExtraImport": true, - "detail": "collections.abc", - "documentation": {} - }, - { - "label": "abc", - "importPath": "collections", - "description": "collections", - "isExtraImport": true, - "detail": "collections", - "documentation": {} - }, - { - "label": "OrderedDict", - "importPath": "collections", - "description": "collections", - "isExtraImport": true, - "detail": "collections", - "documentation": {} - }, - { - "label": "AliasedClass", - "importPath": "sqlalchemy.orm.util", - "description": "sqlalchemy.orm.util", - "isExtraImport": true, - "detail": "sqlalchemy.orm.util", - "documentation": {} - }, - { - "label": "operators", - "importPath": "sqlalchemy.sql", - "description": "sqlalchemy.sql", - "isExtraImport": true, - "detail": "sqlalchemy.sql", - "documentation": {} - }, - { - "label": "extract", - "importPath": "sqlalchemy.sql", - "description": "sqlalchemy.sql", - "isExtraImport": true, - "detail": "sqlalchemy.sql", - "documentation": {} - }, - { - "label": "setup", - "importPath": "setuptools", - "description": "setuptools", - "isExtraImport": true, - "detail": "setuptools", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, ActiveRecordMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "class BaseModel(Base, ActiveRecordMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n age = sa.Column(sa.Integer)", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n age = sa.Column(sa.Integer)\n posts = sa.orm.relationship('Post', backref='user')\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n # user = backref from User.post\n @hybrid_property\n def public(self):\n return not self.archived", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "log", - "kind": 2, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "def log(msg):\n print('\\n{}\\n'.format(msg))\n#################### setup ######################\nclass Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, ActiveRecordMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "db_file", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "db_file = os.path.join(os.path.dirname(__file__), 'test.sqlite')\nengine = create_engine('sqlite:///{}'.format(db_file), echo=True)\n# autocommit=True - it's to make you see data in 3rd party DB view tool\nsession = scoped_session(sessionmaker(bind=engine))\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\n# setup base model: inject session so it can be accessed from model\nBaseModel.set_session(session)\n#################### CRUD demo ######################\n# ['id', 'body', 'user_id', 'archived', # normal columns", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "engine = create_engine('sqlite:///{}'.format(db_file), echo=True)\n# autocommit=True - it's to make you see data in 3rd party DB view tool\nsession = scoped_session(sessionmaker(bind=engine))\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\n# setup base model: inject session so it can be accessed from model\nBaseModel.set_session(session)\n#################### CRUD demo ######################\n# ['id', 'body', 'user_id', 'archived', # normal columns\n# 'user', 'comments', # relations", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "session", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\n# setup base model: inject session so it can be accessed from model\nBaseModel.set_session(session)\n#################### CRUD demo ######################\n# ['id', 'body', 'user_id', 'archived', # normal columns\n# 'user', 'comments', # relations\n# 'public'] # hybrid attributes\nprint(Post.settable_attributes)", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "user1", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "user1 = User()\n# equal to\n# user1.name = 'Billy'\n# user1.age = 1\n# session.flush()\nuser1.fill(name='Billy', age=1)\n# you can use kwargs as above or, in real-world apps, unpack dict as below\ndata = {'name': 'Bill', 'age': 21}\nuser1.fill(**data)\n# equal to", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "data", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "data = {'name': 'Bill', 'age': 21}\nuser1.fill(**data)\n# equal to\n# session.add(user1)\n# session.flush()\nuser1.save()\n#### 2. ActiveRecordMixin.create(): ####\n# equal to\n# user2 = User(name='Bob')\n# session.add(user2)", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "user2", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "user2 = User.create(name='Bob')\npost1 = Post.create(body='post1', user=user2)\n#### 3. ActiveRecordMixin.update(): ####\n# equal to\n# post1.fill(...)\n# post1.save()\npost1.update(body='new body', public=True, user=user1)\n#### 4. ActiveRecordMixin.delete(): ####\n# equal to\n# session.delete(post_to_be_deleted)", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "post1", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "post1 = Post.create(body='post1', user=user2)\n#### 3. ActiveRecordMixin.update(): ####\n# equal to\n# post1.fill(...)\n# post1.save()\npost1.update(body='new body', public=True, user=user1)\n#### 4. ActiveRecordMixin.delete(): ####\n# equal to\n# session.delete(post_to_be_deleted)\n# session.flush()", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "post_to_be_deleted", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "post_to_be_deleted = Post.create()\npost_to_be_deleted.delete()\n#### 5. ActiveRecordMixin.destroy() ####\n# equal to\n# session.delete(session.query(User).get(91))\n# session.delete(session.query(User).get(92))\n# session.flush()\n_ = User.create(id=91)\n__ = User.create(id=92)\nUser.destroy(91, 92)", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "_", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "_ = User.create(id=91)\n__ = User.create(id=92)\nUser.destroy(91, 92)\n#################### Query demo ######################\n#### 1. ActiveRecordMixin.all() ####\n# equal to\n# session.query(User).all()\nlog('all users: ' + str(User.all()))\n#### 2. ActiveRecordMixin.first() ####\n# equal to", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "__", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "__ = User.create(id=92)\nUser.destroy(91, 92)\n#################### Query demo ######################\n#### 1. ActiveRecordMixin.all() ####\n# equal to\n# session.query(User).all()\nlog('all users: ' + str(User.all()))\n#### 2. ActiveRecordMixin.first() ####\n# equal to\n# session.query(User).first()", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "user3", - "kind": 5, - "importPath": "examples.activerecord", - "description": "examples.activerecord", - "peekOfCode": "user3 = User.create(name='Bishop', id=3)\nlog('user with id=3: ' + str(User.find(3)))\n#### 4. ActiveRecordMixin.find_or_fail() ####\n# closest code on raw sqlalchemy will be\n# session.query(User).filter_by(id=).one()\n# but one() method throws common error without describing which ID was not\n# found, which is inconvenient: http://www.qopy.me/c5Csw1vWTCuOMKuP07J7iA\ntry:\n print(User.find_or_fail(123987))\nexcept ModelNotFoundError as e:", - "detail": "examples.activerecord", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "examples.all_features", - "description": "examples.all_features", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nclass BaseModel(Base, AllFeaturesMixin, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", - "detail": "examples.all_features", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "examples.all_features", - "description": "examples.all_features", - "peekOfCode": "class BaseModel(Base, AllFeaturesMixin, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'", - "detail": "examples.all_features", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "examples.all_features", - "description": "examples.all_features", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)", - "detail": "examples.all_features", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "examples.all_features", - "description": "examples.all_features", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n rating = sa.Column(sa.Integer)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n # we use this relation in smart_query, so it should be explicitly set\n # (not just a backref from User class)\n user = sa.orm.relationship('User', backref='posts') # but for eagerload", - "detail": "examples.all_features", - "documentation": {} - }, - { - "label": "Comment", - "kind": 6, - "importPath": "examples.all_features", - "description": "examples.all_features", - "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post = sa.orm.relationship('Post')\n user = sa.orm.relationship('User')\nengine = sa.create_engine('sqlite:///:memory:', echo=False)\nsession = scoped_session(sessionmaker(bind=engine))", - "detail": "examples.all_features", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "examples.all_features", - "description": "examples.all_features", - "peekOfCode": "engine = sa.create_engine('sqlite:///:memory:', echo=False)\nsession = scoped_session(sessionmaker(bind=engine))\nBase.metadata.create_all(engine)\nBaseModel.set_session(session)\nbob = User.create(name='Bob')\npost1 = Post.create(body='Post 1', user=bob, rating=3)\npost2 = Post.create(body='long-long-long-long-long body', rating=2,\n user=User.create(name='Bill'),\n comments=[Comment.create(body='cool!', user=bob)])\n# filter using operators like 'in' and 'contains' and relations like 'user'", - "detail": "examples.all_features", - "documentation": {} - }, - { - "label": "session", - "kind": 5, - "importPath": "examples.all_features", - "description": "examples.all_features", - "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nBase.metadata.create_all(engine)\nBaseModel.set_session(session)\nbob = User.create(name='Bob')\npost1 = Post.create(body='Post 1', user=bob, rating=3)\npost2 = Post.create(body='long-long-long-long-long body', rating=2,\n user=User.create(name='Bill'),\n comments=[Comment.create(body='cool!', user=bob)])\n# filter using operators like 'in' and 'contains' and relations like 'user'\n# will output this beauty: ", - "detail": "examples.all_features", - "documentation": {} - }, - { - "label": "bob", - "kind": 5, - "importPath": "examples.all_features", - "description": "examples.all_features", - "peekOfCode": "bob = User.create(name='Bob')\npost1 = Post.create(body='Post 1', user=bob, rating=3)\npost2 = Post.create(body='long-long-long-long-long body', rating=2,\n user=User.create(name='Bill'),\n comments=[Comment.create(body='cool!', user=bob)])\n# filter using operators like 'in' and 'contains' and relations like 'user'\n# will output this beauty: \nprint(Post.where(rating__in=[2, 3, 4], user___name__like='%Bi%').all())\n# joinedload post and user\nprint(Comment.with_joined(Comment.user, Comment.post).first())", - "detail": "examples.all_features", - "documentation": {} - }, - { - "label": "post1", - "kind": 5, - "importPath": "examples.all_features", - "description": "examples.all_features", - "peekOfCode": "post1 = Post.create(body='Post 1', user=bob, rating=3)\npost2 = Post.create(body='long-long-long-long-long body', rating=2,\n user=User.create(name='Bill'),\n comments=[Comment.create(body='cool!', user=bob)])\n# filter using operators like 'in' and 'contains' and relations like 'user'\n# will output this beauty: \nprint(Post.where(rating__in=[2, 3, 4], user___name__like='%Bi%').all())\n# joinedload post and user\nprint(Comment.with_joined(Comment.user, Comment.post).first())\n# subqueryload posts", - "detail": "examples.all_features", - "documentation": {} - }, - { - "label": "post2", - "kind": 5, - "importPath": "examples.all_features", - "description": "examples.all_features", - "peekOfCode": "post2 = Post.create(body='long-long-long-long-long body', rating=2,\n user=User.create(name='Bill'),\n comments=[Comment.create(body='cool!', user=bob)])\n# filter using operators like 'in' and 'contains' and relations like 'user'\n# will output this beauty: \nprint(Post.where(rating__in=[2, 3, 4], user___name__like='%Bi%').all())\n# joinedload post and user\nprint(Comment.with_joined(Comment.user, Comment.post).first())\n# subqueryload posts\nprint(User.with_subquery(User.posts).first())", - "detail": "examples.all_features", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, EagerLoadMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "class BaseModel(Base, EagerLoadMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name'] # we want to display name in repr string\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\n comments = sa.orm.relationship('Comment')\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')\nclass Comment(BaseModel):\n __tablename__ = 'comment'", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "Comment", - "kind": 6, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body', 'post'] # we want to display body and post\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n user = sa.orm.relationship('User')\n post = sa.orm.relationship('Post')", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "log", - "kind": 2, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "def log(msg):\n print('\\n{}\\n'.format(msg))\n#################### setup ######################\nclass Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, EagerLoadMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "reset_session", - "kind": 2, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "def reset_session():\n session = scoped_session(sessionmaker(bind=engine))\n BaseModel.set_session(session)\n return session\n#################### setup some data ######################\nsession = reset_session()\nu1 = User(name='Bill u1', id=1)\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "db_file", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "db_file = os.path.join(os.path.dirname(__file__), 'test.sqlite')\nengine = create_engine('sqlite:///{}'.format(db_file), echo=True)\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\n# sqlalchemy caches data in session, so to not use cache, we recreate session\ndef reset_session():\n session = scoped_session(sessionmaker(bind=engine))\n BaseModel.set_session(session)\n return session\n#################### setup some data ######################", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "engine = create_engine('sqlite:///{}'.format(db_file), echo=True)\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\n# sqlalchemy caches data in session, so to not use cache, we recreate session\ndef reset_session():\n session = scoped_session(sessionmaker(bind=engine))\n BaseModel.set_session(session)\n return session\n#################### setup some data ######################\nsession = reset_session()", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "session", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "session = reset_session()\nu1 = User(name='Bill u1', id=1)\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nsession.commit()\np11 = Post(\n id=11,", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "u1", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "u1 = User(name='Bill u1', id=1)\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nsession.commit()\np11 = Post(\n id=11,\n body='1234567890123',", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "u2", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "u2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nsession.commit()\np11 = Post(\n id=11,\n body='1234567890123',\n archived=True\n)\np11.user = u1", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "p11", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "p11 = Post(\n id=11,\n body='1234567890123',\n archived=True\n)\np11.user = u1\nsession.add(p11)\nsession.commit()\np12 = Post(\n id=12,", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "p11.user", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "p11.user = u1\nsession.add(p11)\nsession.commit()\np12 = Post(\n id=12,\n body='1234567890',\n user=u1\n)\nsession.add(p12)\nsession.commit()", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "p12", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "p12 = Post(\n id=12,\n body='1234567890',\n user=u1\n)\nsession.add(p12)\nsession.commit()\ncm11 = Comment(\n id=11,\n body='cm11 to p11',", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "cm11", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "cm11 = Comment(\n id=11,\n body='cm11 to p11',\n user=u1,\n post=p11,\n rating=1\n)\nsession.add(cm11)\nsession.commit()\ncm12 = Comment(", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "cm12", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "cm12 = Comment(\n id=12,\n body='cm12 to p12',\n user=u2,\n post=p12,\n rating=2\n)\nsession.add(cm12)\nsession.commit()\n#################### Demo ######################", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "comment", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "comment = Comment.with_joined(Comment.user, Comment.post).first()\n# SQL will be like\n\"\"\"\nSELECT comment.*, user_1.*, post_1.*\nFROM comment\nLEFT OUTER JOIN user AS user_1 ON user_1.id = comment.user_id\nLEFT OUTER JOIN post AS post_1 ON post_1.id = comment.post_id\nLEFT OUTER JOIN comment AS comment_1 ON post_1.id = comment_1.post_id\nLIMIT 1 OFFSET 1\n\"\"\"", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "user", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "user = comment.user\npost = comment.post\ncomments = post.comments\nlog('NO ADDITIONAL SQL. END')\n#### 0.2 subqueryload ####\nreset_session()\nusers = User.with_subquery(User.posts).all()\n# there will be 3 queries:\n## first. on users:\n\"\"\"", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "post", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "post = comment.post\ncomments = post.comments\nlog('NO ADDITIONAL SQL. END')\n#### 0.2 subqueryload ####\nreset_session()\nusers = User.with_subquery(User.posts).all()\n# there will be 3 queries:\n## first. on users:\n\"\"\"\nSELECT user.* FROM user", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "comments", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "comments = post.comments\nlog('NO ADDITIONAL SQL. END')\n#### 0.2 subqueryload ####\nreset_session()\nusers = User.with_subquery(User.posts).all()\n# there will be 3 queries:\n## first. on users:\n\"\"\"\nSELECT user.* FROM user\n\"\"\"", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "users", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "users = User.with_subquery(User.posts).all()\n# there will be 3 queries:\n## first. on users:\n\"\"\"\nSELECT user.* FROM user\n\"\"\"\n# second. on posts:\n\"\"\"\nSELECT post.* FROM (SELECT user.id AS user_id FROM user) AS anon_1\nJOIN post ON anon_1.user_id = post.user_id", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "posts", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "posts = users[0].posts\ncomments = posts[0].comments\nlog('NO ADDITIONAL SQL. END')\n#### 1. nested joinedload ####\n# for nested eagerload, you should use dict instead of lists|\n# also make sure you use class properties\nschema = {\n User.posts: {\n Post.comments: {\n Comment.user: JOINED", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "comments", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "comments = posts[0].comments\nlog('NO ADDITIONAL SQL. END')\n#### 1. nested joinedload ####\n# for nested eagerload, you should use dict instead of lists|\n# also make sure you use class properties\nschema = {\n User.posts: {\n Post.comments: {\n Comment.user: JOINED\n }", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "schema", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "schema = {\n User.posts: {\n Post.comments: {\n Comment.user: JOINED\n }\n }\n}\nsession = reset_session()\n###### 1.1 query-level: more flexible\nuser = session.query(User).options(*eager_expr(schema)).get(1)", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "session", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "session = reset_session()\n###### 1.1 query-level: more flexible\nuser = session.query(User).options(*eager_expr(schema)).get(1)\n# SQL will be like\n# note that we select user as parent entity and as post.comments.user\n# EagerLoadMixin will make table aliases for us\n\"\"\"\nSELECT user.*, user_1.*, comment_1.*, post_1.*\nFROM user\nLEFT OUTER JOIN post AS post_1 ON user.id = post_1.user_id", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "user", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "user = session.query(User).options(*eager_expr(schema)).get(1)\n# SQL will be like\n# note that we select user as parent entity and as post.comments.user\n# EagerLoadMixin will make table aliases for us\n\"\"\"\nSELECT user.*, user_1.*, comment_1.*, post_1.*\nFROM user\nLEFT OUTER JOIN post AS post_1 ON user.id = post_1.user_id\nLEFT OUTER JOIN comment AS comment_1 ON post_1.id = comment_1.post_id\nLEFT OUTER JOIN user AS user_1 ON user_1.id = comment_1.user_id", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "user", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "user = User.with_(schema).get(1)\n# now, to get relationships, NO additional query is needed\nlog('NO ADDITIONAL SQL. BEGIN')\npost = user.posts[0]\ncomment = post.comments[0]\ncomment_user = comment.user\nlog('NO ADDITIONAL SQL. END')\n#### 2. combination of joinedload and subqueryload ####\n# sometimes we want to load relations in separate query.\n# i.g. when we load posts, to each post we want to have user and all comments.", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "post", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "post = user.posts[0]\ncomment = post.comments[0]\ncomment_user = comment.user\nlog('NO ADDITIONAL SQL. END')\n#### 2. combination of joinedload and subqueryload ####\n# sometimes we want to load relations in separate query.\n# i.g. when we load posts, to each post we want to have user and all comments.\n# when we load many posts, join comments and comments to each user\nschema = {\n Post.comments: (SUBQUERY, { # load comments in separate query", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "comment", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "comment = post.comments[0]\ncomment_user = comment.user\nlog('NO ADDITIONAL SQL. END')\n#### 2. combination of joinedload and subqueryload ####\n# sometimes we want to load relations in separate query.\n# i.g. when we load posts, to each post we want to have user and all comments.\n# when we load many posts, join comments and comments to each user\nschema = {\n Post.comments: (SUBQUERY, { # load comments in separate query\n Comment.user: JOINED # but, in this separate query, join comments", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "comment_user", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "comment_user = comment.user\nlog('NO ADDITIONAL SQL. END')\n#### 2. combination of joinedload and subqueryload ####\n# sometimes we want to load relations in separate query.\n# i.g. when we load posts, to each post we want to have user and all comments.\n# when we load many posts, join comments and comments to each user\nschema = {\n Post.comments: (SUBQUERY, { # load comments in separate query\n Comment.user: JOINED # but, in this separate query, join comments\n })", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "schema", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "schema = {\n Post.comments: (SUBQUERY, { # load comments in separate query\n Comment.user: JOINED # but, in this separate query, join comments\n })\n}\n###### 2.1 query-level: more flexible\nreset_session()\nposts = session.query(Post).options(*eager_expr(schema)).all()\n###### 2.2 ORM-level: more convenient\nreset_session()", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "posts", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "posts = session.query(Post).options(*eager_expr(schema)).all()\n###### 2.2 ORM-level: more convenient\nreset_session()\nposts = Post.with_(schema).all()\n# there will be 2 queries:\n## first:\n\"\"\"\nSELECT post.* FROM post\n\"\"\"\n# second query loads comments with joined comment users", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "posts", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "posts = Post.with_(schema).all()\n# there will be 2 queries:\n## first:\n\"\"\"\nSELECT post.* FROM post\n\"\"\"\n# second query loads comments with joined comment users\n# it uses first query to get comments for specific posts\n\"\"\"\nSELECT comment.*, user_1.*", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "comments1", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "comments1 = posts[0].comments\ncomments2 = posts[1].comments\nuser1 = posts[0].comments[0].user\nuser2 = posts[1].comments[0].user\nlog('NO ADDITIONAL SQL. END')", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "comments2", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "comments2 = posts[1].comments\nuser1 = posts[0].comments[0].user\nuser2 = posts[1].comments[0].user\nlog('NO ADDITIONAL SQL. END')", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "user1", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "user1 = posts[0].comments[0].user\nuser2 = posts[1].comments[0].user\nlog('NO ADDITIONAL SQL. END')", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "user2", - "kind": 5, - "importPath": "examples.eagerload", - "description": "examples.eagerload", - "peekOfCode": "user2 = posts[1].comments[0].user\nlog('NO ADDITIONAL SQL. END')", - "detail": "examples.eagerload", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "examples.repr", - "description": "examples.repr", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = sa.create_engine('sqlite:///:memory:')\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'", - "detail": "examples.repr", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "examples.repr", - "description": "examples.repr", - "peekOfCode": "class BaseModel(Base, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')", - "detail": "examples.repr", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "examples.repr", - "description": "examples.repr", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\nclass Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n __repr_max_length__ = 25", - "detail": "examples.repr", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "examples.repr", - "description": "examples.repr", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n __repr_max_length__ = 25\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\nBase.metadata.create_all(engine)\nbob = User(name='Bob')\nsession.add(bob)", - "detail": "examples.repr", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "examples.repr", - "description": "examples.repr", - "peekOfCode": "engine = sa.create_engine('sqlite:///:memory:')\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "examples.repr", - "documentation": {} - }, - { - "label": "session", - "kind": 5, - "importPath": "examples.repr", - "description": "examples.repr", - "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", - "detail": "examples.repr", - "documentation": {} - }, - { - "label": "bob", - "kind": 5, - "importPath": "examples.repr", - "description": "examples.repr", - "peekOfCode": "bob = User(name='Bob')\nsession.add(bob)\nsession.flush()\npost1 = Post(body='Post 1', user=bob)\nsession.add(post1)\nsession.flush()\npost2 = Post(body='Post 2 long-long body', user=bob)\nsession.add(post2)\nsession.flush()\n# ", - "detail": "examples.repr", - "documentation": {} - }, - { - "label": "post1", - "kind": 5, - "importPath": "examples.repr", - "description": "examples.repr", - "peekOfCode": "post1 = Post(body='Post 1', user=bob)\nsession.add(post1)\nsession.flush()\npost2 = Post(body='Post 2 long-long body', user=bob)\nsession.add(post2)\nsession.flush()\n# \nprint(bob)\n# \nprint(post1)", - "detail": "examples.repr", - "documentation": {} - }, - { - "label": "post2", - "kind": 5, - "importPath": "examples.repr", - "description": "examples.repr", - "peekOfCode": "post2 = Post(body='Post 2 long-long body', user=bob)\nsession.add(post2)\nsession.flush()\n# \nprint(bob)\n# \nprint(post1)\n# \nprint(post2)", - "detail": "examples.repr", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "examples.serialize", - "description": "examples.serialize", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = sa.create_engine('sqlite:///:memory:')\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "examples.serialize", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "examples.serialize", - "description": "examples.serialize", - "peekOfCode": "class BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n password = sa.Column(sa.String)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\nclass Post(BaseModel):", - "detail": "examples.serialize", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "examples.serialize", - "description": "examples.serialize", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n password = sa.Column(sa.String)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)", - "detail": "examples.serialize", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "examples.serialize", - "description": "examples.serialize", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\nBase.metadata.create_all(engine)\nbob = User(name='Bob' , password = \"pass123\")\nsession.add(bob)\nsession.flush()\npost1 = Post(body='Post 1', user=bob)", - "detail": "examples.serialize", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "examples.serialize", - "description": "examples.serialize", - "peekOfCode": "engine = sa.create_engine('sqlite:///:memory:')\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n password = sa.Column(sa.String)\n name = sa.Column(sa.String)", - "detail": "examples.serialize", - "documentation": {} - }, - { - "label": "session", - "kind": 5, - "importPath": "examples.serialize", - "description": "examples.serialize", - "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n password = sa.Column(sa.String)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')", - "detail": "examples.serialize", - "documentation": {} - }, - { - "label": "bob", - "kind": 5, - "importPath": "examples.serialize", - "description": "examples.serialize", - "peekOfCode": "bob = User(name='Bob' , password = \"pass123\")\nsession.add(bob)\nsession.flush()\npost1 = Post(body='Post 1', user=bob)\nsession.add(post1)\nsession.flush()\npost2 = Post(body='Post 2', user=bob)\nsession.add(post2)\nsession.flush()\n# {'id': 1, 'name': 'Bob' , 'password' : 'pass123'}", - "detail": "examples.serialize", - "documentation": {} - }, - { - "label": "post1", - "kind": 5, - "importPath": "examples.serialize", - "description": "examples.serialize", - "peekOfCode": "post1 = Post(body='Post 1', user=bob)\nsession.add(post1)\nsession.flush()\npost2 = Post(body='Post 2', user=bob)\nsession.add(post2)\nsession.flush()\n# {'id': 1, 'name': 'Bob' , 'password' : 'pass123'}\nprint(bob.to_dict())\n# {'id': 1,\n# 'name': 'Bob',", - "detail": "examples.serialize", - "documentation": {} - }, - { - "label": "post2", - "kind": 5, - "importPath": "examples.serialize", - "description": "examples.serialize", - "peekOfCode": "post2 = Post(body='Post 2', user=bob)\nsession.add(post2)\nsession.flush()\n# {'id': 1, 'name': 'Bob' , 'password' : 'pass123'}\nprint(bob.to_dict())\n# {'id': 1,\n# 'name': 'Bob',\n# 'posts': [{'body': 'Post 1', 'id': 1, 'user_id': 1},\n# {'body': 'Post 2', 'id': 2, 'user_id': 1}]}\nprint(bob.to_dict(nested=True , exclude = ['password']))", - "detail": "examples.serialize", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, SmartQueryMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "class BaseModel(Base, SmartQueryMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n # to smart query relationship, it should be explicitly set,", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n # to smart query relationship, it should be explicitly set,\n # not to be a backref\n posts = sa.orm.relationship('Post')\n comments = sa.orm.relationship('Comment')\n # below relationship will just return query (without executing)", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n # to smart query relationship, it should be explicitly set,\n # not to be a backref\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "Comment", - "kind": 6, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n created_at = sa.Column(sa.DateTime)\n # to smart query relationship, it should be explicitly set,", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "log", - "kind": 2, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "def log(msg):\n print('\\n{}\\n'.format(msg))\n#################### setup ######################\nclass Base(DeclarativeBase):\n __abstract__ = True\n# we also use ReprMixin which is optional\nclass BaseModel(Base, SmartQueryMixin, ReprMixin):\n __abstract__ = True\n __repr__ = ReprMixin.__repr__\n pass", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "db_file", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "db_file = os.path.join(os.path.dirname(__file__), 'test.sqlite')\nengine = create_engine('sqlite:///{}'.format(db_file), echo=True)\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\nsession = scoped_session(sessionmaker(bind=engine))\nBaseModel.set_session(session)\n#################### setup some data ######################\nu1 = User(name='Bill u1')\nsession.add(u1)\nsession.commit()", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "engine = create_engine('sqlite:///{}'.format(db_file), echo=True)\nBase.metadata.drop_all(engine)\nBase.metadata.create_all(engine)\nsession = scoped_session(sessionmaker(bind=engine))\nBaseModel.set_session(session)\n#################### setup some data ######################\nu1 = User(name='Bill u1')\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "session", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nBaseModel.set_session(session)\n#################### setup some data ######################\nu1 = User(name='Bill u1')\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nu3 = User(name='Bishop u3')", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "u1", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "u1 = User(name='Bill u1')\nsession.add(u1)\nsession.commit()\nu2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nu3 = User(name='Bishop u3')\nsession.add(u3)\nsession.commit()\nsession.commit()", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "u2", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "u2 = User(name='Alex u2')\nsession.add(u2)\nsession.commit()\nu3 = User(name='Bishop u3')\nsession.add(u3)\nsession.commit()\nsession.commit()\np11 = Post(\n id=11,\n body='1234567890123',", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "u3", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "u3 = User(name='Bishop u3')\nsession.add(u3)\nsession.commit()\nsession.commit()\np11 = Post(\n id=11,\n body='1234567890123',\n archived=True,\n user=u1\n)", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "p11", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "p11 = Post(\n id=11,\n body='1234567890123',\n archived=True,\n user=u1\n)\nsession.add(p11)\nsession.commit()\np12 = Post(\n id=12,", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "p12", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "p12 = Post(\n id=12,\n body='1234567890',\n user=u1\n)\nsession.add(p12)\nsession.commit()\np21 = Post(\n id=21,\n body='p21',", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "p21", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "p21 = Post(\n id=21,\n body='p21',\n user=u2\n)\nsession.add(p21)\nsession.commit()\np22 = Post(\n id=22,\n body='p22',", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "p22", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "p22 = Post(\n id=22,\n body='p22',\n user=u2\n)\nsession.add(p22)\nsession.commit()\ncm11 = Comment(\n id=11,\n body='cm11',", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "cm11", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "cm11 = Comment(\n id=11,\n body='cm11',\n user=u1,\n post=p11,\n rating=1,\n created_at=datetime.datetime(2014, 1, 1)\n)\nsession.add(cm11)\nsession.commit()", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "cm12", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "cm12 = Comment(\n id=12,\n body='cm12',\n user=u2,\n post=p12,\n rating=2,\n created_at=datetime.datetime(2015, 10, 20)\n)\nsession.add(cm12)\nsession.commit()", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "cm21", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "cm21 = Comment(\n id=21,\n body='cm21',\n user=u1,\n post=p21,\n rating=1,\n created_at=datetime.datetime(2015, 11, 21)\n)\nsession.add(cm21)\nsession.commit()", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "cm22", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "cm22 = Comment(\n id=22,\n body='cm22',\n user=u3,\n post=p22,\n rating=3,\n created_at=datetime.datetime(2016, 11, 20)\n)\nsession.add(cm22)\nsession.commit()", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "cm_empty", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "cm_empty = Comment(\n id=29,\n # no body\n # no user\n # no post\n # no rating\n)\nsession.add(cm_empty)\nsession.commit()\n#################### Demo ######################", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "filters", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "filters = {'user': u1, 'public': True}\nlog(Post.where(**filters).all())\n##### 1.2 filter by hybrid_method 'is_commented_by_user' #####\n# low-level filter_expr()\nlog(session.query(Post).filter(\n *Post.filter_expr(is_commented_by_user=u1)).all())\n# high-level SmartQueryMixin.where() method\nlog(Post.where(is_commented_by_user=u1).all())\n##### 1.3 operators #####\n# rating == None", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "sort_attrs", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "sort_attrs = ['-rating', 'created_at']\nlog(Comment.sort(*sort_attrs))\n##### 2.1.3 hybrid properties\nlog(session.query(Post).order_by(*Post.order_expr('-public')).all())\nlog(Post.sort('-public').all())\n#### 2.2 sort() with auto-joined relations ####\n# sort by name of user ASC (user relation will be auto-joined), then by\n# created_at DESC\nlog(Comment.sort('user___name', '-created_at').all())\n# get comments on public posts first, then order by post user name", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "schema", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "schema = {\n Comment.post: {\n Post.user: JOINED\n }\n}\n##### 3.1 high-level smart_query() class method #####\nres = Comment.smart_query(\n filters={\n 'post___public': True,\n 'user__isnull': False", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "res", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "res = Comment.smart_query(\n filters={\n 'post___public': True,\n 'user__isnull': False\n },\n sort_attrs=['user___name', '-created_at'],\n schema=schema).all()\nlog(res) # cm12, cm21, cm22\n##### 3.2 more flexible smart_query() function #####\n##### 3.2.1. The same as 3.1", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "query", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "query = Comment.query # could be any query you want\nres = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False\n },\n sort_attrs=['user___name', '-created_at'],\n schema=schema).all()\nlog(res) # cm12, cm21, cm22\n##### 3.2.2. Real-life example with lazy='dynamic' relationship", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "res", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "res = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False\n },\n sort_attrs=['user___name', '-created_at'],\n schema=schema).all()\nlog(res) # cm12, cm21, cm22\n##### 3.2.2. Real-life example with lazy='dynamic' relationship\n# let's imagine we want to display some user relations", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "user", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "user = session.query(User).first()\n# and we have initial query for his/her comments\n# (see User.comments_ relationship)\nquery = user.comments_\n# now we just smartly apply all filters, sorts and eagerload. Perfect!\nres = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False\n },", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "query", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "query = user.comments_\n# now we just smartly apply all filters, sorts and eagerload. Perfect!\nres = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False\n },\n sort_attrs=['user___name', '-created_at'],\n schema=schema).all()\nlog(res) # cm21", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "res", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "res = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False\n },\n sort_attrs=['user___name', '-created_at'],\n schema=schema).all()\nlog(res) # cm21\n##### 3.2.3 Logical operators and arbitrary expressions in filters\n# If we want to use OR, NOT or other logical operators in our queries", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "res", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "res = Post.smart_query(filters={\n sa.or_: {'archived': True, 'is_commented_by_user': u3}\n})\nlog(res) # p11, p22\n# Some logic cannot be expressed without using a list instead, e.g.\n# (X OR Y) AND (W OR Z)\n# E.g. (somewhat contrived example):\n# (non-archived OR has comments) AND \n# (user_name like 'B%' or user_name like 'C%')\nres = Post.smart_query(filters=[", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "res", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "res = Post.smart_query(filters=[\n {sa.or_: {'archived': False, 'comments__isnull': False }},\n {sa.or_: [\n {'user___name__like': 'B%'},\n {'user___name__like': 'C%'}\n ]}\n])\n# !! NOTE !! This cannot be used with the where method, e.g. \n# Post.where(**{sa.or: {...}})\n# TypeError!! (only strings are allowed as keyword arguments)", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "res", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "res = Comment.where(post___public=True, post___user___name__like='Bi%').all()\nlog(res)\n# no additional query needed: we used 'post' and 'post__user'\n# relations in smart_query()\nlog(res[0].post)\nlog(res[0].post.user)\n# we didn't use post___comments in filters, so additional query is needed\nlog(res[0].post.comments)\n##### 3.3.2 sort()\nres = Comment.sort('-post___public', 'post___user___name').all()", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "res", - "kind": 5, - "importPath": "examples.smartquery", - "description": "examples.smartquery", - "peekOfCode": "res = Comment.sort('-post___public', 'post___user___name').all()\nlog(res)\n# no additional query needed: we used 'post' and 'post__user'\n# relations in smart_query()\nlog(res[0].post)\nlog(res[0].post.user)\n# we didn't use post___comments in filters, so additional query is needed\nlog(res[0].post.comments)", - "detail": "examples.smartquery", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "examples.timestamp", - "description": "examples.timestamp", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = sa.create_engine(\"sqlite:///:memory:\")\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n \"\"\"User Model to example.\"\"\"\n __tablename__ = \"users\"", - "detail": "examples.timestamp", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "examples.timestamp", - "description": "examples.timestamp", - "peekOfCode": "class BaseModel(Base, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n \"\"\"User Model to example.\"\"\"\n __tablename__ = \"users\"\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nBase.metadata.create_all(engine)\nprint(\"Current time: \", datetime.utcnow())", - "detail": "examples.timestamp", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "examples.timestamp", - "description": "examples.timestamp", - "peekOfCode": "class User(BaseModel):\n \"\"\"User Model to example.\"\"\"\n __tablename__ = \"users\"\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nBase.metadata.create_all(engine)\nprint(\"Current time: \", datetime.utcnow())\n# Current time: 2019-03-04 03:53:53.605602\nbob = User(name=\"Bob\")\nsession.add(bob)", - "detail": "examples.timestamp", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "examples.timestamp", - "description": "examples.timestamp", - "peekOfCode": "engine = sa.create_engine(\"sqlite:///:memory:\")\nsession = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n \"\"\"User Model to example.\"\"\"\n __tablename__ = \"users\"\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", - "detail": "examples.timestamp", - "documentation": {} - }, - { - "label": "session", - "kind": 5, - "importPath": "examples.timestamp", - "description": "examples.timestamp", - "peekOfCode": "session = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, TimestampsMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n \"\"\"User Model to example.\"\"\"\n __tablename__ = \"users\"\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nBase.metadata.create_all(engine)", - "detail": "examples.timestamp", - "documentation": {} - }, - { - "label": "bob", - "kind": 5, - "importPath": "examples.timestamp", - "description": "examples.timestamp", - "peekOfCode": "bob = User(name=\"Bob\")\nsession.add(bob)\nsession.flush()\nprint(\"Created Bob: \", bob.created_at)\n# Created Bob: 2019-03-04 03:53:53.606765\nprint(\"Pre-update Bob: \", bob.updated_at)\n# Pre-update Bob: 2019-03-04 03:53:53.606769\ntime.sleep(2)\nbob.name = \"Robert\"\nsession.commit()", - "detail": "examples.timestamp", - "documentation": {} - }, - { - "label": "bob.name", - "kind": 5, - "importPath": "examples.timestamp", - "description": "examples.timestamp", - "peekOfCode": "bob.name = \"Robert\"\nsession.commit()\nprint(\"Updated Bob: \", bob.updated_at)\n# Updated Bob: 2019-03-04 03:53:55.613044", - "detail": "examples.timestamp", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nAlternativeBase = declarative_base()\nengine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ActiveRecordMixin):\n __abstract__ = True\n pass\nclass BaseModelAlternative(AlternativeBase, ActiveRecordMixin):", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "class BaseModel(Base, ActiveRecordMixin):\n __abstract__ = True\n pass\nclass BaseModelAlternative(AlternativeBase, ActiveRecordMixin):\n __abstract__ = True\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "BaseModelAlternative", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "class BaseModelAlternative(AlternativeBase, ActiveRecordMixin):\n __abstract__ = True\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\n posts_viewonly = sa.orm.relationship('Post', viewonly=True)\nclass UserAlternative(BaseModelAlternative):", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\n posts_viewonly = sa.orm.relationship('Post', viewonly=True)\nclass UserAlternative(BaseModelAlternative):\n __tablename__ = 'user_alt'\n __repr_attrs__ = ['name']", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "UserAlternative", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "class UserAlternative(BaseModelAlternative):\n __tablename__ = 'user_alt'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n # user = backref from User.post\n comments = sa.orm.relationship('Comment', backref='post')\n @hybrid_property\n def public(self):", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "Comment", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n user = sa.orm.relationship('User', backref='comments')\n # post = backref from Post.comments\nclass TestActiveRecord(unittest.TestCase):", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "TestActiveRecord", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "class TestActiveRecord(unittest.TestCase):\n def setUp(self):\n sess.rollback()\n BaseModel.set_session(None)\n Base.metadata.drop_all(engine)\n Base.metadata.create_all(engine)\n BaseModel.set_session(sess)\n def test_settable_attributes(self):\n self.assertEqual(set(User.settable_attributes),\n {'id', 'name', # normal columns", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "TestActiveRecordAlternative", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "class TestActiveRecordAlternative(unittest.TestCase):\n def setUp(self):\n sess.rollback()\n BaseModelAlternative.set_session(None)\n AlternativeBase.metadata.drop_all(engine)\n AlternativeBase.metadata.create_all(engine)\n BaseModelAlternative.set_session(sess)\n def test_create(self):\n u1 = UserAlternative.create(name='Bill u1')\n self.assertEqual(u1, sess.query(UserAlternative).first())", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "AlternativeBase", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "AlternativeBase = declarative_base()\nengine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ActiveRecordMixin):\n __abstract__ = True\n pass\nclass BaseModelAlternative(AlternativeBase, ActiveRecordMixin):\n __abstract__ = True\nclass User(BaseModel):", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ActiveRecordMixin):\n __abstract__ = True\n pass\nclass BaseModelAlternative(AlternativeBase, ActiveRecordMixin):\n __abstract__ = True\nclass User(BaseModel):\n __tablename__ = 'user'", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "sess", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_activerecord", - "description": "sqlalchemy_mixins.tests.test_activerecord", - "peekOfCode": "sess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ActiveRecordMixin):\n __abstract__ = True\n pass\nclass BaseModelAlternative(AlternativeBase, ActiveRecordMixin):\n __abstract__ = True\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']", - "detail": "sqlalchemy_mixins.tests.test_activerecord", - "documentation": {} - }, - { - "label": "AsyncBaseModel", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", - "description": "sqlalchemy_mixins.tests.test_activerecordasync", - "peekOfCode": "class AsyncBaseModel(Base, ActiveRecordMixinAsync, SmartQueryMixin):\n __abstract__ = True\nclass User(AsyncBaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = relationship('Post', backref='user', lazy=\"selectin\")\n posts_viewonly = relationship('Post', viewonly=True)\nclass Post(AsyncBaseModel):", - "detail": "sqlalchemy_mixins.tests.test_activerecordasync", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", - "description": "sqlalchemy_mixins.tests.test_activerecordasync", - "peekOfCode": "class User(AsyncBaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = relationship('Post', backref='user', lazy=\"selectin\")\n posts_viewonly = relationship('Post', viewonly=True)\nclass Post(AsyncBaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "sqlalchemy_mixins.tests.test_activerecordasync", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", - "description": "sqlalchemy_mixins.tests.test_activerecordasync", - "peekOfCode": "class Post(AsyncBaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n comments = relationship('Comment', backref='post', lazy=\"selectin\")\n @hybrid_property\n def public(self):\n return not self.archived", - "detail": "sqlalchemy_mixins.tests.test_activerecordasync", - "documentation": {} - }, - { - "label": "Comment", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", - "description": "sqlalchemy_mixins.tests.test_activerecordasync", - "peekOfCode": "class Comment(AsyncBaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n user = relationship('User', backref='comments', lazy=\"selectin\")\nclass TestAsyncActiveRecord(unittest.IsolatedAsyncioTestCase):\n async def asyncSetUp(self):", - "detail": "sqlalchemy_mixins.tests.test_activerecordasync", - "documentation": {} - }, - { - "label": "TestAsyncActiveRecord", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", - "description": "sqlalchemy_mixins.tests.test_activerecordasync", - "peekOfCode": "class TestAsyncActiveRecord(unittest.IsolatedAsyncioTestCase):\n async def asyncSetUp(self):\n self.engine = create_async_engine('sqlite+aiosqlite:///:memory:', echo=False)\n self.async_session = sessionmaker(self.engine, class_=AsyncSession, expire_on_commit=False)\n async with self.engine.begin() as conn:\n await conn.run_sync(Base.metadata.drop_all)\n await conn.run_sync(Base.metadata.create_all)\n AsyncBaseModel.set_session(self.async_session)\n async def asyncTearDown(self):\n await self.engine.dispose()", - "detail": "sqlalchemy_mixins.tests.test_activerecordasync", - "documentation": {} - }, - { - "label": "Base", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_activerecordasync", - "description": "sqlalchemy_mixins.tests.test_activerecordasync", - "peekOfCode": "Base = declarative_base()\nclass AsyncBaseModel(Base, ActiveRecordMixinAsync, SmartQueryMixin):\n __abstract__ = True\nclass User(AsyncBaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = relationship('Post', backref='user', lazy=\"selectin\")\n posts_viewonly = relationship('Post', viewonly=True)", - "detail": "sqlalchemy_mixins.tests.test_activerecordasync", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, EagerLoadMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class BaseModel(Base, EagerLoadMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\nclass Post(BaseModel):", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')\nclass Comment(BaseModel):\n __tablename__ = 'comment'", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "Comment", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n user = sa.orm.relationship('User')\n post = sa.orm.relationship('Post')", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "TestEagerLoad", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class TestEagerLoad(unittest.TestCase):\n def setUp(self):\n Base.metadata.drop_all(engine)\n Base.metadata.create_all(engine)\n BaseModel.set_session(sess)\n u1 = User(name='Bill u1')\n sess.add(u1)\n sess.commit()\n u2 = User(name='Alex u2')\n sess.add(u2)", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "TestNoEagerLoad", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class TestNoEagerLoad(TestEagerLoad):\n def test_no_eagerload(self):\n self.assertEqual(self.query_count, 0)\n post = Post.query.get(11)\n self.assertEqual(self.query_count, 1)\n # to get relationship, ADDITIONAL query is needed\n comment = post.comments[0]\n self.assertEqual(self.query_count, 2)\n # to get relationship, ADDITIONAL query is needed\n _ = comment.user", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "TestEagerExpr", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class TestEagerExpr(TestEagerLoad):\n \"\"\"test of low-level eager_expr function\"\"\"\n def _test_ok(self, schema):\n self.assertEqual(self.query_count, 0)\n user = sess.query(User).options(*eager_expr(schema)).get(1)\n self.assertEqual(self.query_count, 2)\n # now, to get relationships, NO additional query is needed\n post = user.posts[0]\n _ = post.comments[0]\n self.assertEqual(self.query_count, 2)", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "TestOrmWithJoinedClassProperties", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class TestOrmWithJoinedClassProperties(TestEagerLoad):\n def _test(self):\n self.assertEqual(self.query_count, 0)\n post = Post.with_joined(Post.comments, Post.user).get(11)\n self.assertEqual(self.query_count, 1)\n # now, to get relationship, NO additional query is needed\n _ = post.comments[0]\n _ = post.user\n self.assertEqual(self.query_count, 1)\nclass TestOrmWithSubquery(TestEagerLoad):", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "TestOrmWithSubquery", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class TestOrmWithSubquery(TestEagerLoad):\n def test(self):\n self.assertEqual(self.query_count, 0)\n # take post with user and comments (including comment author)\n # NOTE: you can separate relations with dot.\n # Its due to SQLAlchemy: https://goo.gl/yM2DLX\n post = Post.with_subquery(Post.user, Post.comments).get(11)\n # 3 queries were executed:\n # 1 - on posts\n # 2 - on user (eagerload subquery)", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "TestOrmWithSubqueryClassProperties", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class TestOrmWithSubqueryClassProperties(TestEagerLoad):\n def test(self):\n self.assertEqual(self.query_count, 0)\n post = Post.with_subquery(Post.comments, Post.user).get(11)\n # 3 queries were executed:\n # 1 - on posts\n # 2 - on comments (eagerload subquery)\n # 3 - on user (eagerload subquery)\n self.assertEqual(self.query_count, 3)\n # now, to get relationship, NO additional query is needed", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "TestOrmWithDict", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "class TestOrmWithDict(TestEagerLoad):\n def _test_joinedload(self, schema):\n self.assertEqual(self.query_count, 0)\n post = Post.with_(schema).get(11)\n self.assertEqual(self.query_count, 1)\n # now, to get relationship, NO additional query is needed\n _ = post.comments[0]\n self.assertEqual(self.query_count, 1)\n def test_joinedload_class_properties(self):\n schema = {Post.comments: JOINED}", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, EagerLoadMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "sess", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_eagerload", - "description": "sqlalchemy_mixins.tests.test_eagerload", - "peekOfCode": "sess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, EagerLoadMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", - "detail": "sqlalchemy_mixins.tests.test_eagerload", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_inspection", - "description": "sqlalchemy_mixins.tests.test_inspection", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = create_engine('sqlite:///:memory:', echo=False)\nclass BaseModel(Base, InspectionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n first_name = sa.Column(sa.String)", - "detail": "sqlalchemy_mixins.tests.test_inspection", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_inspection", - "description": "sqlalchemy_mixins.tests.test_inspection", - "peekOfCode": "class BaseModel(Base, InspectionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n first_name = sa.Column(sa.String)\n last_name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\n posts_viewonly = sa.orm.relationship('Post', viewonly=True)", - "detail": "sqlalchemy_mixins.tests.test_inspection", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_inspection", - "description": "sqlalchemy_mixins.tests.test_inspection", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n first_name = sa.Column(sa.String)\n last_name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')\n posts_viewonly = sa.orm.relationship('Post', viewonly=True)\n @hybrid_property\n def surname(self):\n return self.last_name", - "detail": "sqlalchemy_mixins.tests.test_inspection", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_inspection", - "description": "sqlalchemy_mixins.tests.test_inspection", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\nclass Parent(BaseModel):\n __tablename__ = 'parent'\n id = sa.Column(sa.Integer, primary_key=True)\nclass Child(Parent):\n some_prop = sa.Column(sa.String)", - "detail": "sqlalchemy_mixins.tests.test_inspection", - "documentation": {} - }, - { - "label": "Parent", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_inspection", - "description": "sqlalchemy_mixins.tests.test_inspection", - "peekOfCode": "class Parent(BaseModel):\n __tablename__ = 'parent'\n id = sa.Column(sa.Integer, primary_key=True)\nclass Child(Parent):\n some_prop = sa.Column(sa.String)\nclass ModelWithTwoPks(BaseModel):\n __tablename__ = 'two_pks'\n pk1 = sa.Column(sa.Integer, primary_key=True)\n pk2 = sa.Column(sa.Integer, primary_key=True)\nclass TestSessionMixin(unittest.TestCase):", - "detail": "sqlalchemy_mixins.tests.test_inspection", - "documentation": {} - }, - { - "label": "Child", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_inspection", - "description": "sqlalchemy_mixins.tests.test_inspection", - "peekOfCode": "class Child(Parent):\n some_prop = sa.Column(sa.String)\nclass ModelWithTwoPks(BaseModel):\n __tablename__ = 'two_pks'\n pk1 = sa.Column(sa.Integer, primary_key=True)\n pk2 = sa.Column(sa.Integer, primary_key=True)\nclass TestSessionMixin(unittest.TestCase):\n def setUp(self):\n Base.metadata.create_all(engine)\n def test_columns(self):", - "detail": "sqlalchemy_mixins.tests.test_inspection", - "documentation": {} - }, - { - "label": "ModelWithTwoPks", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_inspection", - "description": "sqlalchemy_mixins.tests.test_inspection", - "peekOfCode": "class ModelWithTwoPks(BaseModel):\n __tablename__ = 'two_pks'\n pk1 = sa.Column(sa.Integer, primary_key=True)\n pk2 = sa.Column(sa.Integer, primary_key=True)\nclass TestSessionMixin(unittest.TestCase):\n def setUp(self):\n Base.metadata.create_all(engine)\n def test_columns(self):\n self.assertEqual(set(User.columns), {'id', 'first_name', 'last_name'})\n self.assertEqual(set(Post.columns), {'id', 'body', 'user_id'})", - "detail": "sqlalchemy_mixins.tests.test_inspection", - "documentation": {} - }, - { - "label": "TestSessionMixin", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_inspection", - "description": "sqlalchemy_mixins.tests.test_inspection", - "peekOfCode": "class TestSessionMixin(unittest.TestCase):\n def setUp(self):\n Base.metadata.create_all(engine)\n def test_columns(self):\n self.assertEqual(set(User.columns), {'id', 'first_name', 'last_name'})\n self.assertEqual(set(Post.columns), {'id', 'body', 'user_id'})\n def test_nested_columns(self):\n self.assertEqual(set(Parent.columns), {'id'})\n self.assertEqual(set(Child.columns), {'id', 'some_prop'})\n def test_primary_keys(self):", - "detail": "sqlalchemy_mixins.tests.test_inspection", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_inspection", - "description": "sqlalchemy_mixins.tests.test_inspection", - "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nclass BaseModel(Base, InspectionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n first_name = sa.Column(sa.String)\n last_name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post', backref='user')", - "detail": "sqlalchemy_mixins.tests.test_inspection", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_repr", - "description": "sqlalchemy_mixins.tests.test_repr", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n # !!! IMPORTANT !!!\n # include below string to make mixin work\n __repr__ = ReprMixin.__repr__", - "detail": "sqlalchemy_mixins.tests.test_repr", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_repr", - "description": "sqlalchemy_mixins.tests.test_repr", - "peekOfCode": "class BaseModel(Base, ReprMixin):\n __abstract__ = True\n # !!! IMPORTANT !!!\n # include below string to make mixin work\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "sqlalchemy_mixins.tests.test_repr", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_repr", - "description": "sqlalchemy_mixins.tests.test_repr", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\nclass Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "sqlalchemy_mixins.tests.test_repr", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_repr", - "description": "sqlalchemy_mixins.tests.test_repr", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n __repr_attrs__ = ['body', 'user']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')\nclass Comment(BaseModel):", - "detail": "sqlalchemy_mixins.tests.test_repr", - "documentation": {} - }, - { - "label": "Comment", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_repr", - "description": "sqlalchemy_mixins.tests.test_repr", - "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body', 'post', 'user']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n user = sa.orm.relationship('User')\n post = sa.orm.relationship('Post')", - "detail": "sqlalchemy_mixins.tests.test_repr", - "documentation": {} - }, - { - "label": "TestEagerLoad", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_repr", - "description": "sqlalchemy_mixins.tests.test_repr", - "peekOfCode": "class TestEagerLoad(unittest.TestCase):\n def test(self):\n Base.metadata.drop_all(engine)\n Base.metadata.create_all(engine)\n u1 = User(name='Bill u1', id=1)\n sess.add(u1)\n sess.commit()\n u2 = User(name='Alex u2', id=2)\n sess.add(u2)\n sess.commit()", - "detail": "sqlalchemy_mixins.tests.test_repr", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_repr", - "description": "sqlalchemy_mixins.tests.test_repr", - "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n # !!! IMPORTANT !!!\n # include below string to make mixin work\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):", - "detail": "sqlalchemy_mixins.tests.test_repr", - "documentation": {} - }, - { - "label": "sess", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_repr", - "description": "sqlalchemy_mixins.tests.test_repr", - "peekOfCode": "sess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, ReprMixin):\n __abstract__ = True\n # !!! IMPORTANT !!!\n # include below string to make mixin work\n __repr__ = ReprMixin.__repr__\n pass\nclass User(BaseModel):\n __tablename__ = 'user'", - "detail": "sqlalchemy_mixins.tests.test_repr", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_serialize", - "description": "sqlalchemy_mixins.tests.test_serialize", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nclass BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')", - "detail": "sqlalchemy_mixins.tests.test_serialize", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_serialize", - "description": "sqlalchemy_mixins.tests.test_serialize", - "peekOfCode": "class BaseModel(Base, SerializeMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\n password = sa.Column(sa.String)\n @hybrid_property", - "detail": "sqlalchemy_mixins.tests.test_serialize", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_serialize", - "description": "sqlalchemy_mixins.tests.test_serialize", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n posts = sa.orm.relationship('Post')\n password = sa.Column(sa.String)\n @hybrid_property\n def posts_count(self):\n return len(self.posts)\nclass Post(BaseModel):", - "detail": "sqlalchemy_mixins.tests.test_serialize", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_serialize", - "description": "sqlalchemy_mixins.tests.test_serialize", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')\nclass Comment(BaseModel):\n __tablename__ = 'comment'", - "detail": "sqlalchemy_mixins.tests.test_serialize", - "documentation": {} - }, - { - "label": "Comment", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_serialize", - "description": "sqlalchemy_mixins.tests.test_serialize", - "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n user = sa.orm.relationship('User')\n post = sa.orm.relationship('Post')\nclass TestSerialize(unittest.TestCase):", - "detail": "sqlalchemy_mixins.tests.test_serialize", - "documentation": {} - }, - { - "label": "TestSerialize", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_serialize", - "description": "sqlalchemy_mixins.tests.test_serialize", - "peekOfCode": "class TestSerialize(unittest.TestCase):\n @classmethod\n def setUpClass(cls):\n cls.engine = create_engine('sqlite:///:memory:', echo=False)\n def setUp(self):\n self.session = Session(self.engine)\n Base.metadata.create_all(self.engine)\n user_1 = User(name='Bill u1', id=1 , password = 'pass1')\n self.session.add(user_1)\n self.session.commit()", - "detail": "sqlalchemy_mixins.tests.test_serialize", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_session", - "description": "sqlalchemy_mixins.tests.test_session", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = create_engine('sqlite:///:memory:', echo=False)\nsession = Session(engine)\nclass BaseModel(Base, SessionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "sqlalchemy_mixins.tests.test_session", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_session", - "description": "sqlalchemy_mixins.tests.test_session", - "peekOfCode": "class BaseModel(Base, SessionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "sqlalchemy_mixins.tests.test_session", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_session", - "description": "sqlalchemy_mixins.tests.test_session", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\nclass TestSessionMixin(unittest.TestCase):\n def setUp(self):", - "detail": "sqlalchemy_mixins.tests.test_session", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_session", - "description": "sqlalchemy_mixins.tests.test_session", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\nclass TestSessionMixin(unittest.TestCase):\n def setUp(self):\n Base.metadata.create_all(engine)\n def test_set_session(self):\n # before setting session, error is raised\n with self.assertRaises(NoSessionError):", - "detail": "sqlalchemy_mixins.tests.test_session", - "documentation": {} - }, - { - "label": "TestSessionMixin", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_session", - "description": "sqlalchemy_mixins.tests.test_session", - "peekOfCode": "class TestSessionMixin(unittest.TestCase):\n def setUp(self):\n Base.metadata.create_all(engine)\n def test_set_session(self):\n # before setting session, error is raised\n with self.assertRaises(NoSessionError):\n _ = BaseModel.session\n with self.assertRaises(NoSessionError):\n _ = User.session\n with self.assertRaises(NoSessionError):", - "detail": "sqlalchemy_mixins.tests.test_session", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_session", - "description": "sqlalchemy_mixins.tests.test_session", - "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nsession = Session(engine)\nclass BaseModel(Base, SessionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):", - "detail": "sqlalchemy_mixins.tests.test_session", - "documentation": {} - }, - { - "label": "session", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_session", - "description": "sqlalchemy_mixins.tests.test_session", - "peekOfCode": "session = Session(engine)\nclass BaseModel(Base, SessionMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass Post(BaseModel):\n __tablename__ = 'post'", - "detail": "sqlalchemy_mixins.tests.test_session", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nengine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SmartQueryMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class BaseModel(Base, SmartQueryMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n # to smart query relationship, it should be explicitly set,\n # not to be a backref", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\n # to smart query relationship, it should be explicitly set,\n # not to be a backref\n posts = sa.orm.relationship('Post')\n comments = sa.orm.relationship('Comment')\n # below relationship will just return query (without executing)", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "Post", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class Post(BaseModel):\n __tablename__ = 'post'\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n archived = sa.Column(sa.Boolean, default=False)\n # to smart query relationship, it should be explicitly set,\n # not to be a backref\n user = sa.orm.relationship('User')\n comments = sa.orm.relationship('Comment')", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "Comment", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class Comment(BaseModel):\n __tablename__ = 'comment'\n __repr_attrs__ = ['body']\n id = sa.Column(sa.Integer, primary_key=True)\n body = sa.Column(sa.String)\n user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))\n post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id'))\n rating = sa.Column(sa.Integer)\n created_at = sa.Column(sa.DateTime)\n # to smart query relationship, it should be explicitly set,", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "BaseTest", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class BaseTest(unittest.TestCase):\n def setUp(self):\n sess.rollback()\n BaseModel.set_session(None)\n Base.metadata.drop_all(engine)\n Base.metadata.create_all(engine)\n BaseModel.set_session(sess)\n def _seed(self):\n u1 = User(name='Bill u1')\n sess.add(u1)", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "TestFilterExpr", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class TestFilterExpr(BaseTest):\n # def setUp(self):\n # Base.metadata.create_all(engine)\n def test_filterable_attributes(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n self.assertEqual(set(User.filterable_attributes),\n {'id', 'name', # normal columns\n 'posts', 'comments', 'comments_' # relations\n })", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "TestOrderExpr", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class TestOrderExpr(BaseTest):\n def test_incorrect_expr(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n with self.assertRaises(KeyError):\n _ = sess.query(Post).filter(\n *Post.order_expr('INCORRECT_ATTR')).all()\n with self.assertRaises(KeyError):\n _ = sess.query(Post).filter(\n *Post.order_expr('*body')).all()", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "TestSmartQueryFilters", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class TestSmartQueryFilters(BaseTest):\n def test_incorrect_expr(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n with self.assertRaises(KeyError):\n _ = User.where(INCORRECT_ATTR='nomatter').all()\n def test_is_a_shortcut_to_filter_expr_in_simple_cases(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n \"\"\"when have no joins, where() is a shortcut for filter_expr \"\"\"", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "TestSmartQuerySort", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class TestSmartQuerySort(BaseTest):\n def test_incorrect_expr(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n with self.assertRaises(KeyError):\n _ = Post.sort('INCORRECT_ATTR').all()\n with self.assertRaises(KeyError):\n _ = Post.sort('*body').all()\n def test_is_a_shortcut_to_order_expr_in_simple_cases(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "TestFullSmartQuery", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class TestFullSmartQuery(BaseTest):\n def test_schema_with_strings(self):\n u1, u2, u3, p11, p12, p21, p22, cm11, cm12, cm21, cm22, cm_empty = \\\n self._seed()\n # standalone function\n query = Comment.query\n res = smart_query(query,\n filters={\n 'post___public': True,\n 'user__isnull': False", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "TestSmartQueryAutoEagerLoad", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "class TestSmartQueryAutoEagerLoad(BaseTest):\n \"\"\"\n Smart_query does auto-joins for filtering/sorting,\n so there's a sense to tell sqlalchemy that we alreeady joined that relation\n So we test that relations are set to be joinedload\n if they were used in smart_query()\n \"\"\"\n def _seed(self):\n result = BaseTest._seed(self)\n self.query_count = 0", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "engine", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "engine = create_engine('sqlite:///:memory:', echo=False)\nsess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SmartQueryMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "sess", - "kind": 5, - "importPath": "sqlalchemy_mixins.tests.test_smartquery", - "description": "sqlalchemy_mixins.tests.test_smartquery", - "peekOfCode": "sess = Session(engine)\n# sess = scoped_session(sessionmaker(bind=engine))\nclass BaseModel(Base, SmartQueryMixin):\n __abstract__ = True\n pass\nclass User(BaseModel):\n __tablename__ = 'user'\n __repr_attrs__ = ['name']\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)", - "detail": "sqlalchemy_mixins.tests.test_smartquery", - "documentation": {} - }, - { - "label": "Base", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_timestamp", - "description": "sqlalchemy_mixins.tests.test_timestamp", - "peekOfCode": "class Base(DeclarativeBase):\n __abstract__ = True\nclass BaseModel(Base, TimestampsMixin):\n \"\"\"Model to use as base.\"\"\"\n __abstract__ = True\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass User(BaseModel):\n \"\"\"User model exemple.\"\"\"\n __tablename__ = 'user'", - "detail": "sqlalchemy_mixins.tests.test_timestamp", - "documentation": {} - }, - { - "label": "BaseModel", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_timestamp", - "description": "sqlalchemy_mixins.tests.test_timestamp", - "peekOfCode": "class BaseModel(Base, TimestampsMixin):\n \"\"\"Model to use as base.\"\"\"\n __abstract__ = True\n id = sa.Column(sa.Integer, primary_key=True)\n name = sa.Column(sa.String)\nclass User(BaseModel):\n \"\"\"User model exemple.\"\"\"\n __tablename__ = 'user'\nclass TestTimestamps(unittest.TestCase):\n \"\"\"Test case for Timestamp mixin.\"\"\"", - "detail": "sqlalchemy_mixins.tests.test_timestamp", - "documentation": {} - }, - { - "label": "User", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_timestamp", - "description": "sqlalchemy_mixins.tests.test_timestamp", - "peekOfCode": "class User(BaseModel):\n \"\"\"User model exemple.\"\"\"\n __tablename__ = 'user'\nclass TestTimestamps(unittest.TestCase):\n \"\"\"Test case for Timestamp mixin.\"\"\"\n @classmethod\n def setUpClass(cls):\n cls.engine = create_engine('sqlite:///:memory:', echo=False)\n def setUp(self):\n self.session = Session(self.engine)", - "detail": "sqlalchemy_mixins.tests.test_timestamp", - "documentation": {} - }, - { - "label": "TestTimestamps", - "kind": 6, - "importPath": "sqlalchemy_mixins.tests.test_timestamp", - "description": "sqlalchemy_mixins.tests.test_timestamp", - "peekOfCode": "class TestTimestamps(unittest.TestCase):\n \"\"\"Test case for Timestamp mixin.\"\"\"\n @classmethod\n def setUpClass(cls):\n cls.engine = create_engine('sqlite:///:memory:', echo=False)\n def setUp(self):\n self.session = Session(self.engine)\n Base.metadata.create_all(self.engine)\n user_1 = User(name='User')\n self.session.add(user_1)", - "detail": "sqlalchemy_mixins.tests.test_timestamp", - "documentation": {} - }, - { - "label": "ModelNotFoundError", - "kind": 6, - "importPath": "sqlalchemy_mixins.activerecord", - "description": "sqlalchemy_mixins.activerecord", - "peekOfCode": "class ModelNotFoundError(ValueError):\n pass\nclass ActiveRecordMixin(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classproperty\n def settable_attributes(cls):\n return cls.columns + cls.hybrid_properties + cls.settable_relations\n def fill(self, **kwargs):\n for name in kwargs.keys():\n if name in self.settable_attributes:", - "detail": "sqlalchemy_mixins.activerecord", - "documentation": {} - }, - { - "label": "ActiveRecordMixin", - "kind": 6, - "importPath": "sqlalchemy_mixins.activerecord", - "description": "sqlalchemy_mixins.activerecord", - "peekOfCode": "class ActiveRecordMixin(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classproperty\n def settable_attributes(cls):\n return cls.columns + cls.hybrid_properties + cls.settable_relations\n def fill(self, **kwargs):\n for name in kwargs.keys():\n if name in self.settable_attributes:\n setattr(self, name, kwargs[name])\n else:", - "detail": "sqlalchemy_mixins.activerecord", - "documentation": {} - }, - { - "label": "ActiveRecordMixinAsync", - "kind": 6, - "importPath": "sqlalchemy_mixins.activerecordasync", - "description": "sqlalchemy_mixins.activerecordasync", - "peekOfCode": "class ActiveRecordMixinAsync(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classmethod\n def _get_primary_key_name(cls) -> str:\n \"\"\"\n Gets the primary key of the model.\n Note: This method can only be used if the model has a single primary key.\n :return: The name of the primary key.\n :raises InvalidRequestError: If the model does not have a primary key or \n has a composite primary key.", - "detail": "sqlalchemy_mixins.activerecordasync", - "documentation": {} - }, - { - "label": "async_root_cls", - "kind": 2, - "importPath": "sqlalchemy_mixins.activerecordasync", - "description": "sqlalchemy_mixins.activerecordasync", - "peekOfCode": "def async_root_cls(query: Query):\n \"\"\"Monkey patch SmaryQuery to handle async queries.\"\"\"\n try:\n return get_root_cls(query)\n except ValueError:\n # Handle async queries\n if query.__dict__[\"_propagate_attrs\"][\"plugin_subject\"].class_:\n return query.__dict__[\"_propagate_attrs\"][\"plugin_subject\"].class_\n raise\nSmaryQuery._get_root_cls = lambda query: async_root_cls(query)", - "detail": "sqlalchemy_mixins.activerecordasync", - "documentation": {} - }, - { - "label": "get_root_cls", - "kind": 5, - "importPath": "sqlalchemy_mixins.activerecordasync", - "description": "sqlalchemy_mixins.activerecordasync", - "peekOfCode": "get_root_cls = SmaryQuery._get_root_cls\ndef async_root_cls(query: Query):\n \"\"\"Monkey patch SmaryQuery to handle async queries.\"\"\"\n try:\n return get_root_cls(query)\n except ValueError:\n # Handle async queries\n if query.__dict__[\"_propagate_attrs\"][\"plugin_subject\"].class_:\n return query.__dict__[\"_propagate_attrs\"][\"plugin_subject\"].class_\n raise", - "detail": "sqlalchemy_mixins.activerecordasync", - "documentation": {} - }, - { - "label": "SmaryQuery._get_root_cls", - "kind": 5, - "importPath": "sqlalchemy_mixins.activerecordasync", - "description": "sqlalchemy_mixins.activerecordasync", - "peekOfCode": "SmaryQuery._get_root_cls = lambda query: async_root_cls(query)\nclass ActiveRecordMixinAsync(InspectionMixin, SessionMixin):\n __abstract__ = True\n @classmethod\n def _get_primary_key_name(cls) -> str:\n \"\"\"\n Gets the primary key of the model.\n Note: This method can only be used if the model has a single primary key.\n :return: The name of the primary key.\n :raises InvalidRequestError: If the model does not have a primary key or ", - "detail": "sqlalchemy_mixins.activerecordasync", - "documentation": {} - }, - { - "label": "EagerLoadMixin", - "kind": 6, - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "peekOfCode": "class EagerLoadMixin(SessionMixin):\n __abstract__ = True\n @classmethod\n def with_(cls, schema):\n \"\"\"\n Query class and eager load schema at once.\n :type schema: dict\n Example:\n schema = {\n Post.user: JOINED, # joinedload user", - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "eager_expr", - "kind": 2, - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "peekOfCode": "def eager_expr(schema):\n \"\"\"\n :type schema: dict\n \"\"\"\n return _eager_expr_from_schema(schema)\ndef _flatten_schema(schema):\n \"\"\"\n :type schema: dict\n \"\"\"\n def _flatten(schema, parent_path, result):", - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "JOINED", - "kind": 5, - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "peekOfCode": "JOINED = 'joined'\nSUBQUERY = 'subquery'\ndef eager_expr(schema):\n \"\"\"\n :type schema: dict\n \"\"\"\n return _eager_expr_from_schema(schema)\ndef _flatten_schema(schema):\n \"\"\"\n :type schema: dict", - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "SUBQUERY", - "kind": 5, - "importPath": "sqlalchemy_mixins.eagerload", - "description": "sqlalchemy_mixins.eagerload", - "peekOfCode": "SUBQUERY = 'subquery'\ndef eager_expr(schema):\n \"\"\"\n :type schema: dict\n \"\"\"\n return _eager_expr_from_schema(schema)\ndef _flatten_schema(schema):\n \"\"\"\n :type schema: dict\n \"\"\"", - "detail": "sqlalchemy_mixins.eagerload", - "documentation": {} - }, - { - "label": "InspectionMixin", - "kind": 6, - "importPath": "sqlalchemy_mixins.inspection", - "description": "sqlalchemy_mixins.inspection", - "peekOfCode": "class InspectionMixin:\n @classproperty\n def columns(cls):\n return inspect(cls).columns.keys()\n @classproperty\n def primary_keys_full(cls):\n \"\"\"Get primary key properties for a SQLAlchemy cls.\n Taken from marshmallow_sqlalchemy\n \"\"\"\n mapper = cls.__mapper__", - "detail": "sqlalchemy_mixins.inspection", - "documentation": {} - }, - { - "label": "ReprMixin", - "kind": 6, - "importPath": "sqlalchemy_mixins.repr", - "description": "sqlalchemy_mixins.repr", - "peekOfCode": "class ReprMixin:\n __abstract__ = True\n __repr_attrs__ = []\n __repr_max_length__ = 15\n @property\n def _id_str(self):\n ids = inspect(self).identity\n if ids:\n return '-'.join([str(x) for x in ids]) if len(ids) > 1 \\\n else str(ids[0])", - "detail": "sqlalchemy_mixins.repr", - "documentation": {} - }, - { - "label": "SerializeMixin", - "kind": 6, - "importPath": "sqlalchemy_mixins.serialize", - "description": "sqlalchemy_mixins.serialize", - "peekOfCode": "class SerializeMixin(InspectionMixin):\n \"\"\"Mixin to make model serializable.\"\"\"\n __abstract__ = True\n def to_dict(self,nested = False, hybrid_attributes = False, exclude = None):\n \"\"\"Return dict object with model's data.\n :param nested: flag to return nested relationships' data if true\n :type: bool\n :param hybrid_attributes: flag to include hybrid attributes if true\n :type: bool\n :return: dict", - "detail": "sqlalchemy_mixins.serialize", - "documentation": {} - }, - { - "label": "NoSessionError", - "kind": 6, - "importPath": "sqlalchemy_mixins.session", - "description": "sqlalchemy_mixins.session", - "peekOfCode": "class NoSessionError(RuntimeError):\n pass\nclass SessionMixin:\n _session = None\n @classmethod\n def set_session(cls, session):\n \"\"\"\n :type session: scoped_session | Session\n \"\"\"\n cls._session = session", - "detail": "sqlalchemy_mixins.session", - "documentation": {} - }, - { - "label": "SessionMixin", - "kind": 6, - "importPath": "sqlalchemy_mixins.session", - "description": "sqlalchemy_mixins.session", - "peekOfCode": "class SessionMixin:\n _session = None\n @classmethod\n def set_session(cls, session):\n \"\"\"\n :type session: scoped_session | Session\n \"\"\"\n cls._session = session\n @classproperty\n def session(cls):", - "detail": "sqlalchemy_mixins.session", - "documentation": {} - }, - { - "label": "SmartQueryMixin", - "kind": 6, - "importPath": "sqlalchemy_mixins.smartquery", - "description": "sqlalchemy_mixins.smartquery", - "peekOfCode": "class SmartQueryMixin(InspectionMixin, EagerLoadMixin):\n __abstract__ = True\n _operators = {\n 'isnull': lambda c, v: (c == None) if v else (c != None),\n 'exact': operators.eq,\n 'ne': operators.ne, # not equal or is not (for None)\n 'gt': operators.gt, # greater than , >\n 'ge': operators.ge, # greater than or equal, >=\n 'lt': operators.lt, # lower than, <\n 'le': operators.le, # lower than or equal, <=", - "detail": "sqlalchemy_mixins.smartquery", - "documentation": {} - }, - { - "label": "smart_query", - "kind": 2, - "importPath": "sqlalchemy_mixins.smartquery", - "description": "sqlalchemy_mixins.smartquery", - "peekOfCode": "def smart_query(query, filters=None, sort_attrs=None, schema=None):\n \"\"\"\n Does magic Django-ish joins like post___user___name__startswith='Bob'\n (see https://goo.gl/jAgCyM)\n Does filtering, sorting and eager loading at the same time.\n And if, say, filters and sorting need the same joinm it will be done\n only one. That's why all stuff is combined in single method\n :param query: sqlalchemy.orm.query.Query\n :param filters: dict\n :param sort_attrs: List[basestring]", - "detail": "sqlalchemy_mixins.smartquery", - "documentation": {} - }, - { - "label": "RELATION_SPLITTER", - "kind": 5, - "importPath": "sqlalchemy_mixins.smartquery", - "description": "sqlalchemy_mixins.smartquery", - "peekOfCode": "RELATION_SPLITTER = '___'\nOPERATOR_SPLITTER = '__'\nDESC_PREFIX = '-'\ndef _flatten_filter_keys(filters):\n \"\"\"\n :type filters: dict|list\n Flatten the nested filters, extracting keys where they correspond \n to smart_query paths, e.g. \n {or_: {'id__gt': 1000, and_ : {\n 'id__lt': 500,", - "detail": "sqlalchemy_mixins.smartquery", - "documentation": {} - }, - { - "label": "OPERATOR_SPLITTER", - "kind": 5, - "importPath": "sqlalchemy_mixins.smartquery", - "description": "sqlalchemy_mixins.smartquery", - "peekOfCode": "OPERATOR_SPLITTER = '__'\nDESC_PREFIX = '-'\ndef _flatten_filter_keys(filters):\n \"\"\"\n :type filters: dict|list\n Flatten the nested filters, extracting keys where they correspond \n to smart_query paths, e.g. \n {or_: {'id__gt': 1000, and_ : {\n 'id__lt': 500,\n 'related___property__in': (1,2,3) ", - "detail": "sqlalchemy_mixins.smartquery", - "documentation": {} - }, - { - "label": "DESC_PREFIX", - "kind": 5, - "importPath": "sqlalchemy_mixins.smartquery", - "description": "sqlalchemy_mixins.smartquery", - "peekOfCode": "DESC_PREFIX = '-'\ndef _flatten_filter_keys(filters):\n \"\"\"\n :type filters: dict|list\n Flatten the nested filters, extracting keys where they correspond \n to smart_query paths, e.g. \n {or_: {'id__gt': 1000, and_ : {\n 'id__lt': 500,\n 'related___property__in': (1,2,3) \n }}}", - "detail": "sqlalchemy_mixins.smartquery", - "documentation": {} - }, - { - "label": "TimestampsMixin", - "kind": 6, - "importPath": "sqlalchemy_mixins.timestamp", - "description": "sqlalchemy_mixins.timestamp", - "peekOfCode": "class TimestampsMixin:\n \"\"\"Mixin that define timestamp columns.\"\"\"\n __abstract__ = True\n __created_at_name__ = 'created_at'\n __updated_at_name__ = 'updated_at'\n __datetime_func__ = sa.func.now()\n created_at = sa.Column(__created_at_name__,\n sa.TIMESTAMP(timezone=False),\n default=__datetime_func__,\n nullable=False)", - "detail": "sqlalchemy_mixins.timestamp", - "documentation": {} - }, - { - "label": "classproperty", - "kind": 6, - "importPath": "sqlalchemy_mixins.utils", - "description": "sqlalchemy_mixins.utils", - "peekOfCode": "class classproperty(object):\n \"\"\"\n @property for @classmethod\n taken from http://stackoverflow.com/a/13624858\n \"\"\"\n def __init__(self, fget):\n self.fget = fget\n def __get__(self, owner_self, owner_cls):\n return self.fget(owner_cls)\ndef get_relations(cls):", - "detail": "sqlalchemy_mixins.utils", - "documentation": {} - }, - { - "label": "get_relations", - "kind": 2, - "importPath": "sqlalchemy_mixins.utils", - "description": "sqlalchemy_mixins.utils", - "peekOfCode": "def get_relations(cls):\n if isinstance(cls, Mapper):\n mapper = cls\n else:\n mapper = cls.__mapper__\n return [c for c in mapper.attrs\n if isinstance(c, RelationshipProperty)]\ndef path_to_relations_list(cls, path):\n path_as_list = path.split('.')\n relations = get_relations(cls)", - "detail": "sqlalchemy_mixins.utils", - "documentation": {} - }, - { - "label": "path_to_relations_list", - "kind": 2, - "importPath": "sqlalchemy_mixins.utils", - "description": "sqlalchemy_mixins.utils", - "peekOfCode": "def path_to_relations_list(cls, path):\n path_as_list = path.split('.')\n relations = get_relations(cls)\n relations_list = []\n for item in path_as_list:\n for rel in relations:\n if rel.key == item:\n relations_list.append(rel)\n relations = get_relations(rel.entity)\n break", - "detail": "sqlalchemy_mixins.utils", - "documentation": {} - }, - { - "label": "requirements", - "kind": 2, - "importPath": "setup", - "description": "setup", - "peekOfCode": "def requirements():\n import os\n filename = os.path.join(os.path.dirname(__file__), 'requirements.txt')\n return [line.rstrip('\\n') for line in open(filename).readlines()]\nsetup(name='sqlalchemy_mixins',\n version='2.0.5',\n description='Active Record, Django-like queries, nested eager load '\n 'and beauty __repr__ for SQLAlchemy',\n url='https://github.com/absent1706/sqlalchemy-mixins',\n download_url='https://github.com/absent1706/sqlalchemy-mixins/archive/master.tar.gz',", - "detail": "setup", - "documentation": {} - } -] \ No newline at end of file