當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。