开发者

Datamapper - best practices for pre-loading data

开发者 https://www.devze.com 2023-03-14 21:28 出处:网络
I\'m writing a web app using Ruby/Sinatra and Datamapper. I have some tables that I want to preload data into. Is there a best practice for that? E.g. I have a table called references

I'm writing a web app using Ruby/Sinatra and Datamapper. I have some tables that I want to preload data into. Is there a best practice for that? E.g. I have a table called references

id name url
-- ---- -------------------
 1 AOL  http://www.aol.com
 2 Dell http://www.dell.com

I want to ensure that this data is always loaded when someone starts up the app开发者_如何学JAVA for the first time and and ensure the IDs do not changes....

Thoughts?


There may be a gem out there to do this for you which I'm not aware of, and if there is, I'd love to hear about it. But, for my last project I simply had my import data in a yaml file and wrote a Ruby class that parsed that yaml file and used DataMapper to insert the data for me.

I then created a Rake task that allowed me to run this Ruby class.

Is this the sort of solution you might be after? If so, I can give you more info on it.

0

精彩评论

暂无评论...
验证码 换一张
取 消