This is a postgres adaptor for Kemal Session
This is a ctrl+f replace fork of kemal-session-mysql
. I am using it until I need to switch to redis for sessions in the future. I have not updated the tests (yet).
Add this to your application's shard.yml
:
dependencies:
kemal-session-postgres:
github: iomcr/kemal-session-postgres
require "kemal"
require "kemal-session-postgres"
require "postgres"
# connect to postgres, update url with your connection info (or perhaps use an ENV var)
connection = DB.open "postgres://root@localhost/test?sslmode=require"
Session.config do |config|
config.cookie_name = "postgres_test"
config.secret = "a_secret"
config.engine = Session::PostgresEngine.new(connection)
config.timeout = Time::Span.new(1, 0, 0)
end
get "/" do
puts "Hello World"
end
post "/sign_in" do |context|
context.session.int("see-it-works", 1)
end
Kemal.run
If you are already using crystal-postgres you can re-use the reference to your connection.
Session.config do |config|
config.cookie_name = "postgres_test"
config.secret = "a_secret"
config.engine = Session::PostgresEngine.new(
connection: connection,
sessiontable: "sessions",
cachetime: 5
)
config.timeout = Time::Span.new(1, 0, 0)
end
Param | Description |
---|---|
connection | A Crystal postgres DB Connection |
sessiontable | Name of the table to use for sessions - defaults to "sessions" |
cachetime | Number of seconds to hold the session data in memory, before re-reading from the database. This is set to 5 seconds by default, set to 0 to hit the db for every request. |
- Fork it ( https://github.com/iomcr/kemal-session-postgres/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request