Skip to content

Commit

Permalink
Change SQL storage default to sqlite file instead of in-memory.
Browse files Browse the repository at this point in the history
  • Loading branch information
gunthercox committed Jul 23, 2017
1 parent ae4ad35 commit 3202f4a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions chatterbot/storage/sql_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class SQLStorageAdapter(StorageAdapter):
Performance test not done yet.
Tests using others databases not finished.
All parameters all optional, default is sqlite database in memory.
All parameters are optional, by default a sqlite database is used.
It will check if tables is present, if not, it will attempt to create required tables.
:keyword database: Used for sqlite database. Ignored if database_uri especified.
Expand All @@ -92,10 +92,6 @@ class SQLStorageAdapter(StorageAdapter):
: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
:keyword create: Force Recreate ChatterBot only tables in database, default False,
if read_only is True create is ignored.
:type create: bool
"""

def __init__(self, **kwargs):
Expand All @@ -104,13 +100,18 @@ def __init__(self, **kwargs):
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

# The default uses a sqlite in-memory database
default_uri = "sqlite:///db.sqlite3"

database_name = self.kwargs.get("database", False)

# None results in a sqlite in-memory database as the default
if database_name is None:
default_uri = "sqlite://"

self.database_uri = self.kwargs.get(
"database_uri", "sqlite://"
"database_uri", default_uri
)

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"
Expand Down
2 changes: 1 addition & 1 deletion tests/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_kwargs(self):
return {
'input_adapter': 'chatterbot.input.VariableInputTypeAdapter',
'output_adapter': 'chatterbot.output.OutputAdapter',
# None runs the test database in-memory
# Run the test database in-memory
'database': None
}

Expand Down

0 comments on commit 3202f4a

Please sign in to comment.