-
Notifications
You must be signed in to change notification settings - Fork 17
PR to solve the issue of messages mixing #53
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
base: master
Are you sure you want to change the base?
Conversation
In this edit, we can now create new databases for the users who have recently registered, and the messages sent by the users will be stored in their respective databases. I have used SQLAlchemy instead of peewee.
Just added a variable 'new' in line 65 and line 78. And a new argument named 'new'.
|
Hello @HashirGJ8842! Thanks for updating this PR.
Comment last updated at 2019-10-29 07:48:29 UTC |
tmessage/db.py
Outdated
|
|
||
| User = '' | ||
| class MessageDatabase(db.Model): | ||
| __bind_key__ = User |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trailing whitespace
tmessage/db.py
Outdated
| db = SQLAlchemy(app) | ||
|
|
||
| User = '' | ||
| class MessageDatabase(db.Model): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected 2 blank lines, found 0
tmessage/db.py
Outdated
| from peewee import CharField, DateTimeField, Model, SqliteDatabase | ||
| app = Flask(__name__) | ||
| app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///main.db' | ||
| app.config['SQLALCHEMY_BINDS'] = { 'we' : 'sqlite:///we.db'} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whitespace after '{'
whitespace before ':'
tmessage/db.py
Outdated
| pip install flask-sqlalchemy | ||
| from datetime import datetime | ||
| from flask import Flask | ||
| from flask_sqlalchemy import SQLAlchemy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
module level import not at top of file
tmessage/db.py
Outdated
| pip install flask | ||
| pip install flask-sqlalchemy | ||
| from datetime import datetime | ||
| from flask import Flask |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
module level import not at top of file
tmessage/db.py
Outdated
| @@ -1,28 +1,34 @@ | |||
| """Handles the connection to the SQLite database as well as DB interaction""" | |||
| pip install flask | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SyntaxError: invalid syntax
tmessage/db.py
Outdated
| from flask_sqlalchemy import SQLAlchemy | ||
|
|
||
| from peewee import CharField, DateTimeField, Model, SqliteDatabase | ||
| app = Flask(__name__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need for flask in tmessage because we are not making a webserver here. Let us know on which issue are you working on or try opening a new issue if you want to work on some other issues.
Thanks for the PR though :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't used flask to make a webserver. I have used it so that I could use SqlAlchemy explicitly to work on this issue, and just because i was comfortable with SqlAlchemy ORM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need flask to use sqlalchemy and secondly, we are using peewee as an ORM
tmessage/db.py
Outdated
|
|
||
| class Message(DB.Model): | ||
| def fun(user): | ||
| __bind_key__ = user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local variable 'bind_key' is assigned to but never used
tmessage/db.py
Outdated
| def new_database(user): | ||
| APP.config['SQLALCHEMY_BINDS'][user] = f'sqlite:///{user}.db' | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank line contains whitespace
tmessage/db.py
Outdated
| @MESSAGES_DB | ||
| def new_database(user): | ||
| APP.config['SQLALCHEMY_BINDS'][user] = f'sqlite:///{user}.db' | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank line contains whitespace
tmessage/db.py
Outdated
| timestamp = DateTimeField() | ||
| def add(self): | ||
| return 1+1 | ||
| def __repr__(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected 1 blank line, found 0
tmessage/db.py
Outdated
| def add(self): | ||
| """ To few methods""" | ||
| print(self.sender) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank line contains whitespace
tmessage/db.py
Outdated
| timestamp = DB.Column(DB.DateTime) | ||
|
|
||
|
|
||
| def __repr__(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too many blank lines (2)
tmessage/db.py
Outdated
| sender = DB.Column(DB.String(120), primary_key=True, nullable=False) | ||
| message = DB.Column(DB.String(120), nullable=False) | ||
| timestamp = DB.Column(DB.DateTime) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank line contains whitespace
tmessage/db.py
Outdated
| @MESSAGES_DB | ||
| def store_messages(user, raw_msg): | ||
| """Store a message sent by the indicated user in the database""" | ||
| if new == True: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comparison to True should be 'if cond is True:' or 'if cond:'
too many blank lines (2)
| sender = CharField() | ||
| message = CharField() | ||
| timestamp = DateTimeField() | ||
| class Message(Model): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too many blank lines (2)
| from simple_chalk import chalk | ||
| import tmessage.auth as auth # auth.py | ||
| from tmessage.db import store_messages # db.py | ||
| from tmessage.db import database # db.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at least two spaces before inline comment
tmessage/db.py
Outdated
| @MESSAGES_DB | ||
| def store_messages(user, raw_msg): | ||
| """Store a message sent by the indicated user in the database""" | ||
| if new = True: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SyntaxError: invalid syntax
too many blank lines (2)
tmessage/db.py
Outdated
| MESSAGES_DB = SqliteDatabase('message_store.sqlite') | ||
| def database(user, raw_msg, new): | ||
| """user for sender, raw_msg for message, new if the user is new""" | ||
| MESSAGES_DB = SqliteDatabase(f'{user}.db')# pylint: disable=invalid_name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at least two spaces before inline comment
| @MESSAGES_DB | ||
| def store_messages(user, raw_msg): | ||
| """Store a message sent by the indicated user in the database""" | ||
| if new == True: # pylint: disable=singleton-comparison |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at least two spaces before inline comment
comparison to True should be 'if cond is True:' or 'if cond:'
too many blank lines (2)
In this, I have done some changes to create a system of databases, with each user having their own
database.