PR to solve the issue of messages mixing#53
PR to solve the issue of messages mixing#53HashirGJ8842 wants to merge 43 commits intoHaider8:masterfrom
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 |
tmessage/db.py
Outdated
| db = SQLAlchemy(app) | ||
|
|
||
| User = '' | ||
| class MessageDatabase(db.Model): |
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.
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.
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.
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 | |||
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.
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.
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.
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.
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' | ||
|
|
||
|
|
tmessage/db.py
Outdated
| @MESSAGES_DB | ||
| def new_database(user): | ||
| APP.config['SQLALCHEMY_BINDS'][user] = f'sqlite:///{user}.db' | ||
|
|
tmessage/db.py
Outdated
| timestamp = DateTimeField() | ||
| def add(self): | ||
| return 1+1 | ||
| def __repr__(self): |
tmessage/db.py
Outdated
| def add(self): | ||
| """ To few methods""" | ||
| print(self.sender) | ||
|
|
tmessage/db.py
Outdated
| timestamp = DB.Column(DB.DateTime) | ||
|
|
||
|
|
||
| def __repr__(self): |
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) | ||
|
|
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.
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): |
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.
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.
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.
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.