From 4c690ac49226d0d94fa3291825a87289ddcbfb68 Mon Sep 17 00:00:00 2001 From: Gunther Cox Date: Wed, 19 Jul 2017 22:00:58 -0400 Subject: [PATCH] Fix database name being ignored --- chatterbot/storage/sql_storage.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/chatterbot/storage/sql_storage.py b/chatterbot/storage/sql_storage.py index d222bb852..4253a11ae 100644 --- a/chatterbot/storage/sql_storage.py +++ b/chatterbot/storage/sql_storage.py @@ -89,7 +89,7 @@ class SQLStorageAdapter(StorageAdapter): can be especified to choose database driver (database parameter will be igored). :type database_uri: str - :keyword read_only: False by default, makes all operations read only, has priority over all DB operations + :keyword read_only: False by default, makes all operations read only, has priority over all DB operations so, create, update, delete will NOT be executed :type read_only: bool @@ -104,20 +104,17 @@ def __init__(self, **kwargs): from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker - self.database_name = self.kwargs.get("database") - - if self.database_name: - - # Create a sqlite file if a database name is provided - self.database_uri = self.kwargs.get( - "database_uri", "sqlite:///" + self.database_name + ".db" - ) - - # The default uses sqlite in-memory database + # The default uses a sqlite in-memory database self.database_uri = self.kwargs.get( "database_uri", "sqlite://" ) + database_name = self.kwargs.get("database") + + # Create a sqlite file if a database name is provided + if database_name: + self.database_uri = "sqlite:///" + database_name + ".db" + self.engine = create_engine(self.database_uri) self.read_only = self.kwargs.get(