{"id":24634617,"url":"https://github.com/sbence/express-sqlite","last_synced_at":"2025-07-06T03:39:33.124Z","repository":{"id":273268269,"uuid":"919177236","full_name":"SBence/express-sqlite","owner":"SBence","description":"An SQLite-based session store for use with express-session, using better-sqlite3, with TypeScript support","archived":false,"fork":false,"pushed_at":"2025-03-06T22:44:48.000Z","size":83,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-06T22:49:16.588Z","etag":null,"topics":["connect","connectjs","express","express-js","express-session","expressjs","session","session-store","sessions","sql","sqlite","sqlite3"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/express-sqlite","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SBence.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-19T22:13:57.000Z","updated_at":"2025-03-06T22:44:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"404e7488-2039-42ff-8a6e-903f6b3d7916","html_url":"https://github.com/SBence/express-sqlite","commit_stats":null,"previous_names":["sbence/express-sqlite"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SBence%2Fexpress-sqlite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SBence%2Fexpress-sqlite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SBence%2Fexpress-sqlite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SBence%2Fexpress-sqlite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SBence","download_url":"https://codeload.github.com/SBence/express-sqlite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244574798,"owners_count":20474818,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["connect","connectjs","express","express-js","express-session","expressjs","session","session-store","sessions","sql","sqlite","sqlite3"],"created_at":"2025-01-25T09:13:20.004Z","updated_at":"2025-03-20T07:47:16.754Z","avatar_url":"https://github.com/SBence.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# express-sqlite\n\nAn SQLite-based session store for use with [express-session](https://github.com/expressjs/session), using [better-sqlite3](https://github.com/WiseLibs/better-sqlite3), with TypeScript support.\n\n[![npm version](https://img.shields.io/npm/v/express-sqlite)](https://www.npmjs.com/package/express-sqlite)\n![Last updated](https://img.shields.io/npm/last-update/express-sqlite)\n[![Publish on npm](https://github.com/SBence/express-sqlite/actions/workflows/publish.yml/badge.svg)](https://github.com/SBence/express-sqlite/actions/workflows/publish.yml)\n[![License](https://img.shields.io/npm/l/express-sqlite)](LICENSE)\n\n## Table of contents\n\n- [Usage](#usage)\n- [`SQLiteStore` constructor](#sqlitestore-constructor)\n- [Types](#types)\n  - [`StoreOptions`](#storeoptions)\n- [Sessions table structure](#sessions-table-structure)\n- [Methods](#methods)\n\n## Usage\n\n```ts\nimport express from \"express\";\nimport session from \"express-session\";\nimport { SQLiteStore } from \"express-sqlite\";\n\nconst app = express();\n\n// With required arguments only\nconst store = new SQLiteStore(\"sessions.db\");\n\n// With customized options\nconst store = new SQLiteStore(\"sessions.db\", {\n  tableName: \"Sessions\",\n  databaseOptions: { fileMustExist: false },\n  wal: true,\n});\n\napp.use(\n  session({ store, secret: \"your-secret-key\", cookie: { secure: true } }),\n);\n```\n\n## `SQLiteStore` constructor\n\n```ts\nclass SQLiteStore extends Store {\n  constructor(database: StoreDatabase, storeOptions?: StoreOptions) {}\n}\n```\n\n| Argument       | Type                            | Default value                          | Description                                                                                                                    |\n| -------------- | ------------------------------- | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |\n| `database`     | [`StoreDatabase`](#types)       | _Required argument_                    | The SQLite database to store sessions in. Can be specified as a file path, a `Buffer`, or a `BetterSqlite3.Database` instance. |\n| `storeOptions` | [`StoreOptions`](#storeoptions) | `{ tableName: \"Sessions\", wal: true }` | Options for initializing the store.                                                                                            |\n\n### `StoreOptions`\n\n| Property          | Type               | Description                                                                                                                                                                                                                                                                                                                        |\n| ----------------- | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `databaseOptions` | `Database.Options` | Options passed to `better-sqlite3`'s [`Database` constructor](https://github.com/WiseLibs/better-sqlite3/blob/master/docs/api.md#new-databasepath-options). Additionally, its `fileMustExist` property also controls whether the directory structure leading to the database file is created by this library, if it doesn't exist. |\n| `tableName`       | `string`           | Name of the table to store sessions in.                                                                                                                                                                                                                                                                                            |\n| `wal`             | `boolean`          | Controls the usage of SQLite's [WAL-mode](https://www.sqlite.org/wal.html).                                                                                                                                                                                                                                                        |\n\n## Types\n\n| Type                    | Definition                                   | Description                                                                                                                                                  |\n| ----------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| **`ErrorOnlyCallback`** | `(error?: unknown) =\u003e void`                  | Callback function with only the `error` argument. Used for store methods that don't return any data on success (`clear`, `destroy`, `set`).                  |\n| **`SessionDataWithId`** | `SessionData \u0026 { id: string }`               | `express-session`'s `SessionData` type extended with an `id` field that holds the session ID. Used for the `all` method.                                     |\n| **`StoreDatabase`**     | `string \\| Buffer \\| BetterSqlite3.Database` | A union type for the values that can be used in the [`SQLiteStore` constructor](#sqlitestore-constructor) to specify the database used for storing sessions. |\n\n## Sessions table structure\n\n| Column name | Data type | Constraints   |\n| ----------- | --------- | ------------- |\n| `id`        | `TEXT`    | `PRIMARY KEY` |\n| `data`      | `TEXT`    | `NOT NULL`    |\n\n\u003e [!NOTE]\n\u003e If the table doesn't exist in the database, it's automatically created.\n\n## Methods\n\n- ```ts\n  all(callback: (error: unknown, sessions?: SessionDataWithId[]) =\u003e void): void\n  ```\n\n  Retrieves all `sessions` in the store, including their IDs.\n\n- ```ts\n  destroy(sid: string, callback?: ErrorOnlyCallback): void\n  ```\n\n  Removes the session with the given ID (`sid`), if it exists. No error is thrown if there is no such session.\n\n- ```ts\n  clear(callback?: ErrorOnlyCallback): void\n  ```\n\n  Removes all sessions from the store.\n\n- ```ts\n  length(callback: (error: unknown, length?: number) =\u003e void): void\n  ```\n\n  Returns the number of active sessions (`length`).\n\n- ```ts\n  get(sid: string, callback: (error: unknown, session?: SessionData | null) =\u003e void): void\n  ```\n\n  Retrieves a `session` by its ID (`sid`). `session` is `null` if there is no such session in the store.\n\n- ```ts\n  set(sid: string, session: SessionData, callback?: ErrorOnlyCallback): void\n  ```\n\n  Saves a `session` with the given ID (`sid`). If such a session already exists, its data will be overwritten.\n\n\u003e [!NOTE]\n\u003e If an error occurs in any of the methods, the callback function will only have its `error` argument defined.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbence%2Fexpress-sqlite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsbence%2Fexpress-sqlite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbence%2Fexpress-sqlite/lists"}