From 2c8cff08e24d1d346deefc6c722d8fb9bf6fe248 Mon Sep 17 00:00:00 2001 From: Andrew Dawson Date: Mon, 1 Mar 2021 14:34:36 -0800 Subject: [PATCH] Add helper methods for sql plugin registeration (#4024) --- common/persistence/sql/store.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/common/persistence/sql/store.go b/common/persistence/sql/store.go index 9dfcbe7f1f1..3bbdf1b77b0 100644 --- a/common/persistence/sql/store.go +++ b/common/persistence/sql/store.go @@ -37,6 +37,19 @@ func RegisterPlugin(pluginName string, plugin sqlplugin.Plugin) { supportedPlugins[pluginName] = plugin } +// RegisterPluginIfNotExists will register a SQL plugin only if a plugin with same name has not already been registered +func RegisterPluginIfNotExists(pluginName string, plugin sqlplugin.Plugin) { + if _, ok := supportedPlugins[pluginName]; !ok { + supportedPlugins[pluginName] = plugin + } +} + +// PluginRegistered returns true if plugin with given name has been registered, false otherwise +func PluginRegistered(pluginName string) bool { + _, ok := supportedPlugins[pluginName] + return ok +} + // NewSQLDB creates a returns a reference to a logical connection to the // underlying SQL database. The returned object is to tied to a single // SQL database and the object can be used to perform CRUD operations on