Windows 10 Universal App SQLite

I am currently trying to connect a working Windows 8 application to a Windows 10 UAP application. In my Windows 8 application, I heavily used this shell and SQLite library: https://github.com/doo/SQLite3-WinRT . However, after adding SQLite3-WinRT to my Windows 10 UAP application in accordance with the installation instructions in the readme repo, I get the "WinJS not defined" error from the SQLite3.js source file, which I added to the my / js directory in the application (as it works fine in a windows 8 app). Am I doing something wrong here, or is this wild SQLite3-WinRT not working with Win 10 UAP, and is there any better way to use SQLite in a Windows 10 UAP application for JavaScript? Many thanks!

+4
source share
2 answers

I tried using https://github.com/doo/SQLite3-WinRT on Windows 10 and found that VS2015 Community Edition could not even load the project. Every time I tried to load it, VS crashes with the "unloading project" displayed on the status bar. Killing him through the task manager was the only way out.

I found this sample application that implements SQLite in a generic application. This compiles and works fine for me on Windows 10, although I had to update the links to SQLite 3.8.4.3 with the version I had, SQLite 3.8.11.1

  • Download and unzip SQLite Universal JavaScript Example
  • Open in Visual Studio
  • Click on the Joint Application project group
  • Expand SQLite.Windows> Links
  • Delete link to "SQLite.WinRT81, Version = 3.8.4.3
  • Right Click> Add Link
  • In Windows 8.1> Extensions, select "SQLite for Windows Runtime (Windows 8.1)
  • Expand SQLite.WindowsPhone> Links
  • Delete link to "SQLite.WP81, Version = 3.8.5
  • Right Click> Add Link
  • In Windows 8.1> Extensions, select "SQLite for Windows Runtime (Windows 8.1)
  • Compile
+4
source

If you are looking for a step-by-step procedure, you can see this post .

You can use it with:

  • Windows 10: SQLite for Universal Application Platform
  • Windows Phone 8.1: SQLite for Windows Phone 8.1
  • Windows 8.1: SQLite for Windows Runtime (Windows 8.1)

After configuring packages and extensions, you can create a database and model classes using:

using System.IO; using System.Threading.Tasks; using SQLiteModernApp.DataModel; using SQLite.Net.Async; using System; using SQLite.Net; using SQLite.Net.Platform.WinRT; namespace SQLiteModernApp.DataAccess { public class DbConnection : IDbConnection { string dbPath; SQLiteAsyncConnection conn; public DbConnection() { dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Sample.sqlite"); var connectionFactory = new Func<SQLiteConnectionWithLock>(() => new SQLiteConnectionWithLock(new SQLitePlatformWinRT(), new SQLiteConnectionString(dbPath, storeDateTimeAsTicks: false))); conn = new SQLiteAsyncConnection(connectionFactory); } public async Task InitializeDatabase() { await conn.CreateTableAsync<Department>(); await conn.CreateTableAsync<Employee>(); await conn.CreateTableAsync<EmployeeDepartment>(); } public SQLiteAsyncConnection GetAsyncConnection() { return conn; } } } 

Now you can create a CRUD, following the example:

 using System.Collections.Generic; using System.Threading.Tasks; using SQLite.Net.Async; using SQLiteModernApp.DataAccess; using SQLiteModernApp.DataModel; using SQLiteNetExtensionsAsync.Extensions; namespace SQLiteModernApp.Repository { public class EmployeeRepository : IEmployeeRepository { SQLiteAsyncConnection conn; public EmployeeRepository(IDbConnection oIDbConnection) { conn = oIDbConnection.GetAsyncConnection(); } public async Task InsertEmployeeAsync(Employee employee) { await conn.InsertOrReplaceWithChildrenAsync(employee); } public async Task UpdateEmployeeAsync(Employee employee) { await conn.UpdateWithChildrenAsync(employee); } public async Task DeleteEmployeeAsync(Employee employee) { await conn.DeleteAsync(employee); } public async Task<List<Employee>> SelectAllEmployeesAsync() { return await conn.GetAllWithChildrenAsync<Employee>(); } public async Task<List<Employee>> SelectEmployeesAsync(string query) { return await conn.QueryAsync<Employee>(query); } } } 
0
source

All Articles