mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Add DuckDb demo
This commit is contained in:
parent
fadafc463f
commit
5e1c601d69
@ -24,6 +24,12 @@ namespace OrmTest
|
||||
// 如果数据库不存在,则创建数据库
|
||||
db.DbMaintenance.CreateDatabase();
|
||||
|
||||
var xx=db.DbMaintenance.IsAnyTable("UserInfo001", false);
|
||||
var yy = db.DbMaintenance.GetColumnInfosByTableName("UserInfo001", false);
|
||||
foreach (var item in yy)
|
||||
{
|
||||
Console.WriteLine($"{item.DbColumnName} {item.DataType} IsIdentity:{item.IsIdentity} IsPrimarykey:{item.IsPrimarykey} IsNullable:{item.IsNullable} ");
|
||||
}
|
||||
// Initialize tables based on UserInfo001 entity class
|
||||
// 根据 UserInfo001 实体类初始化表
|
||||
db.CodeFirst.InitTables<UserInfo001>();
|
||||
@ -32,6 +38,8 @@ namespace OrmTest
|
||||
//表结构和类存在差异 初始化表
|
||||
db.CodeFirst.InitTables<UserInfo002>();
|
||||
|
||||
var dt=db.Ado.GetDataTable("select @id as id", new { id = 1 });
|
||||
|
||||
//Insert
|
||||
//插入
|
||||
var id=db.Insertable(new UserInfo001()
|
||||
|
12
Src/Asp.NetCore2/DuckDBTest/Class1.cs
Normal file
12
Src/Asp.NetCore2/DuckDBTest/Class1.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DuckDBTest
|
||||
{
|
||||
class Class1
|
||||
{
|
||||
}
|
||||
}
|
48
Src/Asp.NetCore2/DuckDBTest/DBHelper/DbHelper.cs
Normal file
48
Src/Asp.NetCore2/DuckDBTest/DBHelper/DbHelper.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper class for database operations
|
||||
/// 数据库操作的辅助类
|
||||
/// </summary>
|
||||
public class DbHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Get a new SqlSugarClient instance with specific configurations
|
||||
/// 获取具有特定配置的新 SqlSugarClient 实例
|
||||
/// </summary>
|
||||
/// <returns>SqlSugarClient instance</returns>
|
||||
public static SqlSugarClient GetNewDb()
|
||||
{
|
||||
//注册DLL防止找不到DLL
|
||||
InstanceFactory.CustomAssemblies = new System.Reflection.Assembly[] {
|
||||
typeof(SqlSugar.DuckDB.DuckDBProvider).Assembly };
|
||||
|
||||
//创建DB
|
||||
var db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
IsAutoCloseConnection = true,
|
||||
DbType = DbType.DuckDB,
|
||||
ConnectionString = "DataSource = train_services.db",
|
||||
LanguageType = LanguageType.Default//Set language
|
||||
|
||||
},
|
||||
it =>
|
||||
{
|
||||
// Logging SQL statements and parameters before execution
|
||||
// 在执行前记录 SQL 语句和参数
|
||||
it.Aop.OnLogExecuting = (sql, para) =>
|
||||
{
|
||||
Console.WriteLine(UtilMethods.GetNativeSql(sql, para));
|
||||
};
|
||||
});
|
||||
return db;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,40 +1,5 @@
|
||||
using SqlSugar;
|
||||
|
||||
using OrmTest;
|
||||
_1_CodeFirst.Init();
|
||||
Console.WriteLine("DEMO执行完成");
|
||||
Console.Read();
|
||||
/// <summary>
|
||||
/// Helper class for database operations
|
||||
/// 数据库操作的辅助类
|
||||
/// </summary>
|
||||
public class DbHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Database connection string
|
||||
/// 数据库连接字符串
|
||||
/// </summary>
|
||||
public readonly static string Connection = "DataSource = train_services.db";
|
||||
|
||||
/// <summary>
|
||||
/// Get a new SqlSugarClient instance with specific configurations
|
||||
/// 获取具有特定配置的新 SqlSugarClient 实例
|
||||
/// </summary>
|
||||
/// <returns>SqlSugarClient instance</returns>
|
||||
public static SqlSugarClient GetNewDb()
|
||||
{
|
||||
var db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
IsAutoCloseConnection = true,
|
||||
DbType = DbType.DuckDB,
|
||||
ConnectionString = Connection,
|
||||
LanguageType = LanguageType.Default//Set language
|
||||
|
||||
},
|
||||
it => {
|
||||
// Logging SQL statements and parameters before execution
|
||||
// 在执行前记录 SQL 语句和参数
|
||||
it.Aop.OnLogExecuting = (sql, para) =>
|
||||
{
|
||||
Console.WriteLine(UtilMethods.GetNativeSql(sql, para));
|
||||
};
|
||||
});
|
||||
return db;
|
||||
}
|
Loading…
Reference in New Issue
Block a user