nestjs 连接MSSQL 2014
重点是要Return Datasource对象
export const databaseProviders = [
{
provide: 'DATA_SOURCE',
useFactory: async () => {
const dataSource = new DataSource({
type: 'mssql',
host: 'localhost',
port: 1433,
username: 'sa',
password: 'xxx',
database: 'xxx',
entities: [
// __dirname + '/../**/*.entity{.ts,.js}', //此处如论如何实验对mssql无效。对MongoDb/mysql有效
Ct2,
],
synchronize: false,
//materialized:true,
connectionTimeout: 15000,
requestTimeout: 15000,
pool:
{
max: 10,
min: 0,
idleTimeoutMillis: 30000
},
options: {
"encrypt": false // Windows Azure时设置为true,其他设置为false
},
extra: {
trustServerCertificate: true,
trustedConnection: true,
}
});
var b=dataSource.initialize();
// var a=(await b).getRepository(Ct2);
// console.log(await a.find({
// select: ["fJiePai"],
// skip: 0,
// take: 200,
// where: { fStation: "OP020", fJiePai: MoreThan('15') },
// order: {
// "fTime": "DESC"
// }
// }
// ));
return b;//很重要
},
},
];