Skip to content

nateware/sql_session_store

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

== 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+,
see:

    http://github.com/nateware/sql_session_store/tree/master

To install, use:

    script/plugin install git://github.com/nateware/sql_session_store.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
or

    SqlSessionStore.session_class = PostgresqlSession

or

    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
environment.rb:

   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
      t.timestamps
    end

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]  = @user.id
    session[:language] = @language

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

== IMPORTANT NOTES

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 (0.7.1.2005.12.21) with postgreql 8.1
   * ruby-mysql 2.7.1 with Mysql 4.1
   * ruby-mysql 2.7.2 with Mysql 5.0

About

Git(hub) mirror of Dr.-Ing. Stefan Kaes' SqlSessionStore plugin. Copyright (c) Dr.-Ing. Stefan Kaes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages