Added a method to create views in bot's database
Given a list of dictionaries with `name` and `query` elements, overwrite or create a view.
This commit is contained in:
parent
a2e1b0c11a
commit
8a524a4e55
@ -7,7 +7,7 @@ __author__ = "Davide Testa"
|
|||||||
__email__ = "davte@libero.it"
|
__email__ = "davte@libero.it"
|
||||||
__credits__ = "Marco Origlia"
|
__credits__ = "Marco Origlia"
|
||||||
__license__ = "GNU General Public License v3.0"
|
__license__ = "GNU General Public License v3.0"
|
||||||
__version__ = "1.5.0"
|
__version__ = "1.5.1"
|
||||||
__maintainer__ = "Davide Testa"
|
__maintainer__ = "Davide Testa"
|
||||||
__contact__ = "t.me/davte"
|
__contact__ = "t.me/davte"
|
||||||
|
|
||||||
|
@ -2305,3 +2305,28 @@ class Bot(telepot.aio.Bot, Gettable):
|
|||||||
else:
|
else:
|
||||||
logging.info("Invalid name, please try again.")
|
logging.info("Invalid name, please try again.")
|
||||||
return 65 # Keep running, making user select another bot
|
return 65 # Keep running, making user select another bot
|
||||||
|
|
||||||
|
def create_views(self, views, overwrite=False):
|
||||||
|
"""Take a list of `views` and add them to bot database.
|
||||||
|
|
||||||
|
Each element of this list should have
|
||||||
|
- a `name` field
|
||||||
|
- a `query field`
|
||||||
|
"""
|
||||||
|
with self.db as db:
|
||||||
|
for view in views:
|
||||||
|
try:
|
||||||
|
if overwrite:
|
||||||
|
db.query(
|
||||||
|
f"""
|
||||||
|
DROP VIEW IF EXISTS {view['name']}
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
db.query(
|
||||||
|
f"""
|
||||||
|
CREATE VIEW IF NOT EXISTS {view['name']}
|
||||||
|
AS {view['query']}
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"{e}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user