Repository: litestar-org/litestar

Issue:
StaticFilesConfig and virtual directories
I'm trying to write a ``FileSystemProtocol`` to load files from the package data using [importlib_resources](https://importlib-resources.readthedocs.io/en/latest/using.html#). But because ``directories`` is defined as ``DirectoryPath``, pydantic checks if the given directories exist in the local filesystem. 

This is not generally true, especially in any kind of virtual filesystem (e.g. a zipped package). I think this condition should be relaxed to support virtual filesystems.

https://github.com/starlite-api/starlite/blob/9bb6dcd57c10a591377cf8e3a537e9292566d5b9/starlite/config/static_files.py#L32


Discussion:
I agree. Do you want to submit a PR?

Resolving patch:
diff --git a/litestar/contrib/sqlalchemy/types.py b/litestar/contrib/sqlalchemy/types.py
--- a/litestar/contrib/sqlalchemy/types.py
+++ b/litestar/contrib/sqlalchemy/types.py
@@ -4,11 +4,12 @@
 from base64 import b64decode
 from typing import TYPE_CHECKING, Any, cast
 
+from sqlalchemy import text, util
 from sqlalchemy.dialects.oracle import BLOB as ORA_BLOB
 from sqlalchemy.dialects.oracle import RAW as ORA_RAW
 from sqlalchemy.dialects.postgresql import JSONB as PG_JSONB
 from sqlalchemy.dialects.postgresql import UUID as PG_UUID
-from sqlalchemy.types import BINARY, CHAR, BigInteger, Integer, TypeDecorator
+from sqlalchemy.types import BINARY, CHAR, BigInteger, Integer, SchemaType, TypeDecorator
 from sqlalchemy.types import JSON as _JSON
 
 if TYPE_CHECKING:
@@ -80,7 +81,7 @@ def to_uuid(value: Any) -> uuid.UUID | None:
         return cast("uuid.UUID | None", value)
 
 
-class JSON(TypeDecorator):
+class JSON(TypeDecorator, SchemaType):  # type: ignore
     """Platform-independent JSON type.
 
     Uses JSONB type for postgres, BLOB for Oracle, otherwise uses the generic JSON data type.
@@ -98,6 +99,8 @@ def python_type(self) -> type[dict]:
 
     def __init__(self, *args: Any, **kwargs: Any) -> None:
         """Initialize JSON type"""
+        self.name = kwargs.pop("name", None)
+        self.oracle_strict = kwargs.pop("oracle_strict", True)
 
     def load_dialect_impl(self, dialect: Dialect) -> Any:
         if dialect.name == "postgresql":
@@ -105,3 +108,31 @@ def load_dialect_impl(self, dialect: Dialect) -> Any:
         if dialect.name == "oracle":
             return dialect.type_descriptor(ORA_BLOB())
         return dialect.type_descriptor(_JSON())
+
+    def _should_create_constraint(self, compiler: Any, **kw: Any) -> bool:
+        return bool(compiler.dialect.name == "oracle")
+
+    def _variant_mapping_for_set_table(self, column: Any) -> dict | None:
+        if column.type._variant_mapping:
+            variant_mapping = dict(column.type._variant_mapping)
+            variant_mapping["_default"] = column.type
+        else:
+            variant_mapping = None
+        return variant_mapping
+
+    @util.preload_module("sqlalchemy.sql.schema")
+    def _set_table(self, column: Any, table: Any) -> None:
+        schema = util.preloaded.sql_schema
+        variant_mapping = self._variant_mapping_for_set_table(column)
+        constraint_options = "(strict)" if self.oracle_strict else ""
+        sqltext = text(f"{column.name} is json {constraint_options}")
+        e = schema.CheckConstraint(
+            sqltext,
+            name=f"{column.name}_is_json",
+            _create_rule=util.portable_instancemethod(  # type: ignore[no-untyped-call]
+                self._should_create_constraint,
+                {"variant_mapping": variant_mapping},
+            ),
+            _type_bound=True,
+        )
+        table.append_constraint(e)


Test patch:
diff --git a/tests/contrib/sqlalchemy/repository/oracledb/test_sqlalchemy_oracledb_json.py b/tests/contrib/sqlalchemy/repository/oracledb/test_sqlalchemy_oracledb_json.py
--- a/tests/contrib/sqlalchemy/repository/oracledb/test_sqlalchemy_oracledb_json.py
+++ b/tests/contrib/sqlalchemy/repository/oracledb/test_sqlalchemy_oracledb_json.py
@@ -7,6 +7,7 @@
 import pytest
 from sqlalchemy import Engine, NullPool, create_engine
 from sqlalchemy.dialects import oracle
+from sqlalchemy.schema import CreateTable
 
 from tests.contrib.sqlalchemy.models_uuid import (
     UUIDEventLog,
@@ -47,7 +48,9 @@ def fx_engine(docker_ip: str) -> Engine:
     )
 
 
-@pytest.mark.xfail
 def test_json_constraint_generation(engine: Engine) -> None:
-    _ddl = UUIDEventLog.__table__.compile(engine, dialect=oracle.dialect())  # type: ignore
-    assert "BLOB" in str(_ddl)
+    ddl = str(CreateTable(UUIDEventLog.__table__).compile(engine, dialect=oracle.dialect()))  # type: ignore
+    assert "BLOB" in ddl.upper()
+    assert "JSON" in ddl.upper()
+    with engine.begin() as conn:
+        UUIDEventLog.metadata.create_all(conn)