mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
- 增加 DuckDB 数据库支持;
This commit is contained in:
54
Providers/FreeSql.Provider.Duckdb/DuckdbProvider.cs
Normal file
54
Providers/FreeSql.Provider.Duckdb/DuckdbProvider.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using FreeSql.Internal;
|
||||
using FreeSql.Internal.CommonProvider;
|
||||
using FreeSql.Duckdb.Curd;
|
||||
using System;
|
||||
using System.Data.Common;
|
||||
using System.Threading;
|
||||
using System.Collections;
|
||||
using System.Numerics;
|
||||
|
||||
namespace FreeSql.Duckdb
|
||||
{
|
||||
|
||||
public class DuckdbProvider<TMark> : BaseDbProvider, IFreeSql<TMark>
|
||||
{
|
||||
static int _firstInit = 1;
|
||||
static void InitInternal()
|
||||
{
|
||||
if (Interlocked.Exchange(ref _firstInit, 0) == 1) //不能放在 static ctor .NetFramework 可能报初始化类型错误
|
||||
{
|
||||
Utils.dicExecuteArrayRowReadClassOrTuple[typeof(BigInteger)] = true;
|
||||
Utils.dicExecuteArrayRowReadClassOrTuple[typeof(BitArray)] = true;
|
||||
Select0Provider._dicMethodDataReaderGetValue[typeof(Guid)] = typeof(DbDataReader).GetMethod("GetGuid", new Type[] { typeof(int) });
|
||||
}
|
||||
}
|
||||
|
||||
public override ISelect<T1> CreateSelectProvider<T1>(object dywhere) => new DuckdbSelect<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere);
|
||||
public override IInsert<T1> CreateInsertProvider<T1>() => new DuckdbInsert<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||
public override IUpdate<T1> CreateUpdateProvider<T1>(object dywhere) => new DuckdbUpdate<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere);
|
||||
public override IDelete<T1> CreateDeleteProvider<T1>(object dywhere) => new DuckdbDelete<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere);
|
||||
public override IInsertOrUpdate<T1> CreateInsertOrUpdateProvider<T1>() => new DuckdbInsertOrUpdate<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||
|
||||
public DuckdbProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
|
||||
{
|
||||
InitInternal();
|
||||
this.InternalCommonUtils = new DuckdbUtils(this);
|
||||
this.InternalCommonExpression = new DuckdbExpression(this.InternalCommonUtils);
|
||||
|
||||
this.Ado = new DuckdbAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString, connectionFactory);
|
||||
this.Aop = new AopProvider();
|
||||
|
||||
this.CodeFirst = new DuckdbCodeFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||
this.DbFirst = new DuckdbDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||
if (connectionFactory != null) this.CodeFirst.IsNoneCommandParameter = true;
|
||||
}
|
||||
|
||||
~DuckdbProvider() => this.Dispose();
|
||||
int _disposeCounter;
|
||||
public override void Dispose()
|
||||
{
|
||||
if (Interlocked.Increment(ref _disposeCounter) != 1) return;
|
||||
(this.Ado as AdoProvider)?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user