You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 30, 2020. It is now read-only.
* version bump: 1.0.0 🎆
* remove express-session as dependency
* remove note about code status
* mark code blocks in readme as JS for syntax highlighting
* update readme on how to pass express-session
* remove ESLint comments
* require user to pass express-session to documentdb-session
* install express-session for testing
Copy file name to clipboardExpand all lines: README.md
+55-30Lines changed: 55 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,20 +29,22 @@ Used in conjunction with the [`express-session`](https://www.npmjs.com/package/e
29
29
30
30
* Provides an optional `.initialize()` method if you'd like to initialize your database, collection, and stored procedures before making your first request, allowing you to check for errors before making other requests (otherwise the database will be initialized on the first request).
31
31
32
-
## Status
33
-
Code is stable and passes all tests, and been tested in a production environment. The version will be incremented to `v1.0.0` once others have successfully implemented it in production.
`collection` | `"sessions"` | The ID of the collection where the session data should be stored. If the collection does not exist, it will be created when the session store initializes. The collection may contain other data, or it may be a dedicated collection just for sessions.
69
71
`database` | `"sessionstore"` | The ID of the database where the session data should be stored. If the database does not exist, it will be creaed when the session store initializes.
70
72
`discriminator` | `{ type: "session" }` | By default, `documentdb-session` sets a `"type"` attribute on each session document with a value of `"session"`, to distinguish session documents from other documents in the collection. If you would like a different attribute or value to be used to discriminate session documents from other documents, enter that as an attribute-value pair in an object here, e.g. `{ site: "mysite.com" }` or `{ _type: "session" }`.
71
-
`host`(required) | none | The URL / hostname of your DocumentDB database account, usually of the form `https://mydbaccount.documents.azure.com:443/`. You can also provide this in an environment variable, (`DOCUMENTDB_URL`) instead.
72
-
`key`(required) | none | The primary key for your DocumentDB account. A primary key is required because `documentdb-session` may create a new database for your account, if none exists. You can also provide this in an environment variable (`DOCUMENTDB_KEY`) instead.
73
+
`host`(required) | none | The URL / hostname of your DocumentDB database account, usually of the form `https://mydbaccount.documents.azure.com:443/`. You can also provide this in an environment variable, (`DOCUMENTDB_URL`) instead.
74
+
`key`(required) | none | The primary key for your DocumentDB account. A primary key is required because `documentdb-session` may create a new database for your account, if none exists. You can also provide this in an environment variable (`DOCUMENTDB_KEY`) instead.
73
75
`ttl` | none | The TTL (time-to-live or expiration time) for your sessions, in seconds. After this time has elapsed since the last change to the session data, the session will be deleted. A session's TTL is extended each time session data is changed, restarting the timer. See more on [**Configuring TTL**](https://github.com/dwhieb/documentdb-session#configuring-ttl-time-to-live-or-expiration-time) below. *Enabling TTL is strongly recommended.*
74
76
75
77
**NB:** If you'd like to more fully customize the settings for the collection where your session data is stored (e.g. the connection policy and consistency level), you can create the collection in advance, and simply provide the ID of that collection in the `collection` config parameter. `documentdb-session` will then use that collection's settings.
@@ -98,7 +100,7 @@ To enable TTL without a default expiration, either call the `.replaceCollection(
98
100
### Working with Partitioned Collections
99
101
If you use partitioned collections, you can enable partitioning in the same way that you would enable it using the [DocumentDB Node.js SDK](https://github.com/Azure/azure-documentdb-node). The session store instance exposes the DocumentDB SDK's [DocumentClient](http://azure.github.io/azure-documentdb-node/DocumentClient.html) object (as `.client`), which you can use to register your partition resolver. A short example is below, and you can see a more complete example of using a partition resolver [here](https://github.com/Azure/azure-documentdb-node/blob/master/samples/Partitioning/app.js).
`documentdb-session` follows the [specification for session stores](https://github.com/expressjs/session#session-store-implementation) given by `express-session`. It includes all required, recommended, and optional methods, as well as a few extra convenience methods.
124
126
127
+
### DocumentDBSession
128
+
The `DocumentDBSession` method is exposed by requiring `documentdb-session`. Calling this function and passing it the `express-session` instance will return the [DocumentDBStore constructor](https://github.com/dwhieb/documentdb-session#documentdbstore). Example use:
The `DocumentDBStore`object exposed by `documentdb-session` is used to create a new instance of a session store. This may then be passed to `express-session`. See the [Typical Usage](https://github.com/dwhieb/documentdb-session#typical-usage) above for an example.
137
+
The `DocumentDBStore`constructor exposed by `documentdb-session` is used to create a new instance of a session `store` object. Calling this function and passing it an object with config options will return the new DocumentDB store object. This may then be passed to `express-session`. See the [Typical Usage](https://github.com/dwhieb/documentdb-session#typical-usage)and [DocumentDBSession](https://github.com/dwhieb/documentdb-session#documentdbsession) sections above for examples.
127
138
128
-
### .client
139
+
### store.client
129
140
The DocumentDB DocumentClient object from the Node.js SDK (complete documentation [here](http://azure.github.io/azure-documentdb-node/DocumentClient.html)). This provides complete access to the DocumentDB API and all its methods, and can be used to customize collection settings, or make other database calls independent of storing session data.
130
141
131
-
### .all(cb)
142
+
### store.all(cb)
132
143
Retrieves all sessions from the collection, by filtering on the session discriminator (usually `"type": "session"`).
133
144
134
-
`callback(err, sessions = [])`
145
+
```js
146
+
callback(err, sessions = [])
147
+
```
135
148
136
-
### .clear(cb)
149
+
### store.clear(cb)
137
150
Deletes all sessions from the collection. Callback is fired once the collection is cleared of all sessions. Other documents in the collection that are not sessions are not affected. This operation uses a stored procedure called `clear`, which is uploaded to the collection on initialization.
138
151
139
-
`callback(err)`
152
+
```js
153
+
callback(err)
154
+
```
140
155
141
-
### .destroy(sid, cb)
156
+
### store.destroy(sid, cb)
142
157
Deletes a session with the given session ID (`sid`). Callback is fired once the document is deleted.
143
158
144
-
`callback(err)`
159
+
```js
160
+
callback(err)
161
+
```
145
162
146
-
### .get(sid, cb)
163
+
### store.get(sid, cb)
147
164
Retrieves a session from the collection using the given session ID (`sid`). The session is returned as an object, and includes its administrative database properties (e.g. `_RID`, `_ETAG`). If the session is not found, the `session` object will be set to `null`.
148
165
149
-
`callback(err, session)`
166
+
```js
167
+
callback(err, session)
168
+
```
150
169
151
-
### .initialize(cb)
170
+
### store.initialize(cb)
152
171
Normally, `documentdb-session` will check for a DocumentDB database and collection the first time a request to the database is made, and will create them if they do not exist. It will also upload a few stored procedures to the collection. If you would like to initialize the database before you start making database calls, you can do so by calling `.initialize()`. This is useful if you want your application to check for database configuration errors before attempting to write sessions, and for testing.
Retrieves a count of the number of sessions in the collection, filtering on the session discriminator (usually `"type": "session"`). This operation uses a stored procedure called `length`, which is uploaded to the collection on initialization.
174
193
175
-
`callback(err, len)`
194
+
```js
195
+
callback(err, len)
196
+
```
176
197
177
-
### .set(sid, session, cb)
198
+
### store.set(sid, session, cb)
178
199
Upserts the session into the collection given a session ID (`sid`) and session object (`session`). The callback fires once the session has been added to the collection.
179
200
180
-
`callback(err)`
201
+
```js
202
+
callback(err)
203
+
```
181
204
182
-
### .touch(sid, session, cb)
205
+
### store.touch(sid, session, cb)
183
206
Resets the TTL (time-to-live) for the session (see the [`ttl` config option](https://github.com/dwhieb/documentdb-session#config-options) above). The callback fires onces the document has been updated. This operation works by updating the `lastActive` field on the document.
0 commit comments