diff options
Diffstat (limited to 'module/database')
-rw-r--r-- | module/database/ConfigDatabase.py | 41 | ||||
-rw-r--r-- | module/database/DatabaseBackend.py | 6 | ||||
-rw-r--r-- | module/database/__init__.py | 4 |
3 files changed, 37 insertions, 14 deletions
diff --git a/module/database/ConfigDatabase.py b/module/database/ConfigDatabase.py index cc24f6785..198ae0173 100644 --- a/module/database/ConfigDatabase.py +++ b/module/database/ConfigDatabase.py @@ -1,28 +1,49 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from module.database import DatabaseMethods, queue, async, inner - -# TODO +from module.database import DatabaseMethods, queue, async class ConfigMethods(DatabaseMethods): @async - def saveConfig(self, plugin, user, config): - pass + 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): - pass + 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): - pass + 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): - pass + 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 diff --git a/module/database/DatabaseBackend.py b/module/database/DatabaseBackend.py index 3e6b059c0..58e1e74d8 100644 --- a/module/database/DatabaseBackend.py +++ b/module/database/DatabaseBackend.py @@ -139,7 +139,7 @@ class DatabaseBackend(Thread): set_DB(self) def setup(self): - + """ *MUST* be called before db can be used !""" self.start() self.running.wait() @@ -352,9 +352,9 @@ class DatabaseBackend(Thread): self.c.execute( 'CREATE TABLE IF NOT EXISTS "settings" (' '"plugin" TEXT NOT NULL, ' - '"user" INTEGER NOT NULL, ' + '"user" INTEGER DEFAULT -1 NOT NULL, ' '"config" TEXT NOT NULL, ' - 'FOREIGN KEY(owner) REFERENCES users(uid), ' + 'FOREIGN KEY(user) REFERENCES users(uid), ' 'PRIMARY KEY (plugin, user) ON CONFLICT REPLACE' ')' ) diff --git a/module/database/__init__.py b/module/database/__init__.py index bf4ead872..d3f97fb53 100644 --- a/module/database/__init__.py +++ b/module/database/__init__.py @@ -3,4 +3,6 @@ from DatabaseBackend import DatabaseMethods, DatabaseBackend, queue, async, inne from FileDatabase import FileMethods from UserDatabase import UserMethods from StorageDatabase import StorageMethods -from AccountDatabase import AccountMethods
\ No newline at end of file +from AccountDatabase import AccountMethods +from ConfigDatabase import ConfigMethods +from StatisticDatabase import StatisticMethods
\ No newline at end of file |