Skip to content

Commit da72623

Browse files
w3b6x9soedirgo
authored andcommitted
feat: change function config param value to string
1 parent bdc5de0 commit da72623

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

src/lib/PostgresMetaFunctions.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export default class PostgresMetaFunctions {
9494
language?: string
9595
behavior?: 'IMMUTABLE' | 'STABLE' | 'VOLATILE'
9696
security_definer?: boolean
97-
config_params: { [key: string]: string[] }
97+
config_params: { [key: string]: string }
9898
}): Promise<PostgresMetaResult<PostgresFunction>> {
9999
const sql = `
100100
CREATE FUNCTION ${ident(schema)}.${ident(name)}(${args.join(', ')})
@@ -105,10 +105,8 @@ export default class PostgresMetaFunctions {
105105
${security_definer ? 'SECURITY DEFINER' : 'SECURITY INVOKER'}
106106
${Object.entries(config_params)
107107
.map(
108-
([param, values]) =>
109-
`SET ${param} ${
110-
values[0] === 'FROM CURRENT' ? 'FROM CURRENT' : 'TO ' + values.map(ident).join(',')
111-
}`
108+
([param, value]) =>
109+
`SET ${param} ${value[0] === 'FROM CURRENT' ? 'FROM CURRENT' : 'TO ' + value}`
112110
)
113111
.join('\n')}
114112
RETURNS NULL ON NULL INPUT;

src/lib/sql/functions.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ SELECT
1515
WHEN p.provolatile = 'v' THEN 'VOLATILE'
1616
END AS behavior,
1717
p.prosecdef AS security_definer,
18-
JSON_OBJECT_AGG(p_config.param, p_config.values)
18+
JSON_OBJECT_AGG(p_config.param, p_config.value)
1919
FILTER (WHERE p_config.param IS NOT NULL) AS config_params
2020
FROM
2121
pg_proc p
@@ -26,7 +26,7 @@ FROM
2626
SELECT
2727
oid as id,
2828
(string_to_array(unnest(proconfig), '='))[1] AS param,
29-
string_to_array((string_to_array(unnest(proconfig), '='))[2], ', ') AS values
29+
(string_to_array(unnest(proconfig), '='))[2] AS value
3030
FROM
3131
pg_proc
3232
) p_config ON p_config.id = p.oid

src/lib/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const postgresFunctionSchema = Type.Object({
8484
Type.Literal('VOLATILE'),
8585
]),
8686
security_definer: Type.Boolean(),
87-
config_params: Type.Union([Type.Dict(Type.Array(Type.String())), Type.Null()]),
87+
config_params: Type.Union([Type.Dict(Type.String()), Type.Null()]),
8888
})
8989
export type PostgresFunction = Static<typeof postgresFunctionSchema>
9090

test/integration/index.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ describe('/functions', () => {
167167
language: 'sql',
168168
behavior: 'STABLE',
169169
security_definer: true,
170-
config_params: { search_path: ['hooks', 'auth'], role: ['postgres'] },
170+
config_params: { search_path: 'hooks, auth', role: 'postgres' },
171171
}
172172
before(async () => {
173173
await axios.post(`${URL}/query`, {
@@ -217,7 +217,7 @@ describe('/functions', () => {
217217
assert.strictEqual(newFunc.return_type, 'int4')
218218
assert.strictEqual(newFunc.behavior, 'STABLE')
219219
assert.strictEqual(newFunc.security_definer, true)
220-
assert.deepStrictEqual(newFunc.config_params, { search_path: ['hooks', 'auth'], role: ['postgres'] })
220+
assert.deepStrictEqual(newFunc.config_params, { search_path: 'hooks, auth', role: 'postgres' })
221221
func.id = newFunc.id
222222
})
223223
it('PATCH', async () => {

0 commit comments

Comments
 (0)