Deploy apps to servers that you own and control.
Application monitoring that helps developers get it done.
In our last video, we explored the 11 different column types that Active Record supports and how SQLite stores them using four different storage types. But how can you be certain about how SQLite is actually storing your data?
In this video, we’ll look at how to use SQLite’s TYPEOF function to gain clear introspection into how the database stores and handles different column types.
Let’s jump back into our IRB session playground, where we have our posts table with all 11 column types, along with our Post model. We’ll set everything up—creating the posts table, schema migrations, and metadata tables—and then insert a new post record.
When we check the logs, we see some interesting details about how Active Record serializes data:
For date and time values, Active Record serializes them as ISO 8601 strings:
By preserving ISO 8601 formatting, Active Record ensures that SQLite’s date functions work predictably and efficiently while keeping datetime values readable and sortable.
The JSON column is simply stored as TEXT, formatted with keys wrapped in double quotes and structured as expected.
Although recent SQLite updates allow storing JSON documents as BLOBs, Active Record does not yet support this feature. However, for most web applications, the performance difference is negligible, and the Rails team is working on adding support in the future.
Now, let’s verify how SQLite actually stores these values in the database using the TYPEOF function.
By running:
SELECT TYPEOF(datetime_column) FROM posts;
We can confirm that the datetime column is stored as TEXT, just as expected.
If you want to have a hundred percent certainty of how a particular column is being stored, this is the tool you want to reach for:
def type_of(column_name)
ActiveRecord::Base.connection.execute(
"SELECT TYPEOF(#{column_name}) AS type FROM posts;"
).first['type'].upcase
end
We can set up this function to run this query passing in a column name and we're going to pretty print the SQLite storage type.
typeof 'binary'
Using this, we can inspect all 11 column types:
This TYPEOF function is an essential tool for verifying how data is stored in the database, ensuring that Active Record’s serialization methods align with SQLite’s storage mechanisms.
In the next video, we’ll explore how Active Record bridges the gap between Ruby classes and SQLite storage types, creating a seamless and predictable development experience.