如何使用loopback 4 typescript
在Mssql中调用存储过程如何在数据源中进行查询,如调用存储过程
import { DataSourceConstructor} from '@loopback/repository';
export const db = new DataSourceConstructor({
connector: 'mssql',
host: '192.168.1.110',
port: 1433,
database: 'FastDryNew',
password: 'sa$123',
user: 'sa',
});
目前我正在使用Default Crud Repository with simple where condition
@get('/Job/{CustomerID}')
@param.path.number('CustomerID')
async findJobByCustomerID(CustomerID: number): Promise<Jobs[]> {
return await this.JobsRepo.find({ where: { CustomerID: CustomerID } });
}
提前致谢。
答案 0 :(得分:1)
更改了数据源配置
var DataSource = require('loopback-datasource-juggler').DataSource;
export var db = new DataSource({
connector: require('loopback-connector-mssql'),
host: '192.168.1.110',
port: 1433,
database: 'FastDryNew',
password: 'sa$123',
user: 'sa',
});
在Controller上导入dataSource
import { db } from '../datasources/db.datasource';
@get('/user')
async findUser() {
let sql = 'select * from [User]';
db.connector.query(sql, function (err: any, results: User[]) {
if (err) {
throw err;
} else {
return results;
}
});
}