我正在编写一个Ruby gem,它使用Yaml :: dump将sql可执行文件转换为yaml。但是,当在Postgresql中测试它时,我发现整数是用它们周围的单引号输出的(作为字符串),除非它们以零开头。下面是对Yaml :: dump的调用的代码片段以及一些结果数据。
db_object = {}
db_output = {}
full_table = ActiveRecord::Base.connection.execute("SELECT * FROM #{model};")
keys = full_table[0].keys
db_object["columns"] = keys
model_arr=[]
full_table.each do |row|
model_arr << row.values_at(*keys)
end
db_object["records"] = model_arr
db_output[model] = db_object
YAML::dump(db_output, file)
以下是前几行结果:
schema_migrations:
columns:
- version
records:
- - '20121225230020'
- - '20121225230129'
---
students:
columns:
- id
- first_name
- last_name
- date_of_birth
- rank
- phone
records:
- - '1'
- Celestino
- Towne
- '2007-09-20'
- '2'
- '6417358360'
非常感谢任何见解。