当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript mysql.createConnection函数代码示例

本文整理汇总了TypeScript中mysql.createConnection函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createConnection函数的具体用法?TypeScript createConnection怎么用?TypeScript createConnection使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了createConnection函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: initConnection

    static initConnection(env: string) {
        switch (env) {
            case 'development':

                this.dbConnection = mysql.createConnection(credentials.development.connection);
                break;
            case 'production':
                this.dbConnection = mysql.createConnection(credentials.production.connection);
                break;
            default:
                throw new Error('Unknown execution environment: ' + env);
        }
        this.dbConnection.connect();
    }
开发者ID:JohanBaskovec,项目名称:libraryBackEnd,代码行数:14,代码来源:database.ts

示例2: reject

                (resolve: (c: mysql.IConnection)=>void, reject: (e: Error)=> void) => {

                    const resolveC = (connection: mysql.IConnection) => {
                        connection.beginTransaction(err => {
                            if (err) {
                                reject(err);
                            } else {
                                resolve(connection);
                            }
                        });
                    };

                    if (MariaDBBase.pool_) {

                        MariaDBBase.pool_.getConnection((err, connection) => {
                            if (err) {
                                reject(err);
                            } else {
                                resolveC(connection);
                            }
                        });

                    } else {
                        // プールが無いときは接続を新規に作成
                        const connection = mysql.createConnection(MariaDBBase.config_);
                        resolveC(connection);

                    }
                }
开发者ID:Huruikagi,项目名称:Meshinator,代码行数:29,代码来源:MariaDBBase.ts

示例3: createConnection

export function createConnection(props: { database: string }) {
    return new DatabaseConnection(mysql.createConnection({
        host: 'localhost',
        user: 'root',
        database: props.database
    }))
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:7,代码来源:database.ts

示例4: constructor

 constructor(config: ConnectionConfig, errorCallback?: (err: string) => void) {
     const connection = createConnection(config);
     connection.connect();
     if (errorCallback) {
         connection.on('error', errorCallback);
     }
     super(connection);
 }
开发者ID:chasidic,项目名称:mysql,代码行数:8,代码来源:MySQLConnect.ts

示例5: beforeEach

 beforeEach((done) => {
     con = mysql.createConnection(options.dbTest);
     con.connect((err) => {
         if (err) throw err;
         helper = new TestHelper(con);
         done();
     });
 });
开发者ID:emilioastarita,项目名称:typed-rows,代码行数:8,代码来源:InformationTest.ts

示例6: connect

function connect() {
  const connection = Mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "password"
  });

  return connection;
}
开发者ID:Schniz,项目名称:cuery,代码行数:9,代码来源:mysql.spec.ts

示例7: init

 public init(): void {
   this.connection = createConnection({
     host     : DATABASE.host,
     user     : DATABASE.user,
     password : DATABASE.password,
     database : DATABASE.database
   });
   this.enableDebug(false);
 }
开发者ID:paullessing,项目名称:splitting-bills,代码行数:9,代码来源:database.service.ts

示例8: connect

export function connect(host:string,user:string,password:string,port:number){
    db=mysql.createConnection({
        host:host,
        user: user,
        password: password,
        port:port
    });

    db.connect(); 
}
开发者ID:michsu0927,项目名称:node-mysql-demo,代码行数:10,代码来源:db.ts

示例9: create

  create(): Promise<mysql.IConnection> {
    LOGGER.trace(`Creating new connection for pool ${this.name}`);
    const connection = mysql.createConnection(this.connConfig);

    /*
    * There isnt any good reason why a connection should ever error, so we mark any connection
    * that throws as error as bad, the pool will then check before giving this connection back out
    * and throw it away.
    */
    connection.on('error', (error) => {
      LOGGER.error(error, 'Connection Error', {
        connectionId: connection.threadId,
      });
      connection[MARKED_FOR_DELETION] = true;
    });

    return new Promise((resolve, reject) => connection.connect((err) => {
      if (err) {
        reject(err);
      } else {
        resolve(connection);
      }
    }));
  }
