Skip to content

Commit 39c5c18

Browse files
authored
Merge pull request #85 from cipherstash/cip-1167/eql-show-config
Added cs_config() function for easier config inspection
2 parents f919fb3 + 51e3e29 commit 39c5c18

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

sql/021-config-functions.sql

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,34 @@ LANGUAGE sql STRICT PARALLEL SAFE
402402
BEGIN ATOMIC
403403
RETURN NULL;
404404
END;
405+
406+
DROP FUNCTION IF EXISTS cs_config();
407+
408+
--
409+
-- A convenience function to return the configuration in a tabular format, allowing for easier filtering, and querying.
410+
-- Query using `SELECT * FROM cs_config();`
411+
--
412+
CREATE FUNCTION cs_config() RETURNS TABLE (
413+
state cs_configuration_state_v1,
414+
relation text,
415+
col_name text,
416+
decrypts_as text,
417+
indexes jsonb
418+
)
419+
AS $$
420+
BEGIN
421+
RETURN QUERY
422+
WITH tables AS (
423+
SELECT config.state, tables.key AS table, tables.value AS config
424+
FROM cs_configuration_v1 config, jsonb_each(data->'tables') tables
425+
WHERE config.data->>'v' = '1'
426+
)
427+
SELECT
428+
tables.state,
429+
tables.table,
430+
column_config.key,
431+
column_config.value->>'cast_as',
432+
column_config.value->'indexes'
433+
FROM tables, jsonb_each(tables.config) column_config;
434+
END;
435+
$$ LANGUAGE plpgsql;

0 commit comments

Comments
 (0)