Sha256: ea18e2d0bc3faf9727e3b376047d5accb2d517d8290056638c81fff90f891cfd
Contents?: true
Size: 1.28 KB
Versions: 12
Compression:
Stored size: 1.28 KB
Contents
# = Mysql to PostgreSQL migration example. # # A simple example to demonstrate the flexibility of # Og. Two connections to different databases are # created and data is copied from a MySQL database # to a PostgreSQL database. # # Og makes it easier to switch to a REAL database :) require 'og' # Configure databases. psql_config = { :destroy => true, :name => 'test', :store => 'psql', :user => 'postgres', :password => 'navelrulez' } mysql_config = { :destroy => true, :name => 'test', :store => 'mysql', :user => 'root', :password => 'navelrulez' } # Initialize Og. psql = Og.connect(psql_config) mysql = Og.connect(mysql_config) # An example managed object. # Looks like an ordinary Ruby object. class Article property :name, :body, String def initialize(name = nil, body = nil) @name, @body = name, body end end # First populate the mysql database. mysql.manage(Article) a1 = Article.create('name1', 'body1') a1 = Article.create('name1', 'body1') a1 = Article.create('name1', 'body1') # Read all articles from Mysql. articles = Article.all # Switch to PostgreSQL. psql.manage(Article) # Store all articles. for article in articles article.insert end # Fetch an article from PostgreSQL # as an example. Lookup by name. article = Article.find_by_name('name1')
Version data entries
12 entries across 12 versions & 1 rubygems