dimanche 24 janvier 2016

What kind of database schema would I use to store users' transaction histories?

I have a series of python objects, each associated with a different user, e.g., obj1.userID = 1, obj2.userID = 2, etc. Each object also has a transaction history expressed as a python dict, i.e., obj2.transaction_record = {"itemID": 1, "amount": 1, "date": "2011-01-04"} etc.

I need these objects to persist, and transaction records may grow over time. Therefore, I'm thinking of using an ORM like sqlalchemy to make this happen.

What kind of database schema would I need to specify to store these objects in a database?

I have two alternatives, but neither seems like the correct thing to do:

  1. Have a different table for each user:

CREATE TABLE user_id ( itemID INT PRIMARY KEY, amount INT, date CHARACTER(10) );

  1. Store the transaction history dict as a BLOB of json:

CREATE TABLE foo ( userID INT PRIMARY KEY, trasaction_history BLOB);

Is there a cleaner way to implement this?

Aucun commentaire:

Enregistrer un commentaire