Git Product home page Git Product logo

Comments (5)

jepiqueau avatar jepiqueau commented on May 31, 2024 1

@eugenezhornyak
First thanks for using the plugin, i spent my afternoon to try understanding what is wrong. In fact the main reason is that the way you want to work with the plugin is questionable. In fact, the sqliteService instance use in DatabaseInitializationService and the one ProductsRepositoryService is not the same meaning that the

res = mDb.querySQL(statement, new ArrayList<String>());
``` in the CapacitorSQLite.java file  the mDb is null as the open method has not been called for that instance.

The way you make your `readAll()` method in `ProductsRepositoryService` is wrong. It should be 

async readAll(): Promise<Product[]> {
/*
return this.executeIfDbExist(this.selectAllCommand).then(result => {
console.log('Read products result:' + JSON.stringify(result));
return result;
});
*/
return await this.sqliteService.query(this.selectAllCommand);
}

YOU DO NOT REALLY NEED TO EXECUTE executeIfDbExist
as when you run the database.initialization.service.initializeDatabase()
if it return false you do not execute in Home page the refreshData()
if you still do it, it will slow down the app for nothing

I didn't find the way to make the SQLiteService a singleton through the app. 

From Angular doc

Providing a singleton service
There are two ways to make a service a singleton in Angular:

  • Set the providedIn property of the @Injectable() to "root".
  • Include the service in the AppModule or in a module that is only imported by the AppModule
I have tried both but i did not find the way to make it working.

Look at `https://github.com/jepiqueau/angular-sqlite-app-starter` this one works, and build your application along that.
If you find the way to make the SQLiteService a singleton, i will be interested in

from sqlite.

jepiqueau avatar jepiqueau commented on May 31, 2024 1

@eugenezhornyak i have found the solution. I have to update first the android plugin to implement a listener for granted permissions and after this i will share the app.

from sqlite.

jepiqueau avatar jepiqueau commented on May 31, 2024 1

@eugenezhornyak have a look at https://github.com/jepiqueau/test-sqlite-issue51
You cannot instantiate DatabaseInitializationService in the ngAfterViewInit lifecycle event on the app.component as the router bring you straight forward in the Home page. Hope this will help.

from sqlite.

eugenezhornyak avatar eugenezhornyak commented on May 31, 2024

@jepiqueau Thank you for attention paid! Your solution is very helpful. My problem solved

from sqlite.

jepiqueau avatar jepiqueau commented on May 31, 2024

@eugenezhornyak Happy that everything works fine. i close the issue

from sqlite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.