{"id":13781341,"url":"https://github.com/thinkjs/think-session-mysql","last_synced_at":"2025-04-06T17:31:38.942Z","repository":{"id":65374730,"uuid":"86654062","full_name":"thinkjs/think-session-mysql","owner":"thinkjs","description":"Use Mysql to store session for ThinkJS 3.x","archived":false,"fork":false,"pushed_at":"2021-07-02T00:21:21.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":3,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-22T04:01:54.480Z","etag":null,"topics":["mysql","session-mysql","thinkjs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":false,"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/thinkjs.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}},"created_at":"2017-03-30T03:19:17.000Z","updated_at":"2021-07-02T00:21:16.000Z","dependencies_parsed_at":"2023-01-20T01:25:23.082Z","dependency_job_id":null,"html_url":"https://github.com/thinkjs/think-session-mysql","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-session-mysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-session-mysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-session-mysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-session-mysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thinkjs","download_url":"https://codeload.github.com/thinkjs/think-session-mysql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247522328,"owners_count":20952522,"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":["mysql","session-mysql","thinkjs"],"created_at":"2024-08-03T18:01:25.060Z","updated_at":"2025-04-06T17:31:38.616Z","avatar_url":"https://github.com/thinkjs.png","language":"JavaScript","readme":"# think-session-mysql\nUse Mysql to store session for ThinkJS\n\n\n## Install\n\n```\nnpm install think-session-mysql\n```\n\n## How to use\n\nconfig file `src/config/adapter.js`, add options:\n\n```js\nconst mysqlSession = require('think-session-mysql');\nexports.session = {\n  type: 'mysql',\n  common: {\n    cookie: {\n      name: 'thinkjs',\n      //maxAge: '',\n      //expires: '',\n      path: '/',  //a string indicating the path of the cookie\n      //domain: '',\n      //secure: false,\n      //keys: [],\n      httpOnly: true,\n      sameSite: false,\n      signed: false,\n      overwrite: false\n    }\n  },\n   mysql:{\n    handle:mysqlSession,\n    // optional config fields,merge model.mysql if empty\n    database:'think_test',\n    prefix:'think_',\n    host:'127.0.0.1',\n    port:'3306',\n    user:'root',\n    password:'',\n    gcInterval: 3600 * 1000 //gc interval\n  }\n}\n```\n\nif some fields also in model config, you can use Spread Properties.\n\n```js\nconst mysqlConfig = {\n  database:'think_test',\n  prefix:'think_',\n  host:'127.0.0.1',\n  port:'3306',\n  user:'root',\n  password:'',\n}\nexports.model = {\n  type: 'mysql',\n  mysql: {\n    handle: mysqlModel,\n    ...mysqlConfig\n  }\n}\nexports.session = {\n  type: 'mysql',\n  mysql: {\n    handle: mysqlSession,\n    ...mysqlConfig\n  }\n}\n```\n\n## Create Database\n`think_` is the prefix in `adapter.js`\n```\nCREATE TABLE `think_session` (\n  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n  `cookie` varchar(255) NOT NULL DEFAULT '',\n  `data` text,\n  `expire` bigint(11) NOT NULL DEFAULT '0',\n  `maxage` int(11) NOT NULL DEFAULT '0',\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `cookie` (`cookie`),\n  KEY `expire` (`expire`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n```\n","funding_links":[],"categories":["Adapters"],"sub_categories":["session"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkjs%2Fthink-session-mysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthinkjs%2Fthink-session-mysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkjs%2Fthink-session-mysql/lists"}