[英]Windows 10 Universal App SQLite
I'm currently trying to port a working Windows 8 JavaScript app to a Windows 10 UAP app. 我目前正在尝试将工作的Windows 8 JavaScript应用程序移植到Windows 10 UAP应用程序。 In my Windows 8 app, I heavily used this SQLite wrapper and library: https://github.com/doo/SQLite3-WinRT .
在我的Windows 8应用程序中,我大量使用了这个SQLite包装器和库: https : //github.com/doo/SQLite3-WinRT 。 However, after adding SQLite3-WinRT to my Windows 10 UAP app as per the setup instructions in the readme of the repo, I get a "WinJS is not defined" error coming from the SQLite3.js source file that I added to my /js directory in the app (the way it works fine in the windows 8 app).
但是,根据repo自述文件中的设置说明将SQLite3-WinRT添加到我的Windows 10 UAP应用程序后,我收到来自我添加到my / js的SQLite3.js源文件的“WinJS未定义”错误应用程序中的目录(它在Windows 8应用程序中正常工作的方式)。 Am I doing something wrong here, or wild this SQLite3-WinRT not work with Win 10 UAP and is there some better way of using SQLite in a JavaScript Windows 10 UAP app?
我在这里做错了什么,或者这个SQLite3-WinRT无法与Win 10 UAP一起使用,是否有更好的方法在JavaScript Windows 10 UAP应用程序中使用SQLite? Thanks a lot!
非常感谢!
I tried using https://github.com/doo/SQLite3-WinRT on Windows 10 and found VS2015 Community Edition couldn't even load the project. 我尝试在Windows 10上使用https://github.com/doo/SQLite3-WinRT ,发现VS2015 Community Edition甚至无法加载项目。 Every time I tried to load it, VS would hang with "unloading project" showing in the status bar.
每次我尝试加载它时,VS都会挂起状态栏中显示的“卸载项目”。 Killing it via task manager was the only way out.
通过任务管理器杀死它是唯一的出路。
I found this sample app which implements SQLite in a Universal App. 我找到了这个在通用应用程序中实现SQLite的示例应用程序。 This compiles and runs fine for me on Windows 10, although I did have to update the references to SQLite 3.8.4.3 with the version I had, SQLite 3.8.11.1
这在Windows 10上为我编译并运行正常,尽管我必须使用我的版本更新对SQLite 3.8.4.3的引用,SQLite 3.8.11.1
If you are looking for a step by step procedure, you can take a look at this post . 如果您正在寻找一步一步的程序,您可以看一下这篇文章 。
You can use it with: 您可以使用它:
After setting up the packages and extensions, you are able to create the database and the models 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: 现在您可以按照示例创建一个CRUD:
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);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.