Hey, how should I go about storing historical valu...
# orm-help
k
Hey, how should I go about storing historical values? I want to store points that a user has achieved over the course of a month. Would I need to set up a points table where I store the given date and points and reference that to the user's table or how should I go about doing this? Also how would I fetch the points over the course of the last 5 days?
👀 1
✅ 1
c
I would create a table with id, user_id, score, and created_at/scored_datetime
then you can use the datetime where clauses very easily
k
Yeah I get your point but then I would have to connect each user to a point and vice verse. Each registered point would populate the points table .Hmm, not sure but thanks for answering
c
that’s what a db is for? Storing data!
I imagine you would have a user table, containing more information about your user, and then a points table like above
n
Are you using SQL or a NoSQL Database?
k
SQL
n
@Kenny Tran Creating two tables, one for the user and the other for points would be the most straightforward approach. Is there any issue in needing to connect a point to a user?
k
I would need to map collected points to a user and I assume I would be doing so by connecting those tables through a many-to-many relation. But I'm also considering storing points as a string field and make the calculation after fetching the user table. Not sure
n
That should also work, is there a range of how many maximum points a user can have?
k
No, the accumulation would just go on. But I think I have got an idea. Thank your for your help
🙌 1