File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed
src/sqlalchemy_declarative_extensions/dialects/postgresql Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,17 @@ class FunctionVolatility(enum.Enum):
21
21
STABLE = "STABLE"
22
22
IMMUTABLE = "IMMUTABLE"
23
23
24
+ @classmethod
25
+ def from_provolatile (cls , provolatile : str ) -> FunctionVolatility :
26
+ """Convert a `pg_proc.provolatile` value to a `FunctionVolatility` enum."""
27
+ if provolatile == "v" :
28
+ return cls .VOLATILE
29
+ if provolatile == "s" :
30
+ return cls .STABLE
31
+ if provolatile == "i" :
32
+ return cls .IMMUTABLE
33
+ raise ValueError (f"Invalid volatility: { provolatile } " )
34
+
24
35
25
36
def normalize_arg (arg : str ) -> str :
26
37
parts = arg .strip ().split (maxsplit = 1 )
Original file line number Diff line number Diff line change @@ -217,11 +217,6 @@ def get_procedures_postgresql(connection: Connection) -> Sequence[BaseProcedure]
217
217
218
218
def get_functions_postgresql (connection : Connection ) -> Sequence [BaseFunction ]:
219
219
functions = []
220
- volatility_map = {
221
- "v" : FunctionVolatility .VOLATILE ,
222
- "s" : FunctionVolatility .STABLE ,
223
- "i" : FunctionVolatility .IMMUTABLE ,
224
- }
225
220
226
221
for f in connection .execute (functions_query ).fetchall ():
227
222
name = f .name
@@ -233,7 +228,7 @@ def get_functions_postgresql(connection: Connection) -> Sequence[BaseFunction]:
233
228
parameters = (
234
229
[p .strip () for p in f .parameters .split ("," )] if f .parameters else None
235
230
),
236
- volatility = volatility_map [ f .volatility ] ,
231
+ volatility = FunctionVolatility . from_provolatile ( f .volatility ) ,
237
232
name = name ,
238
233
definition = definition ,
239
234
language = language ,
You can’t perform that action at this time.
0 commit comments