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

Add a base class for SQL Alchemy models #852

Merged
merged 1 commit into from
Jul 16, 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
Empty file.
26 changes: 26 additions & 0 deletions chatterbot/ext/sqlalchemy_app/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from sqlalchemy import Column, Integer
from sqlalchemy.ext.declarative import (
declared_attr, declarative_base
)


class ModelBase(object):
"""
An augmented base class for SqlAlchemy models.
"""

@declared_attr
def __tablename__(cls):
"""
Return the lowercase class name as the name of the table.
"""
return cls.__name__.lower()

id = Column(
Integer,
primary_key=True,
autoincrement=True
)


Base = declarative_base(cls=ModelBase)
6 changes: 1 addition & 5 deletions chatterbot/storage/sql_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
Base = None

try:
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
from chatterbot.ext.sqlalchemy_app.models import Base

class StatementTable(Base):
"""
Expand All @@ -32,7 +30,6 @@ def get_statement_serialized(context):
del params['text_search']
return json.dumps(params)

id = Column(Integer, primary_key=True, autoincrement=True)
text = Column(String, unique=True)
extra_data = Column(PickleType)

Expand Down Expand Up @@ -60,7 +57,6 @@ def get_reponse_serialized(context):
del params['text_search']
return json.dumps(params)

id = Column(Integer, primary_key=True, autoincrement=True)
text = Column(String)
occurrence = Column(Integer, default=1)
statement_text = Column(String, ForeignKey('StatementTable.text'))
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
'chatterbot.corpus',
'chatterbot.conversation',
'chatterbot.ext',
'chatterbot.ext.sqlalchemy_app',
'chatterbot.ext.django_chatterbot',
'chatterbot.ext.django_chatterbot.migrations',
'chatterbot.ext.django_chatterbot.management',
Expand Down