willbarrett commented on a change in pull request #9129: [datasets] new, API 
using command pattern
URL: 
https://github.com/apache/incubator-superset/pull/9129#discussion_r379118740
 
 

 ##########
 File path: superset/datasets/dao.py
 ##########
 @@ -0,0 +1,119 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import logging
+from typing import Dict, Optional
+
+from flask import current_app
+from flask_appbuilder.models.sqla.interface import SQLAInterface
+from sqlalchemy.exc import SQLAlchemyError
+
+from superset import db
+from superset.connectors.sqla.models import SqlaTable
+from superset.models.core import Database
+from superset.views.base import DatasourceFilter
+
+logger = logging.getLogger(__name__)
+
+
+class DatasetDAO:
+    @staticmethod
+    def get_owner_by_id(owner_id: int) -> Optional[object]:
+        return (
+            db.session.query(current_app.appbuilder.sm.user_model)
+            .filter_by(id=owner_id)
+            .one_or_none()
+        )
+
+    @staticmethod
+    def get_database_by_id(database_id) -> Optional[Database]:
+        try:
+            return 
db.session.query(Database).filter_by(id=database_id).one_or_none()
+        except SQLAlchemyError as e:  # pragma: no cover
+            logger.error(f"Could not get database by id: {e}")
+            return None
+
+    @staticmethod
+    def validate_table_exists(database: Database, table_name: str, schema: 
str) -> bool:
+        try:
+            database.get_table(table_name, schema=schema)
 
 Review comment:
   I think a `one_or_none` query here would be better - that would avoid the 
error handling.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to