如何使用loopback 4调用Mssql中的存储过程?
How to call stored procedure in Mssql using loopback 4?
如何使用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: 'sa3',
user: 'sa',
});
目前我正在使用具有简单 where 条件的默认 Crud 存储库
@get('/Job/{CustomerID}')
@param.path.number('CustomerID')
async findJobByCustomerID(CustomerID: number): Promise<Jobs[]> {
return await this.JobsRepo.find({ where: { CustomerID: CustomerID } });
}
提前致谢。
更改了数据源配置
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: 'sa3',
user: 'sa',
});
并在控制器上导入数据源
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;
}
});
}
如何使用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: 'sa3',
user: 'sa',
});
目前我正在使用具有简单 where 条件的默认 Crud 存储库
@get('/Job/{CustomerID}')
@param.path.number('CustomerID')
async findJobByCustomerID(CustomerID: number): Promise<Jobs[]> {
return await this.JobsRepo.find({ where: { CustomerID: CustomerID } });
}
提前致谢。
更改了数据源配置
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: 'sa3',
user: 'sa',
});
并在控制器上导入数据源
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;
}
});
}