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

use sqlite as database #126

Merged
merged 17 commits into from
May 23, 2019
Merged

use sqlite as database #126

merged 17 commits into from
May 23, 2019

Conversation

rishabhKalakoti
Copy link
Contributor

@rishabhKalakoti rishabhKalakoti commented May 19, 2019

fixes #118
TODO

  • installed peewee & setup database
  • setup user table
  • setup session table
  • setup submissions table
  • setup contest & questions table

@rishabhKalakoti
Copy link
Contributor Author

Is this implementation okay? let's finalize for one table and then we will do it similarly for other tables

server.py Show resolved Hide resolved
server.py Outdated Show resolved Hide resolved
@rishabhKalakoti
Copy link
Contributor Author

So... I left contest and question database as work has to be done with that in #119
There are a few things I need help in...
Defining a primary/ unique key in Submission (username + time should be the joint key)
Relationship between tables: Should we implement it?
And for rankings I had to convert the recordset into list first in a seperate statement, I could not do that and enumerate (for ranks) in the same statement.

server.py Outdated Show resolved Hide resolved
server.py Outdated Show resolved Hide resolved
@theSage21
Copy link
Member

Defining a primary/ unique key in Submission (username + time should be the joint key)

The indexing docs might be of help

Relationship between tables: Should we implement it?

What relations do you have in mind? I think linking between question,contest,submission,user should happen.

And for rankings I had to convert the recordset into list first in a seperate statement, I could not do that and enumerate (for ranks) in the same statement.

That's fine for now. Things will settle in a while. Let's get to a point where we can stop using shelve and completely switch to peewee.

server.py Outdated Show resolved Hide resolved
@rishabhKalakoti
Copy link
Contributor Author

Database fully implemented (almost).
Tasks left:

  • Make relationships
  • Correct the query for ranking

@rishabhKalakoti rishabhKalakoti changed the title WIP: use sqlite as database use sqlite as database May 20, 2019
Copy link
Member

@theSage21 theSage21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going in the right direction. 👍

Let's get the relations done

.gitignore Show resolved Hide resolved
server.py Outdated Show resolved Hide resolved
server.py Outdated Show resolved Hide resolved
server.py Show resolved Hide resolved
server.py Outdated Show resolved Hide resolved
@rishabhKalakoti
Copy link
Contributor Author

rishabhKalakoti commented May 21, 2019

I got some problems implementing relationships, can't really understand it.
Usually foreign keys are a field of another table, but here, the foreign key is a class
And, I am unable to implement insert operation with foreign keys, I went thorough the documentation, but can't get the hang of it yet :)

@theSage21
Copy link
Member

so foreign keys are a exactly what you mentioned. Simply numbers appearing in another table. But that is at the database level (mysql/sqlite). Right now we are using peewee which is an ORM. So in our case:

class Base(pw.Model):
    class Meta:
        database = db
class Question(Base):
    instructions = pw.CharField()

class Contest(Base):
    title = pw.CharField()

class QuesInContest(Base):
    question = pw.ForeignKeyField(Question)
    contest = pw.ForeignKeyField(Contest)

Peewee handles the index-integer-autoincrement thing for us. We just give it the class.

Now to insert things into QuesInContest table:

contest = Contest.create(...)
ques = Question.create(...)
q_in_c = QuesInContest.create(question=ques, contest=contest)

# or you could supply IDs ( for example when ID is a parameter in an API)
qid = int(ques.id)
cid = int(contest.id)
q_in_c = QuesInContest.create(question=qid, contest=cid)

@theSage21
Copy link
Member

I'd prefer to keep master in a working state always so if you could wrap up the relations thing also in this PR it would be wonderful!

@rishabhKalakoti
Copy link
Contributor Author

I'll give it a shot :)

@rishabhKalakoti
Copy link
Contributor Author

Should I implement the question table in this too?

@theSage21
Copy link
Member

theSage21 commented May 21, 2019 via email

@rishabhKalakoti
Copy link
Contributor Author

The database system looks ready to me now.
Relationships implemented.
(Bug in ranking for incorrect scoring still there)
@theSage21 you can have a look now :)

server.py Outdated Show resolved Hide resolved
server.py Show resolved Hide resolved
server.py Show resolved Hide resolved
server.py Show resolved Hide resolved
server.py Show resolved Hide resolved
server.py Outdated Show resolved Hide resolved
@theSage21
Copy link
Member

This is starting to make sense! 👍

server.py Outdated Show resolved Hide resolved
server.py Show resolved Hide resolved
server.py Outdated Show resolved Hide resolved
server.py Outdated Show resolved Hide resolved
server.py Outdated Show resolved Hide resolved
server.py Outdated Show resolved Hide resolved
server.py Outdated Show resolved Hide resolved
@theSage21 theSage21 merged commit 96f91d9 into PyJaipur:master May 23, 2019
rsvarma95 added a commit to rsvarma95/PyJudge that referenced this pull request May 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use sqlite as a database
2 participants