开发者ID:yruan,项目名称:inceptum,代码行数:24,代码来源:MySQLClient.ts

示例10: bootstrap_database

function bootstrap_database(type:DatabaseType, config:model.Configuration, finalCallback:(err:any, database:any) => void) {

    var tableName_zanderDetails = "ZanderDetails";
    var tableName_users = "Users";
    var tableName_projects = "Projects";

    var nodeSql:any = require('nodesql');

    var builderStack:any = [];
    builderStack[0] = function (db:any, callback:(err:any) => void) {
        db.query("CREATE TABLE " + tableName_zanderDetails + " (id INT NOT NULL, version INT NOT NULL)", function (err:any) {
            console.log("Created version table");
            if (err) {
                callback(err);
                return;
            }

            db.insert(tableName_zanderDetails, { id: 0, version: -1 }, function (err:any) {
                callback(err)
            });
        })
    };
    builderStack[1] = function (db:any, callback:(err:any) => void) {
        db.query("CREATE TABLE " + tableName_users + " (id VARCHAR(36) NOT NULL, " +
            "username VARCHAR(20) NOT NULL, " +
            "email VARCHAR(30) NOT NULL, " +
            "password CHAR(128) NOT NULL, " +
            "timestamp INTEGER NOT NULL)", function (err:any) {
            console.log("Created user table");
            callback(err);
        })
    };
    builderStack[2] = function (db:any, callback:(err:any) => void) {
        db.query("CREATE TABLE " + tableName_projects + " (id VARCHAR(36) NOT NULL, " +
            "userId VARCHAR(36) NOT NULL, " +
            "name VARCHAR(20) NOT NULL, " +
            "git VARCHAR(50) NOT NULL, " +
            "timestamp INTEGER NOT NULL)", function (err:any) {
            console.log("Created project table");
            callback(err);
        })
    };

    function bootstrap(currentVersion:number, db:any, callback:(err:any) => void) {
        var upperVersion = builderStack.length - 1;
        var nextVersion = currentVersion + 1;

        if (currentVersion > upperVersion) {
            callback("Unknown version installed")
        } else if (currentVersion === upperVersion) {
            console.log("Current Version Installed");
            callback(null)
        } else {
            console.log("Update from " + currentVersion + " to " + nextVersion);
            builderStack[nextVersion](db, function (err:any) {
                console.log("Updated from " + currentVersion + " to " + nextVersion);
                if (err)
                    callback(err);
                else
                    db.update(tableName_zanderDetails, { version: nextVersion }, {id: 0}, function (err:any) {
                        console.log("ZanderDetails version updated to " + nextVersion);
                        if (err)
                            callback(err);
                        else
                            bootstrap(nextVersion, db, callback);
                    });
            })
        }
    }

    function bootstrap_with_connection(db:any, callback:(err:any) => void) {
        db.select(tableName_zanderDetails, function (err:any, value:any) {
            if (err || !value || value.length < 1) {
                bootstrap(-1, db, callback);
            }
            else
                bootstrap(value[0].version, db, callback);
        })
    }

    switch (type) {
        case DatabaseType.SqlLite:
            var sqlite3:any = require('sqlite3').verbose();
            var databaseString = config.sqlite || ':memory:';
            console.log("Sqlite connection: " + databaseString);

            var connection = new sqlite3.Database(databaseString,
                function () {
                    var db = nodeSql.createSqliteStrategy(connection);
                    bootstrap_with_connection(db, function (err:any) {
                        finalCallback(err, db);
                    });
                });
            break;

        case DatabaseType.MySQL:
            var mysql:any = require('mysql');
            var connection = mysql.createConnection(config.mysql);
            var db = nodeSql.createMySqlStrategy(connection);
            bootstrap_with_connection(db, function (err:any) {
//.........这里部分代码省略.........
开发者ID:MorleyDev,项目名称:zander.server,代码行数:101,代码来源:bootstrapDatabase.ts


注:本文中的mysql.createConnection函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。