Comment on page
SqlQueryService
SqlQueryService TypeScript Class Reference
SERVICE
This class is a "service" and it is automatically injected if declared as a member in the constructor of the consuming class.
- See the constructor section below for details
- See the Automatic Instance Injection page for details on the topic
The SqlQueryService class provides methods to execute raw sql queries against the local (on-device) database.
Properties
Methods
Constructor
App Types
No properties
Don't instantiate directly instances of the SqlQueryServiceclass.
SqlQueryService instances are automatically injected by Dynamics Mobile framework.
import { View, SqlQueryService } from '$dms';
import { Customer } from '$dms-bo';
@View()
export class MyView {
constructor(
//we need to only declare the member
private SqlQueryService: SqlQueryService
){
}
async load(){
//we can now use the injected instance
let value = await this.SqlQueryService.execute(`select * from ${Customer.boTableName}}`);
}
}
📳
Avoid using SqlQueryService directly as it uses raw (low-level) sql query and does not return business entities.
Use DbQuery class for more cases. See also BusinessObjectBase class
Description
Parameters
Returns
Example
execute method performs query execution of the sql statement provided as argument against the local on-device database and returns array of flat typescript objects.
- array of "flat" javascript objects, where each javascript object represent the affected records , when the sql parameter represents "select" sql clause. If the sql parameter represents sql clause other than "select", the method returns undefined.
mport { SqlQueryService } from '@dms';
import { Customer } from '@dms-bo';
...
var records = await this.SqlQueryService.execute(`select * from ${Customer.boTableName}`);
records.forEach((record)=>{
console.log(`Customer name is ${records.name}`);
});
import { View, SqlQueryService } from '@dms';
import { Customer } from '@dms-bo';
// it is supposed that there is defined business object Customer in the Business Object folder
@View()
export class MyView {
constructor(private SqlQueryService: SqlQueryService){
}
async load(){
var records = await this.SqlQueryService.execute(`select * from ${Customer.boTableName}`);
records.forEach(function(records){
console.log(`Customer name is ${record.name}`);
});
}
}
Last modified 3yr ago