本文整理匯總了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();
}
示例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);
}
}
示例3: createConnection
export function createConnection(props: { database: string }) {
return new DatabaseConnection(mysql.createConnection({
host: 'localhost',
user: 'root',
database: props.database
}))
}
示例4: constructor
constructor(config: ConnectionConfig, errorCallback?: (err: string) => void) {
const connection = createConnection(config);
connection.connect();
if (errorCallback) {
connection.on('error', errorCallback);
}
super(connection);
}
示例5: beforeEach
beforeEach((done) => {
con = mysql.createConnection(options.dbTest);
con.connect((err) => {
if (err) throw err;
helper = new TestHelper(con);
done();
});
});
示例6: connect
function connect() {
const connection = Mysql.createConnection({
host: "localhost",
user: "root",
password: "password"
});
return connection;
}
示例7: init
public init(): void {
this.connection = createConnection({
host : DATABASE.host,
user : DATABASE.user,
password : DATABASE.password,
database : DATABASE.database
});
this.enableDebug(false);
}
示例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();
}
示例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);
}
}));
}
示例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) {
//.........這裏部分代碼省略.........