3 This version of SqlSessionStore properly supports both CGI-based sessions (Rails < 2.3)
 
   4 and Rack-based sessions released in Rails 2.3.  For the latest version of +SqlSessionStore+,
 
   7     http://github.com/nateware/sql_session_store/tree/master
 
  11     script/plugin install git://github.com/nateware/sql_session_store.git
 
  13 This version also includes the "native columns" feature, which enables +session[:xyz]+
 
  14 to map directly to column +xyz+ in the sessions table transparently.  For info,
 
  15 scroll down to "Step 4".
 
  17 Note: Only Mysql, PostgreSQL, and Oracle are currently supported (others work,
 
  18 but you won't see much performance improvement).
 
  22 If you have generated your sessions table using rake db:sessions:create, go to Step 2
 
  24 If you're using an old version of sql_session_store, run
 
  26     script/generate sql_session_store [DB]
 
  28 where DB is mysql, postgresql or oracle
 
  34 to create the sessions table.
 
  38 Add the code below in +config/environment.rb+, inside the initializers section
 
  40   # Use SqlSessionStore instead of the standard ActiveRecord store
 
  41   config.action_controller.session_store = :sql_session_store
 
  43 Then, depending on your database type, add
 
  45     SqlSessionStore.session_class = MysqlSession
 
  48     SqlSessionStore.session_class = PostgresqlSession
 
  52     SqlSessionStore.session_class = OracleSession
 
  54 after the initializer section in environment.rb
 
  58 If you want to use a database separate from your default one to store
 
  59 your sessions, specify a configuration in your database.yml file (say
 
  60 sessions), and establish the connection on SqlSession in
 
  63    SqlSession.establish_connection :sessions
 
  67 If you want to store certain pieces of data as actual columns in the 
 
  68 +sessions+ table transparently, simply update the sessions migration
 
  69 to include the columns.  For example, if you wanted to store +user_id+
 
  70 and +language+ as columns, your migration might look something like:
 
  72     create_table :sessions do |t|
 
  73       t.string  :session_id, :null => false, :references => nil, :unique => true
 
  80 Then, use the "native columns" feature of the specific database driver:
 
  82     OracleSession.native_columns = [:user_id, :language]
 
  84 This will map these columns transparently for you. Simply access them like
 
  87     session[:user_id]  = @user.id
 
  88     session[:language] = @language
 
  90 And the appropriate columns in the sessions table will be updated for you.
 
  94 1. The class name SQLSessionStore has changed to SqlSessionStore to
 
  95    let Rails work its autoload magic.
 
  97 2. You will need the binary drivers for Mysql or Postgresql.
 
  98    These have been verified to work:
 
 100    * ruby-postgres (0.7.1.2005.12.21) with postgreql 8.1
 
 101    * ruby-mysql 2.7.1 with Mysql 4.1
 
 102    * ruby-mysql 2.7.2 with Mysql 5.0