当前位置:网站首页>SQLite net (SQLite is used by unity, WPF and WinForm)
SQLite net (SQLite is used by unity, WPF and WinForm)
2022-06-27 16:55:00 【Wheezing】
Reference package
Search for sqlite-net Package and reference into the project ,unity Direct copy SQLite、SQLiteAsync Just go to the project
Add management class
public static class DatabaseHandler
{
private static string connstr = UnityEngine.Application.streamingAssetsPath + "/data.db"; // No database will create a database
public static SQLiteConnection db;
public static SQLiteAsyncConnection dbAsync;
static DatabaseHandler()
{
db = new SQLiteConnection(connstr, false);
dbAsync = new SQLiteAsyncConnection(connstr, false);
db.CreateTable<User>();
}
public static int Add(object model)
{
return db.Insert(model);
}
public static async Task<int> AddAsync(object model)
{
return await dbAsync.InsertAsync(model);
}
public static int Update(object model)
{
return db.Update(model);
}
public static async Task<int> UpdateAsync(object model)
{
return await dbAsync.UpdateAsync(model);
}
public static int Delete(object model)
{
return db.Delete(model);
}
public static async Task<int> DeleteAsync(object model)
{
return await dbAsync.DeleteAsync(model);
}
public static List<T> Query<T>(string sql) where T : new()
{
return db.Query<T>(sql);
}
public static async Task<List<T>> QueryAsync<T>(string sql) where T : new()
{
return await dbAsync.QueryAsync<T>(sql);
}
public static int Execute(string sql)
{
return db.Execute(sql);
}
public static async Task<int> ExecuteAsync(string sql)
{
return await dbAsync.ExecuteAsync(sql);
}
public static TableQuery<T> Table<T>() where T : new()
{
return db.Table<T>();
}
public static AsyncTableQuery<T> TableAsync<T>() where T : new()
{
return dbAsync.Table<T>();
}
}
[Table("user")]
public class User
{
[PrimaryKey, AutoIncrement]
[Column("id")]
public int Id {
get; set; }
[Column("name")]
public string Name {
get; set; }
}
Use
var users = await DatabaseHandler.TableAsync<User>().Where(x => x.Name == " test ")
.ToListAsync();
边栏推荐
- Realize simple three-D cube automatic rotation
- Leetcode daily practice (main elements)
- About MySQL: the phenomenon and background of the problem
- Ping An technology's practice of migrating from Oracle to ubisql
- Deeply digitise, lead cloud nativity and serve more developers
- Etcd visualization tool: kstone deployment (I), rapid deployment based on Helm
- Oracle概念二
- Mode setting of pulseaudio (21)
- Simulated process scheduling
- Handling method of occasional error reporting on overseas equipment
猜你喜欢

Data center table reports realize customized statistics, overtime leave summary record sharing

Leetcode daily practice (longest substring without repeated characters)

Leetcode daily practice (Yanghui triangle)
#yyds干货盘点#简述chromeV8引擎垃圾回收

What is the level 3 password complexity of ISO? How often is it replaced?

What is RPC
锚文本大量丢失的问题

About MySQL: the phenomenon and background of the problem

Leetcode daily practice (sum of two numbers)

Autodesk NavisWorks 2022 software installation package download and installation tutorial
随机推荐
[multithreading] thread communication scheduling, waiting set wait(), notify()
国家食品安全风险评估中心:不要盲目片面追捧标签为“零添加”“纯天然”食品
Solving Poisson equation by tensorflow
P4251 [scoi2015] small convex play matrix (still a little confused)
Source NAT address translation and server mapping web page configuration of firewall Foundation
Under the influence of external factors, how to manage internal resources and reduce costs is the key
数组表示若干个区间的集合,请你合并所有重叠的区间,并返回 一个不重叠的区间数组,该数组需恰好覆盖输入中的所有区间 。【LeetCodeHot100】
10 minutes to master the installation steps of MySQL
2022年中国音频市场年度综合分析
米哈游起诉五矿信托,后者曾被曝产品暴雷
d3dx9_ How to repair 32.dll? d3dx9_ Solution to 32.dll missing
Raspberry pie preliminary use
The European unified charging specification act was passed before the end of the year, and it is planned to expand to products such as laptop and keyboard
开源二三事|ShardingSphere 与 Database Mesh 之间不得不说的那些事
Qt5 signal and slot mechanism (demonstrate the correlation between the control's own signal and slot function)
The interview lasted for half a year. Last month, I successfully got Alibaba p7offer. It was all because I chewed the latest interview questions in 2020!
Unity 阴影——阴影平坠(Shadow pancaking)
d3dx9_ What if 27.dll is lost? d3dx9_ How to repair 27.dll?
What are the password requirements for waiting insurance 2.0? What are the legal bases?
防火墙基础之源NAT地址转换和服务器映射web页面配置