SqlQueryService
SqlQueryService TypeScript Class Reference

Overview

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.
1
import { View, SqlQueryService } from '$dms';
2
import { Customer } from '$dms-bo';
3
4
@View()
5
export class MyView {
6
7
constructor(
8
//we need to only declare the member
9
private SqlQueryService: SqlQueryService
10
){
11
12
}
13
14
async load(){
15
//we can now use the injected instance
16
let value = await this.SqlQueryService.execute(`select * from ${Customer.boTableName}}`);
17
}
18
19
}
Copied!
📳
Mobile
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

execute(sql: string): Promise<Array<any>>

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.
1
mport { SqlQueryService } from '@dms';
2
import { Customer } from '@dms-bo';
3
4
...
5
6
var records = await this.SqlQueryService.execute(`select * from ${Customer.boTableName}`);
7
records.forEach((record)=>{
8
console.log(`Customer name is ${records.name}`);
9
});
Copied!

How to use

1
import { View, SqlQueryService } from '@dms';
2
import { Customer } from '@dms-bo';
3
4
// it is supposed that there is defined business object Customer in the Business Object folder
5
6
@View()
7
export class MyView {
8
9
constructor(private SqlQueryService: SqlQueryService){
10
11
}
12
13
async load(){
14
var records = await this.SqlQueryService.execute(`select * from ${Customer.boTableName}`);
15
records.forEach(function(records){
16
console.log(`Customer name is ${record.name}`);
17
});
18
}
19
20
}
Copied!
Last modified 1yr ago