Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>there a few frameworks that allow to access the database without using any sql. ActiveRecord, Datamapper .. and i guess there are some more.</p> <p>I use ActiveRecord, because it is standard in Rails, and fits my needs.</p> <p>You can use a script as the following:</p> <pre><code>require 'active_record' ## configuration: all constants should be configured here # DEFAULT_ENVIRONMENT = 'development' database_type = ARGV[0] if database_type.nil? database_type = DEFAULT_ENVIRONMENT end database_yaml = IO.read('../../config/database.yml') ## define model class Group &lt; ActiveRecord::Base end ## the script! class Script def self.run(env) groups = Group.find(:all, :limit =&gt; 10) #groups = Group.find(:first) xml_string = Array.new xml_string &lt;&lt; '&lt;?xml version="1.0" encoding="UTF-8"?&gt;' xml_string &lt;&lt; "&lt;groups&gt;" groups.each do |group| xml_string &lt;&lt; group.to_xml(:skip_instruct =&gt; true) end xml_string &lt;&lt; "&lt;/groups&gt;" # write to file f = File.open("groups.xml", "w") { |f| f.write(xml_string.join("\n")) } end end databases = YAML::load(database_yaml) ActiveRecord::Base.establish_connection(databases[database_type]) Script.run(database_type) </code></pre> <p>So, what i do is first declare a class Group, which will automatically to a table called "groups". Nothing else needed. Iterate over all groups, and convert to_xml (without the doc-type), and save to file.</p> <p>Pretty straightforward.</p> <p>You do have to specify a database.yml file somewhere to be able to connect to the database.</p> <p>Is this clear?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload