diff options
Diffstat (limited to 'module/database/ConfigDatabase.py')
-rw-r--r-- | module/database/ConfigDatabase.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/module/database/ConfigDatabase.py b/module/database/ConfigDatabase.py new file mode 100644 index 000000000..198ae0173 --- /dev/null +++ b/module/database/ConfigDatabase.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from module.database import DatabaseMethods, queue, async + +class ConfigMethods(DatabaseMethods): + + @async + def saveConfig(self, plugin, config, user=None): + if user is None: + self.c.execute('INSERT INTO settings(plugin, config) VALUES(?,?)', (plugin, config)) + else: + self.c.execute('INSERT INTO settings(plugin, config, user) VALUES(?,?,?)', (plugin, config, user)) + + + @queue + def loadConfig(self, plugin, user=None): + if user is None: + self.c.execute('SELECT config FROM settings WHERE plugin=?', (plugin, )) + else: + self.c.execute('SELECT config FROM settings WHERE plugin=? AND user=?', (plugin, user)) + + return self.c.fetchone()[0] + + @async + def deleteConfig(self, plugin, user=None): + if user is None: + self.c.execute('DELETE FROM settings WHERE plugin=?', (plugin, )) + else: + self.c.execute('DELETE FROM settings WHERE plugin=? AND user=?', (plugin, user)) + + @queue + def loadAllConfigs(self): + self.c.execute('SELECT user, plugin, config FROM settings') + configs = {} + for r in self.c: + if r[0] in configs: + configs[r[0]][r[1]] = r[2] + else: + configs[r[0]] = {r[1]: r[2]} + + return configs + + @async + def clearAllConfigs(self): + self.c.execute('DELETE FROM settings') + + +ConfigMethods.register()
\ No newline at end of file |