michael-s-molina commented on code in PR #35259:
URL: https://github.com/apache/superset/pull/35259#discussion_r2529104173


##########
superset-core/src/superset_core/api/daos.py:
##########
@@ -0,0 +1,262 @@
+# 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.
+
+"""
+Data Access Object API for superset-core.
+
+Provides dependency-injected DAO classes that will be replaced by
+host implementations during initialization.
+
+Usage:
+    from superset_core.api.daos import DatasetDAO, DatabaseDAO
+
+    # Use standard BaseDAO methods
+    datasets = DatasetDAO.find_all()
+    dataset = DatasetDAO.find_one_or_none(id=123)
+    DatasetDAO.create(attributes={"name": "New Dataset"})
+"""
+
+from abc import ABC, abstractmethod
+from typing import Any, ClassVar, Generic, TypeVar
+
+from flask_appbuilder.models.filters import BaseFilter
+from sqlalchemy.orm import Query as SQLAQuery
+
+from superset_core.api.models import (
+    Chart,
+    CoreModel,
+    Dashboard,
+    Database,
+    Dataset,
+    KeyValue,
+    Query,
+    SavedQuery,
+    Tag,
+    User,
+)
+
+# Type variable bound to our CoreModel
+T = TypeVar("T", bound=CoreModel)
+
+
+class BaseDAO(Generic[T], ABC):
+    """
+    Abstract base class for DAOs.
+
+    This ABC defines the base that all DAOs should implement,
+    providing consistent CRUD operations across Superset and extensions.
+    """
+
+    # Due to mypy limitations, we can't have `type[T]` here
+    model_cls: ClassVar[type[Any] | None]
+    base_filter: ClassVar[BaseFilter | None]
+    id_column_name: ClassVar[str]
+    uuid_column_name: ClassVar[str]
+
+    @classmethod
+    @abstractmethod
+    def find_all(cls) -> list[T]:
+        """Get all entities that fit the base_filter."""
+        ...
+
+    @classmethod
+    @abstractmethod
+    def find_one_or_none(cls, **filter_by: Any) -> T | None:
+        """Get the first entity that fits the base_filter."""
+        ...
+
+    @classmethod
+    @abstractmethod
+    def create(

Review Comment:
   I wonder if we need another API abstraction which is not commands or DAOs 
but that use them for the implementation. For example, the API would expose 
CRUD operations and delegate R operations to DAOs but CUD operations to 
commands. The method signatures could be the same as their implementations or 
slightly better (command APIs are bad).
   
   In this case, the exposed APIs will always be a subset of the DAOs and 
commands APIs.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to