
join ( DB_STORAGE_PATH, db_name ) conn = sqlite3. commit () # Get db connection to sqlite database using the parameter provided def get_db_connection ( db_name ): db_path = os. get_store_path ( 'db' ) # Create the database specified in the parameters provided def create_db ( db_name ): get_db_connection ( db_name ) # Execute the specified sql file against the database in the parameters provided def execute_schema_sql ( db_name, schema_file_path ): conn = get_db_connection ( db_name ) with conn : with open ( schema_file_path, mode = 'r' ) as schema_file : cur = conn. If it has a progressbar it would be better, but I'm not having success.Import os import sqlite3 from contextlib import closing from qpylib import qpylib DB_STORAGE_PATH = qpylib. My ideia is to populate the SQLite local db with the API data in the button click. Var prod = JsonConvert.DeserializeObject>(response) Recuperando os dados da API e deserializando Var response = await httpClient.GetStringAsync(apiPath + apiName) Var databasePath = Path.Combine(basePath, "localdb.db3") Īwait dataBase.CreateTableAsync(typeof(Propriedade)) //error goes here
#Sqlite json full#
That's is my full code: public string apiPath = " public string apiName I tried to implemente according you example, but the following error: System.TypeInitializationException: 'The type initializer for 'SQLite.SQLiteConnection' threw an exception.' in this part of the code: The following error is displaying: Unhanded Exception: System.TypeInitializationException: The type initializer for 'SQLite.SQLiteConnection' threw an exception Return "Banco de dados criado com sucesso" īut it didn't work. Var db = new SQLite.SQLiteAsyncConnection(caminho, SQLiteOpenFlags.Create | SQLiteOpenFlags.FullMutex | SQLiteOpenFlags.ReadWrite) Var products = await dataBase.Table().ToListAsync() Īwait DisplayAlert("Resultado", "Deu certo", "OK") Īwait DisplayAlert("Erro", "O seguinte erro ocorreu: " + ex.Message, "OK") Var response = await httpClient.GetStringAsync("locahost/api/products") Private void Button_Clicked(object sender, EventArgs e)ĭisplayAlert("Confirmação", CreateDb(dbPath), "OK") ĭataBase = new SQLiteAsyncConnection(dbPath) Īwait dataBase.CreateTableAsync(typeof(Models.Product))

Public string dbPath = Path.Combine(Environment.GetFolderPath(), "localdb.db3") That's what I did: SQLiteAsyncConnection dataBase Can you please share a sample of doing it in a button click event? My idea is to create a sync button to populate the local table.Īfter that, I'll get the data from the local table and show them in different screens, do you understand?
#Sqlite json code#
Thanks friend, I tried to implement this code in my application, but I think I did some mistake. I simply combine the database with the page here, you could separate it to a single constant class as the documentation did. Set it to your list view's items source if needed

Get the data from the database: var product = await dataBase.Table().ToListAsync() Var product = JsonConvert.DeserializeObject>(response) Var response = await httpClient.GetStringAsync("localhost/api/products") Then we could store the data which is retrieved from the api: public async void GetProduct() Var databasePath = Path.Combine(basePath, "SQLite.db3") ĭataBase = new SQLiteAsyncConnection(databasePath) Īwait dataBase.CreateTableAsync(typeof(Product)) Var basePath = Environment.GetFolderPath() Protected async override void OnAppearing() We could store the data directly into a local database using SQLite:įirstly, initialize the database: SQLiteAsyncConnection dataBase
