I'd like to know more is how should I separate them? Like what tables/collections would/should be this NoSQL or SQL?
So I tried testing with MongoDB and Sequel to make them play together and it was quite easy. If you have been using Ramaze before with Sequel, just do the same thing as before then just add configurations for the Mongo (which I also forgot to write configurations on my first part).
Configuration
with both MongoDB and Sequel
require 'rubygems'
require 'ramaze'
require 'yaml'
require 'bson'
require 'mongo_mapper'
require 'sequel'
require 'erubis'
MongoMapper.database = 'mongoplay'
Ramaze.options.layouts = '/view/layout'
Ramaze.options.mode = :dev
Ramaze.options.roots = [__DIR__] # Make sure that Ramaze knows where you are
Sequel.mysql(
'mongoplay',
:user => 'uname',
:password => 'pword',
:host => localhost
)
# Acquire controllers and models and other utilities
Ramaze.acquire 'util/*'
Ramaze.acquire 'model/base.rb', 'model/*'
Ramaze.acquire 'controller/base.rb', 'controller/*'
Ramaze.acquire 'config/routes.rb'
In the previous post on this topic, I was using a messaging/posting system and in here, I added a users table on a MySQL so we could tie some posts to a user if ever they wanted to register (I won't discuss here how to register/authenticate the user for now but you could use this link if so ever, that's what I used before). So the same model would apply ordinarily. I was using the user helper here.
User model
class User < Sequel::Model
def self.register(email, password)
User.create :email => email, :password => encrypt(password, salt), :salt => Digest::SHA1.hexdigest("--#{Time.now.to_f}--#{email}--")
end
...
And now to insert posts and tie them to a certain user. You can also define the key in the message model or don't and you'd still insert them the same like so:
...
if logged_in?
Message.create :name => user.username, :body => request[:body], :user_id => user.id
else
Message.create :name => request[:name], :body => request[:body]
end
...
And I just basically did the same with the comments section.
Now, now, to pull all the messages that a certain user has made:
class UsersController < Ramaze::Controller
map '/users'
def index(id)
@msgs = Message.all :user_id => id.to_i
end
end
If ever you were using a different model, just query first in the SQL table then query in the Mongo or vice-versa. :D