Skip to content

Commit

Permalink
Add a base class for SQL Alchemy models
Browse files Browse the repository at this point in the history
  • Loading branch information
gunthercox committed Jul 17, 2017
1 parent 3a5ff70 commit af92c4e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
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

0 comments on commit af92c4e

Please sign in to comment.