zoukankan      html  css  js  c++  java
  • nodejs读取数据库的一种写法

    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));
    };
  • 相关阅读:
    mysql_单表查询
    mysql_建表
    MySQL基础
    JS_左边栏菜单
    Vue框架之组件系统
    Vue常用语法及命令
    Django的缓存,序列化,ORM操作的性能
    Django中的form表单
    Django中的auth模块
    AJAX请求提交数据
  • 原文地址:https://www.cnblogs.com/liuyinlei/p/7598962.html
Copyright © 2011-2022 走看看