大家好,我正在从数据库中检索数据并将其存储在文件中。我正在以 yaml 格式存储数据。
require 'mysql2'
require 'yaml'
client = Mysql2::Client.new(:host => "localhost",:username => 'root' , :password => 'root' , :database => 'jgroup')
results = client.query("SELECT * FROM jivegroup")
File.open("D:/j.yml","w") do |file|
results.each do |index|
file.write(index.to_yaml);
end
end
below is my file "j.yml"
---
groupID: 1000
name: T1
description: ""
creationDate: 1209446456903
modificationDate: 1378128624533
---
groupID: 1001
name: T2
description:
creationDate: 1209446473683
modificationDate: 1378181717000
---
但是当我尝试使用 YAML::load 加载上述文件时,它给出了我唯一的第一条记录。我想加载所有记录,请帮忙。下面是我读取 yml 文件的代码
YAML::load( File.read('D:/jivegroup.yml') )
{"groupID"=>1000, "name"=>"T1", "description"=>"", "creationDate"=>1209446456903, "modificationDate"=>1378128624533}