0

I have function in which I want to return an Observable as my query result. I am making a SQLite Query and I want to return the result in an Observable. I tried putting the Observable.of outside at the first Promise function but it did not work. This is my code.

GetCustomers(FilterOptions: any): Observable<any> { 

            return Observable.of(this.platform.ready().then(() => { //WRONG CODE

                 this.SQLObj.executeSql("select * from customers, {}).then((res) => {
                    console.log(res);
                });

            })).map(cust => {
                // MODIFY THE RESULT AND CREATE NEW OBJECT.
                return JSON.stringify(cust);
            })

        }

Basically I want to return an Observable with nested promises but before that I want to modify and customize the resulted data of the SQL Query. What is the best way to do it.

1 Answer 1

1

I think this should work as you want.

Observable.fromPromise(this.platform.ready())
.switchMap(() => Observable.fromPromise(this.SQLObj.executeSql("select * from customers", {})))
.map((cust) => JSON.stringify(cust));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.