sql - Storing Hash in Sqlite table . Do I use Serialization? -


I am preparing an app for which to store historical financial data for different stocks I currently have one The stock table where the columns are stock symbols, how I am trying to decide to store with stock names and numerical data. For example, for column stockprice, I have a complete hash where the key date is the value of a string and value share. This information should be easily accessible (fast random access). I've read something about serializing, but I wonder if this is the best option (or if it's applicable at all). Instead, there is a way to automatically generate a squat table for each stock, and which represent columns and rows, representing the stockpoints, create columns?

I appreciate all the information in this matter and maybe some explanations, where I should use the serialization or is there a better option

Edit 1: What is the active model serialization is relevant? ()

2 Edit: Is it appropriate to create and think about the Stockpace model instead; The table where the model is for one share and one stock has_many stockprices is a regular id in the stock market, a stock_id (for which it is related) and a dated column and stockpile Well column.

/ Div> = "Text">

You are right, it is possible to store it as a hash I have no matrix for serialize , but I started this way and I suggest optimizing your data collection if you see significant impact on your application.

You will see something like migration (be sure to use the text data type):

  def self.up add_column: stock,: value,: text  

In your model, you must add

  serialize: price  

in the form of a hash and store it directly.

Stock = Stock New stock Pris = {: date = & gt; "# {Time.nuh}" ,: zodiac => 25.2} stock.save

Edit: Unless you prepare the functionality that is specific to stock_pres. Since each table is per model in the Rail Convention, you will end up with a class for stock_price. It is not necessary to dedicate a class to the stock, unless you have specific methods for that class. Also, depending on your design, you may be able to keep the stock class more cohesive by placing the stock price as a feature of the shares.