-
Notifications
You must be signed in to change notification settings - Fork 2
RethinkDB Provider
A RethinkDB-backed persistable session store for use with Nancy, utilizing the RethinkDb.Driver project.
(This is a community project with no formal relationships with the awesome Nancy project, the wonderful RethinkDB project, or the outstanding RethinkDb.Driver project.)
The RethinkDB connection object is designed to have a multi-request lifetime. The examples below register a singleton instance of a RethinkDB connection, then utilize it to register the RethinkDB session store.
namespace ExampleNancyApp
{
using Nancy;
using Nancy.Bootstrapper;
using Nancy.Session.Persistable;
using Nancy.Session.RethinkDB;
using Nancy.TinyIoc;
using RethinkDb.Driver;
using RethinkDb.Driver.Net;
public class ApplicationBootstrapper : DefaultNancyBootstrapper
{
private static RethinkDB R = RethinkDB.R;
public static IConnection Conn = R.Connection().[options].Connect();
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
base.ApplicationStartup(container, pipelines);
// Register the connection
container.Register(Conn);
// Register the session store
PersistableSessions.Enable(pipelines,
new RethinkDBSessionConfiguration(container.Resolve<IConnection>()));
}
}
}
module ExampleNancyApp
open Nancy
open Nancy.Bootstrapper
open Nancy.Session.Persistable
open Nancy.Session.RethinkDB
open RethinkDb.Driver
open RethinkDb.Driver.Net
/// Set up a database connection
let conn = RethinkDB.R.Connection().[options].Connect()
type ApplicationBootstrapper() =
inherit DefaultNancyBootstrapper()
override this.ApplicationStartup (container, pipelines) =
base.ApplicationStartup (container, pipelines)
// RethinkDB connection
container.Register<IConnection>(conn)
|> ignore
// Sessions
PersistableSessions.Enable
(pipelines, RethinkDBSessionConfiguration(container.Resolve<IConnection>()))
Imports Nancy
Imports Nancy.Bootstrapper
Imports Nancy.Session.Persistable
Imports Nancy.Session.RethinkDB
Imports Nancy.TinyIoc
Imports RethinkDb.Driver.Net
Namespace ExampleNancyApp
Public Class ApplicationBootstrapper
Inherits DefaultNancyBootstrapper
Private Shared R As RethinkDb.Driver.RethinkDB = RethinkDb.Driver.RethinkDB.R
Public Shared Conn As IConnection = R.Connection().Connect()
Protected Overrides Sub ApplicationStartup(container As TinyIoCContainer, pipelines As IPipelines)
MyBase.ApplicationStartup(container, pipelines)
' Register the connection
container.Register(Conn)
' Register the session store
PersistableSessions.Enable(pipelines, New RethinkDBSessionConfiguration(container.Resolve(Of IConnection)))
End Sub
End Class
End Namespace
As you may have noticed in the examples above, the configuration object takes the IConnection
as its only parameter. (There is a zero-parameter constructor as well, but if you do not specify a connection before enabling sessions, the provider will throw an exception.) This is only required configuration option.
In addition to the options provided by Nancy.Session.Persistable, the following options are available (SDHP uses all the defaults):
-
Database (string - default: "NancySession")
This is the RethinkDB database that will be used for persistence.
-
Table (string - default: "Session")
This is the table within the RethinkDB database that will be used for persistence.