Introduces SQL functions to easily manipulate caching functionality. Closes #3442

This commit is contained in:
Binaek Sarkar
2023-05-18 19:29:44 +05:30
committed by GitHub
parent 8ec8c76907
commit 0fa28fcaf3
3 changed files with 56 additions and 10 deletions

View File

@@ -1,5 +1,7 @@
package db_common
import "github.com/turbot/steampipe/pkg/constants"
// Functions is a list of SQLFunction objects that are installed in the db 'steampipe_internal' schema startup
var Functions = []SQLFunction{
{
@@ -15,6 +17,36 @@ begin
output_pattern = replace(output_pattern, '?', '_');
return output_pattern;
end;
`,
},
{
Name: constants.FunctionCacheSet,
Params: map[string]string{"command": "text"},
Returns: "void",
Language: "plpgsql",
Body: `
begin
IF command = 'on' THEN
INSERT INTO steampipe_internal.steampipe_settings("name","value") VALUES ('cache','true');
ELSIF command = 'off' THEN
INSERT INTO steampipe_internal.steampipe_settings("name","value") VALUES ('cache','false');
ELSIF command = 'clear' THEN
INSERT INTO steampipe_internal.steampipe_settings("name","value") VALUES ('cache_clear_time','');
ELSE
RAISE EXCEPTION 'Unknown value % for set_cache - valid values are on, off and clear.', $1;
END IF;
end;
`,
},
{
Name: constants.FunctionCacheSetTtl,
Params: map[string]string{"duration": "int"},
Returns: "void",
Language: "plpgsql",
Body: `
begin
INSERT INTO steampipe_internal.steampipe_settings("name","value") VALUES ('cache_clear_time',duration);
end;
`,
},
}