Mercurial > libervia-backend
diff sat/memory/sqlite.py @ 3120:0c29155ac68b
core: backend autoconnection:
A new Connection/autoconnect_backend param can be set for a profile or component to be
started automatically with backend. This is specially useful for components, but can be
useful for client profile too (e.g. on Android we need to start profile with backend to
get notifications, this part will come with following commits).
The new Sqlite.getIndParamValues method allows to retrieve the same parameters for all
profiles.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 25 Jan 2020 21:08:32 +0100 |
parents | f8cc88c773c8 |
children | 9d0df638c8b4 |
line wrap: on
line diff
--- a/sat/memory/sqlite.py Sat Jan 25 21:08:29 2020 +0100 +++ b/sat/memory/sqlite.py Sat Jan 25 21:08:32 2020 +0100 @@ -196,8 +196,10 @@ @param db_filename: full path to the Sqlite database """ - self.initialized = defer.Deferred() # triggered when memory is fully initialised and ready - self.profiles = {} # we keep cache for the profiles (key: profile name, value: profile id) + # triggered when memory is fully initialised and ready + self.initialized = defer.Deferred() + # we keep cache for the profiles (key: profile name, value: profile id) + self.profiles = {} log.info(_("Connecting database")) new_base = not os.path.exists(db_filename) # do we have to create the database ? @@ -231,10 +233,10 @@ init_defer.addCallback(self.commitStatements) def fillProfileCache(ignore): - d = self.dbpool.runQuery("SELECT profile_id, entry_point FROM components").addCallback(self._cacheComponentsAndProfiles) - d.chainDeferred(self.initialized) + return self.dbpool.runQuery("SELECT profile_id, entry_point FROM components").addCallback(self._cacheComponentsAndProfiles) init_defer.addCallback(fillProfileCache) + init_defer.chainDeferred(self.initialized) def commitStatements(self, statements): @@ -387,10 +389,26 @@ @param profile: %(doc_profile)s @return: deferred """ - d = self.dbpool.runQuery("SELECT value FROM param_ind WHERE category=? AND name=? AND profile_id=?", (category, name, self.profiles[profile])) + d = self.dbpool.runQuery( + "SELECT value FROM param_ind WHERE category=? AND name=? AND profile_id=?", + (category, name, self.profiles[profile])) d.addCallback(self.__getFirstResult) return d + async def getIndParamValues(self, category, name): + """Ask database for the individual values of a parameter for all profiles + + @param category: category of the parameter + @param name: name of the parameter + @return dict: profile => value map + """ + result = await self.dbpool.runQuery( + "SELECT profiles.name, param_ind.value FROM param_ind JOIN profiles ON " + "param_ind.profile_id = profiles.id WHERE param_ind.category=? " + "and param_ind.name=?", + (category, name)) + return dict(result) + def setGenParam(self, category, name, value): """Save the general parameters in database