MySQLStore.prototype.createDatabaseTable = function(cb) { debug_log(‘Creating sessions database table‘); var fs = require(‘fs‘); /**读取当前目录下上级目录中的schema.sql中sql语句*/ /** CREATE TABLE IF NOT EXISTS `sessions` ( `session_id` varchar(255) COLLATE utf8_bin NOT NULL, `expires` int(11) unsigned NOT NULL, `data` text, PRIMARY KEY (`session_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin */ fs.readFile(__dirname + ‘/../schema.sql‘, ‘utf-8‘, function(error, sql) { if (error) { return cb(error); } // ‘??‘ 变成 ?? sql = sql.replace(/`[^`]+`/g, ‘??‘); var params = [ this.options.schema.tableName, this.options.schema.columnNames.session_id, this.options.schema.columnNames.expires, this.options.schema.columnNames.data, this.options.schema.columnNames.session_id ]; //创建sessions表,有列session_id,expires,data this.connection.query(sql, params, function(error) { if (error) { debug_error(‘Failed to create sessions database table.‘); debug_error(error); return cb && cb(error); } cb && cb(); }); }.bind(this)); };
时间: 2024-10-12 04:37:58