Use Progress Data Source for NativeScript and Angular
- Last Updated: January 16, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
Description
The Progress Data Source is an object that connects an Angular application with a Progress Data Object Service. It allows you to perform CRUD operations on a Data Object Service in TypeScript. It is available as an npm package on http://www.npmjs.com.
The declaration file declares two classes:
- DataSource — This provides the integration layer to access the remote data resource. (Internally, it supports access to the JSDO.)
- DataSourceOptions — This provides options to a Data Source instance.
DataSourceOptions Properties
| Property | Type | Description |
|---|---|---|
| countFnName? | string |
|
| filter? | any |
|
| jsdo | progress.data.JSDO |
|
| mergeMode? | number | An integer that represents a merge mode to use.Possible values
are:
|
| readLocal? | boolean |
|
| skip? | number | Use it to specify how many records in the result set must be skipped before a page of data is returned. |
| sort? | any |
|
| tableRef? | string | It refers to the temp table that is to be
accessed as a resource. Note: This property is
required only if the specified jsdo represents a multi-table
DataSet. |
| top? | number | Use it to specify the number of records to be returned from the result set. |
DataSource Functions
| Function/API | Description | Input | Output |
|---|---|---|---|
| read(params?: progress.data.FilterOptions): Observable<DataResult> | It asynchronously retrieves data from the remote data resource. (Internally, it calls the jsdo.fill() method.) |
|
|
| getData(): <Array<object>> | It returns an array of record objects that currently resides in local memory | NA | Returns an array of record objects. |
| create(data: object): object | It creates a new record in local memory. | data: An object that contains the details of the new record. |
|
| findById(id: string): object | It returns a copy of the record with the specified ID. | id Note: The existing implementation of the function uses JSDO's
internal _id as the id property. |
|
| update(data: any): boolean | It updates a record in local memory. | data: An object that contains the updated details for the record. |
|
| remove(data: any): boolean | It deletes a record from local memory. | data: An object with a valid id of the record to be deleted. |
|
| hasCUDSupport(): boolean | It indicates whether CUD (Create, Update and Delete) support is available in the underlying JSDO. | NA |
|
| hasSubmitSupport(): boolean | It indicates whether the underlying JSDO has Submit support (that is, provides a Submit operation). | NA |
|
| saveChanges(): Observable<Array<object>> | It synchronizes the Data Object service with all the record changes (CUD) pending in local memory. It is an asynchronous call. | NA |
|
Example
The following example demonstrates how to instantiate a DataSource in TypeScript:
import { DataSource, DataSourceOptions } from "@progress/jsdo-nativescript";
import { progress } from "@progress/jsdo-core";
let jsdo:progress.data.JSDO,
session:progress.data.JSDOSession,
dataSource: DataSource;
progress.data.getSession({
serviceURI: uri,
catalogURI: catUri,
authenticationModel: "anonymous"
}).then((object) => {
session = object.jsdosession;
jsdo = new progress.data.JSDO({
name: "Customer"
});
dataSource = new DataSource({
jsdo: jsdo,
tableRef: "ttCustomer"
});
});
The following example demonstrates how to read
data:
// This is a read with a filter, the filter is not required
dataSource.read({
filter: {
field: 'State',
operator: 'eq',
value: 'HI'
}
}).subscribe((myData: DataResult) => {
// You can also loop through myData.data instead of calling dataSource.getData()
dataSource.getData().forEach(element => {
// print out each customers CustNum
console.log(element.CustNum);
})
});The following example demonstrates how to create a new
record:
dataSource.create({
CustNum: 100000,
Name: 'testName',
State: 'MA',
Balance: 0
});
// You have to call saveChanges for the changes to propagate to the backend
dataSource.saveChanges().subscribe((myData) => {
// process my data here
myData.data.forEach((elem) => console.log(elem));
}, (error: Error ) => {
// process error here
});The following example demonstrates how to update a record:
dataSource.getData().forEach(element => {
if (element.CustNum === 3000) {
element.Name = "TestUser Foo"
dataSource.update(element);
}
});
// You have to call saveChanges for the changes to propagate to the backend
dataSource.saveChanges().subscribe((myData) => {
// process data here
myData.data.forEach((elem) => console.log(elem));
}, (error: Error ) => {
// process error here
});
The following example demonstrates how to remove a record:
dataSource.getData().forEach(element => {
if (element.CustNum === 9000) {
dataSource.remove(element);
}
});
// You have to call saveChanges for the changes to propagate to the backend
dataSource.saveChanges().subscribe((myData) => {
// process data here
}, (error: Error ) => {
// process error here
});
Note:
saveChanges() only needs to be called when you are finished with
your local changes. You do not need to call it for each individual operation.