capacitor-community / sqlite

⚡Capacitor plugin for native & electron SQLite databases.
MIT License
495 stars 118 forks source link

Can someone make a wiki for new developer to use this? #193

Closed chiqors closed 2 years ago

chiqors commented 2 years ago

Please, for god sake.. I am confused with the readme file.. What is going on?

jepiqueau commented 2 years ago

@chiqors thanks for looking at the plug-in. Can you develop a bit. Did you look at the documentation in the docs folder and at the application starters referenced in the readme. Which framework do you want to use ?

chiqors commented 2 years ago

i am developing application based on quasar framework. I would love to use this plugin. But, i don't know where to start.

jepiqueau commented 2 years ago

@chiqors I do not know the quasar framework but it is based on Vue framework so look at the vue-sqlite-app-starter and vue-sqlite-app this will help you to start. Are you looking for native app ( iOS, Android) or Electron. The Web part of the plug-in has been made to help for a quick test implementation before to move to native.

chiqors commented 2 years ago

i am looking for native app, android with the help of capacitor

jepiqueau commented 2 years ago

@chiqors I assume that you do not want to use Ionic/Vue so may be you can look at https://github.com/jepiqueau/vue-capacitor-sqlite-issue137 it could help you to start

jepiqueau commented 2 years ago

@chiqors did you succeed to do something ?

chiqors commented 2 years ago

i guess so.. i mught need to learn more of how sqlite work with js

jepiqueau commented 2 years ago

@chiqors ok if you have any question you are welcome. Some developers have successfully use it with Quasar.

tobiasmuecksch commented 2 years ago

To be honest, the documentation is really really confusing. Even for experienced developers. For example: When using the createConnection() method, you need to specify several parameters. The third is called mode. I'm scanning through the documentation to find a hint on what exactly this mode is, and which values I can give it. Until now, I had no luck....

jepiqueau commented 2 years ago

@tobiasmuecksch did you look at the API.md under the docs folder. There are also application staters for different frameworks which will guide you under https://github.com/jepiqueau. But all the links to the statère apps are also in the readme.md file

tobiasmuecksch commented 2 years ago

Sure I did. And I really appreciate the work, there massive amounts of stuff. But it is very complicated. For now I don't want a predefined singleton service. All I need to understand the core concepts is some examples about:

  1. How to create a connection
  2. How to setup a database
  3. How to query a database
  4. How does the versioning and upgrading work?
  5. Some best practices and advices (for example should a close a connection after every query, or can I leave them open for ever and re-use them)

I do understand, that most of these questions can be answered by looking at the provided demo code, but because the code very complicated, it takes hours to find even the simplest information.

In the meantime I found out, that mode can have these values: ["encryption", "secret", "newsecret"], but what is the difference? What does each value mean? Do I even have to provide that value if I set the encryption parameter to false?

jepiqueau commented 2 years ago

@tobiasmuecksch what is the framework you intent to use ?

tobiasmuecksch commented 2 years ago

In the end, I will use ionic/angular/cap3.

But I want to understand this plugin without any framework related information as far as possible. I only want to know how to use it with simple TypeScript. No singleton services or anything else. I want to create my own service.

tobiasmuecksch commented 2 years ago

The best introduction I could think of would look like this (just pseudo code, I know that most of it is wrong):


import {CapacitorSQLite, SQLiteConnection} form '@capacitor/sqlite';

// Establish connection
const connection = new SQLiteConnection(CapacitorSQLite);

// Setup database
json = '{ .... }'; // shortened
await connection.setupDatabase({databasename: 'users', schema: json, version: 2})
await connection.addUpgrade({databasename: 'users', statements: [{query: 'UPDATE TABLE'}], version: 2});

// get database specific connection 
const database = await connection.openDatabase({databasename: 'users', version: 2});

// Query the database
const result = await database.query('SELECT * FROM users WHERE username = ?', ['bob']);

A simple introduction like this would help to understand the core concepts quickly. Afterwards it would be way easier to understand what is happening in the example singleton service.