@@ -70,114 +70,8 @@ impl SchemaCacheItem for Function {
7070 type Item = Function ;
7171
7272 async fn load ( pool : & PgPool ) -> Result < Vec < Function > , sqlx:: Error > {
73- sqlx:: query_as!(
74- Function ,
75- r#"
76- with functions as (
77- select
78- *,
79- -- proargmodes is null when all arg modes are IN
80- coalesce(
81- p.proargmodes,
82- array_fill('i'::text, array[cardinality(coalesce(p.proallargtypes, p.proargtypes))])
83- ) as arg_modes,
84- -- proargnames is null when all args are unnamed
85- coalesce(
86- p.proargnames,
87- array_fill(''::text, array[cardinality(coalesce(p.proallargtypes, p.proargtypes))])
88- ) as arg_names,
89- -- proallargtypes is null when all arg modes are IN
90- coalesce(p.proallargtypes, p.proargtypes) as arg_types,
91- array_cat(
92- array_fill(false, array[pronargs - pronargdefaults]),
93- array_fill(true, array[pronargdefaults])) as arg_has_defaults
94- from
95- pg_proc as p
96- where
97- p.prokind = 'f'
98- )
99- select
100- f.oid::int8 as id,
101- n.nspname as schema,
102- f.proname as name,
103- l.lanname as language,
104- case
105- when l.lanname = 'internal' then ''
106- else f.prosrc
107- end as definition,
108- case
109- when l.lanname = 'internal' then f.prosrc
110- else pg_get_functiondef(f.oid)
111- end as complete_statement,
112- coalesce(f_args.args, '[]') as args,
113- pg_get_function_arguments(f.oid) as argument_types,
114- pg_get_function_identity_arguments(f.oid) as identity_argument_types,
115- f.prorettype::int8 as return_type_id,
116- pg_get_function_result(f.oid) as return_type,
117- nullif(rt.typrelid::int8, 0) as return_type_relation_id,
118- f.proretset as is_set_returning_function,
119- case
120- when f.provolatile = 'i' then 'IMMUTABLE'
121- when f.provolatile = 's' then 'STABLE'
122- when f.provolatile = 'v' then 'VOLATILE'
123- end as behavior,
124- f.prosecdef as security_definer
125- from
126- functions f
127- left join pg_namespace n on f.pronamespace = n.oid
128- left join pg_language l on f.prolang = l.oid
129- left join pg_type rt on rt.oid = f.prorettype
130- left join (
131- select
132- oid,
133- jsonb_object_agg(param, value) filter (where param is not null) as config_params
134- from
135- (
136- select
137- oid,
138- (string_to_array(unnest(proconfig), '='))[1] as param,
139- (string_to_array(unnest(proconfig), '='))[2] as value
140- from
141- functions
142- ) as t
143- group by
144- oid
145- ) f_config on f_config.oid = f.oid
146- left join (
147- select
148- oid,
149- jsonb_agg(jsonb_build_object(
150- 'mode', t2.mode,
151- 'name', name,
152- 'type_id', type_id,
153- 'has_default', has_default
154- )) as args
155- from
156- (
157- select
158- oid,
159- unnest(arg_modes) as mode,
160- unnest(arg_names) as name,
161- unnest(arg_types)::int8 as type_id,
162- unnest(arg_has_defaults) as has_default
163- from
164- functions
165- ) as t1,
166- lateral (
167- select
168- case
169- when t1.mode = 'i' then 'in'
170- when t1.mode = 'o' then 'out'
171- when t1.mode = 'b' then 'inout'
172- when t1.mode = 'v' then 'variadic'
173- else 'table'
174- end as mode
175- ) as t2
176- group by
177- t1.oid
178- ) f_args on f_args.oid = f.oid"#
179- )
180- . fetch_all ( pool)
181- . await
73+ sqlx:: query_file_as!( Function , "src/queries/functions.sql" )
74+ . fetch_all ( pool)
75+ . await
18276 }
18377}
0 commit comments