Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then((connection)=>{
// Mix-in for Data Access Methods and SQL Autogenerating Methods
mysqlUtilities.upgrade(connection)
// Mix-in for Introspection Methods
mysqlUtilities.introspection(connection)
mysqlConnection = connection
return Promise.promisify(connection.tables,{context: connection})()
})
//遍历表并生成model和router文件
throw new Error("You must provide a 'mysqlConfig' argument for the database.")
}
if (!opts.prefix) {
opts.prefix = ""
}
PREFIX = Object.freeze(opts.prefix)
// TODO optimize schema creation (use a pool instead of a single connection ?)
const mysqlConnection = mysql.createConnection(opts.mysqlConfig)
// Mix-in for Data Access Methods and SQL Autogenerating Methods
mysqlUtilities.upgrade(mysqlConnection)
// Mix-in for Introspection Methods
mysqlUtilities.introspection(mysqlConnection)
// initialize the graphQL schema
const schemaComposer = new SchemaComposer()
const mysqlTablesNames = await _getMysqlTablesNames(mysqlConnection)
return Promise.all(mysqlTablesNames.map(async mysqlTableName => {
// initialize the graphql type built from the mysql table
const gqlTC = schemaComposer.TypeComposer.create({
name: _clearNameForType(mysqlTableName),
})
// add local fields
const fields = await _buildGqlFieldsFromMysqlTable(mysqlConnection, mysqlTableName)
gqlTC.addFields(fields)
pool.getConnection((err, conn) => {
if (err) {
console.log('Error in fetching database connection -> ' + err);
callback(err, null);
return;
}
mysqlUtilities.upgrade(conn);
mysqlUtilities.introspection(conn);
conn.fields(tableName, (err, fields) => {
if (conn) {
conn.release();
}
if (err) {
console.log('Error in fetching fields -> ' + err);
callback(err, null);
return;
}
callback(null, fields);
});
});