Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change SQL storage default to sqlite file instead of in-memory database #871

Merged
merged 1 commit into from
Jul 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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