Git(hub) mirror of Dr.-Ing. Stefan Kaes' SqlSessionStore plugin. Copyright (c) Dr.-Ing. Stefan Kaes
Switch branches/tags
Nothing to show
Pull request Compare This branch is 1 commit behind nateware:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


== SqlSessionStore

This version of SqlSessionStore properly supports both CGI-based sessions (Rails < 2.3)
and Rack-based sessions released in Rails 2.3.  For the latest version of +SqlSessionStore+,

To install, use:

    script/plugin install git://

This version also includes the "native columns" feature, which enables +session[:xyz]+
to map directly to column +xyz+ in the sessions table transparently.  For info,
scroll down to "Step 4".

Note: Only Mysql, PostgreSQL, and Oracle are currently supported (others work,
but you won't see much performance improvement).

== Step 1

If you have generated your sessions table using rake db:sessions:create, go to Step 2

If you're using an old version of sql_session_store, run

    script/generate sql_session_store [DB]

where DB is mysql, postgresql or oracle

Then run

    rake db:migrate

to create the sessions table.

== Step 2

Add the code below in +config/environment.rb+, inside the initializers section

  # Use SqlSessionStore instead of the standard ActiveRecord store
  config.action_controller.session_store = :sql_session_store

Then, depending on your database type, add

    SqlSessionStore.session_class = MysqlSession

    SqlSessionStore.session_class = PostgresqlSession


    SqlSessionStore.session_class = OracleSession

after the initializer section in environment.rb

== Step 3 (optional)

If you want to use a database separate from your default one to store
your sessions, specify a configuration in your database.yml file (say
sessions), and establish the connection on SqlSession in

   SqlSession.establish_connection :sessions

== Step 4 (optional)

If you want to store certain pieces of data as actual columns in the 
+sessions+ table transparently, simply update the sessions migration
to include the columns.  For example, if you wanted to store +user_id+
and +language+ as columns, your migration might look something like:

    create_table :sessions do |t|
      t.string  :session_id, :null => false, :references => nil, :unique => true
      t.integer :user_id
      t.string  :language
      t.text    :data

Then, use the "native columns" feature of the specific database driver:

    OracleSession.native_columns = [:user_id, :language]

This will map these columns transparently for you. Simply access them like
normal columns:

    session[:user_id]  =
    session[:language] = @language

And the appropriate columns in the sessions table will be updated for you.


1. The class name SQLSessionStore has changed to SqlSessionStore to
   let Rails work its autoload magic.

2. You will need the binary drivers for Mysql or Postgresql.
   These have been verified to work:

   * ruby-postgres ( with postgreql 8.1
   * ruby-mysql 2.7.1 with Mysql 4.1
   * ruby-mysql 2.7.2 with Mysql 5.0