mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 增加 pgsql 索引 B_Tree, Hash, GiST, GIN, SP_GiST, BRIN;
This commit is contained in:
parent
bd71dfd80b
commit
7964785243
@ -19,7 +19,6 @@ using System.ComponentModel;
|
||||
using System.Data.Common;
|
||||
using System.Data.Odbc;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data.SQLite;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
@ -35,7 +34,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace base_entity
|
||||
{
|
||||
static class Program
|
||||
static partial class Program
|
||||
{
|
||||
class TestConfig
|
||||
{
|
||||
@ -62,11 +61,6 @@ namespace base_entity
|
||||
|
||||
static AsyncLocal<IUnitOfWork> _asyncUow = new AsyncLocal<IUnitOfWork>();
|
||||
|
||||
public class TestEnumCls
|
||||
{
|
||||
public CollationTypeEnum val { get; set; } = CollationTypeEnum.Binary;
|
||||
}
|
||||
|
||||
class Sys_reg_user
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
@ -590,11 +584,13 @@ namespace base_entity
|
||||
//.UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper)
|
||||
|
||||
//.UseConnectionString(FreeSql.DataType.OdbcDameng, "Driver={DM8 ODBC DRIVER};Server=127.0.0.1:5236;Persist Security Info=False;Trusted_Connection=Yes;UID=USER1;PWD=123456789")
|
||||
.UseConnectionString(DataType.QuestDb, "host=localhost;port=8812;username=admin;password=quest;database=qdb;ServerCompatibilityMode=NoTypeLoading;")
|
||||
//.UseConnectionString(DataType.QuestDb, "host=localhost;port=8812;username=admin;password=quest;database=qdb;ServerCompatibilityMode=NoTypeLoading;")
|
||||
.UseMonitorCommand(cmd =>
|
||||
{
|
||||
Console.WriteLine(cmd.CommandText + "\r\n");
|
||||
//cmd.CommandText = null; //不执行
|
||||
|
||||
//if (cmd.CommandText.StartsWith(""))
|
||||
})
|
||||
.UseLazyLoading(true)
|
||||
.UseGenerateCommandParameterWithLambda(true)
|
||||
@ -602,6 +598,19 @@ namespace base_entity
|
||||
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
|
||||
#endregion
|
||||
|
||||
test_pgsql(fsql);
|
||||
|
||||
var sqliteConnection = new Microsoft.Data.Sqlite.SqliteConnection("data source=123.db");
|
||||
using(var sqliteSql = new FreeSqlBuilder()
|
||||
.UseConnectionFactory(DataType.Sqlite,() => sqliteConnection)
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseMonitorCommand(cmd => Console.WriteLine(cmd.CommandText))
|
||||
.Build())
|
||||
{
|
||||
sqliteSql.Insert(new User1 { Avatar = "xxxavatar" }).ExecuteAffrows();
|
||||
var xkdkd = sqliteSql.Select<User1>().ToList();
|
||||
}
|
||||
|
||||
var qr1 = fsql.SelectLongSequence(10, () => new
|
||||
{
|
||||
rndstr = QuestFunc.rnd_str(10, 5, 10, 0),
|
||||
|
@ -3,6 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
@ -15,6 +16,7 @@
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="Npgsql.NetTopologySuite" Version="6.0.4" />
|
||||
<PackageReference Include="MessagePack" Version="2.4.35" />
|
||||
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -32,7 +34,7 @@
|
||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Oracle\FreeSql.Provider.Oracle.csproj" />
|
||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.PostgreSQL\FreeSql.Provider.PostgreSQL.csproj" />
|
||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.QuestDb\FreeSql.Provider.QuestDb.csproj" />
|
||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Sqlite\FreeSql.Provider.Sqlite.csproj" />
|
||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.SqliteCore\FreeSql.Provider.SqliteCore.csproj" />
|
||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.SqlServer\FreeSql.Provider.SqlServer.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
25
Examples/base_entity/pgsql_test.cs
Normal file
25
Examples/base_entity/pgsql_test.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using NetTopologySuite.Geometries;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace base_entity
|
||||
{
|
||||
partial class Program
|
||||
{
|
||||
public static void test_pgsql(IFreeSql fsql)
|
||||
{
|
||||
var ddl = fsql.CodeFirst.GetComparisonDDLStatements<gistIndex>();
|
||||
}
|
||||
}
|
||||
|
||||
[Index("sidx_zjds_geom", nameof(Geom), IndexMethod = IndexMethod.GiST)]
|
||||
class gistIndex
|
||||
{
|
||||
public int bb { get; set; }
|
||||
public LineString Geom { get; set; }
|
||||
}
|
||||
}
|
@ -800,5 +800,14 @@
|
||||
<param name="that"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
||||
<summary>
|
||||
批量注入 Repository,可以参考代码自行调整
|
||||
</summary>
|
||||
<param name="services"></param>
|
||||
<param name="globalDataFilter"></param>
|
||||
<param name="assemblies"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
@ -47,5 +47,16 @@ namespace FreeSql.DataAnnotations
|
||||
/// 是否唯一
|
||||
/// </summary>
|
||||
public bool IsUnique { get => _IsUnique ?? false; set => _IsUnique = value; }
|
||||
|
||||
/// <summary>
|
||||
/// 索引类型<para></para>
|
||||
/// 暂时只有 FreeSql.Provider.PostgreSQL 有效
|
||||
/// </summary>
|
||||
public IndexMethod IndexMethod { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 暂时只有 FreeSql.Provider.PostgreSQL 有效
|
||||
/// </summary>
|
||||
public enum IndexMethod { B_Tree, Hash, GiST, GIN, SP_GiST, BRIN }
|
||||
}
|
||||
|
@ -367,6 +367,17 @@
|
||||
是否唯一
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.DataAnnotations.IndexAttribute.IndexMethod">
|
||||
<summary>
|
||||
索引类型<para></para>
|
||||
暂时只有 FreeSql.Provider.PostgreSQL 有效
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:FreeSql.DataAnnotations.IndexMethod">
|
||||
<summary>
|
||||
暂时只有 FreeSql.Provider.PostgreSQL 有效
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:FreeSql.DataAnnotations.NavigateAttribute">
|
||||
<summary>
|
||||
OneToOne:[Navigate(nameof(Primary))] <-> (缺省)外表.Primary<para></para>
|
||||
@ -1073,82 +1084,6 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder">
|
||||
<summary>
|
||||
动态创建实体类型
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.#ctor(IFreeSql,System.String,System.Attribute[])">
|
||||
<summary>
|
||||
配置Class
|
||||
</summary>
|
||||
<param name="className">类名</param>
|
||||
<param name="attributes">类标记的特性[Table(Name = "xxx")] [Index(xxxx)]</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.Property(System.String,System.Type,System.Attribute[])">
|
||||
<summary>
|
||||
配置属性
|
||||
</summary>
|
||||
<param name="propertyName">属性名称</param>
|
||||
<param name="propertyType">属性类型</param>
|
||||
<param name="attributes">属性标记的特性-支持多个</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.Property(System.String,System.Type,System.Boolean,System.Attribute[])">
|
||||
<summary>
|
||||
配置属性
|
||||
</summary>
|
||||
<param name="propertyName">属性名称</param>
|
||||
<param name="propertyType">属性类型</param>
|
||||
<param name="isOverride">该属性是否重写父类属性</param>
|
||||
<param name="attributes">属性标记的特性-支持多个</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.Property(System.String,System.Type,System.Boolean,System.Object,System.Attribute[])">
|
||||
<summary>
|
||||
配置属性
|
||||
</summary>
|
||||
<param name="propertyName">属性名称</param>
|
||||
<param name="propertyType">属性类型</param>
|
||||
<param name="isOverride">该属性是否重写父类属性</param>
|
||||
<param name="defaultValue">属性默认值</param>
|
||||
<param name="attributes">属性标记的特性-支持多个</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.Extend(System.Type)">
|
||||
<summary>
|
||||
配置父类
|
||||
</summary>
|
||||
<param name="superClass">父类类型</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.OverrideProperty(System.Reflection.Emit.TypeBuilder@,System.Reflection.Emit.MethodBuilder,FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.PropertyMethodEnum,System.String)">
|
||||
<summary>
|
||||
Override属性
|
||||
</summary>
|
||||
<param name="typeBuilder"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.Build">
|
||||
<summary>
|
||||
Emit动态创建出Class - Type
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.FirstCharToLower(System.String)">
|
||||
<summary>
|
||||
首字母小写
|
||||
</summary>
|
||||
<param name="input"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.FirstCharToUpper(System.String)">
|
||||
<summary>
|
||||
首字母大写
|
||||
</summary>
|
||||
<param name="input"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Extensions.EntityUtil.EntityUtilExtensions.GetEntityKeyString(IFreeSql,System.Type,System.Object,System.Boolean,System.String)">
|
||||
<summary>
|
||||
获取实体的主键值,以 "*|_,[,_|*" 分割,当任意一个主键属性无值时,返回 null
|
||||
@ -5799,28 +5734,6 @@
|
||||
请使用 fsql.InsertDict(dict) 方法插入字典数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSqlGlobalDynamicEntityExtensions.DynamicEntity(FreeSql.ICodeFirst,System.String,System.Attribute[])">
|
||||
<summary>
|
||||
动态构建Class Type
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSqlGlobalDynamicEntityExtensions.CreateInstance(FreeSql.Internal.Model.TableInfo,System.Collections.Generic.Dictionary{System.String,System.Object})">
|
||||
<summary>
|
||||
根据字典,创建 table 对应的实体对象
|
||||
</summary>
|
||||
<param name="table"></param>
|
||||
<param name="dict"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSqlGlobalDynamicEntityExtensions.CreateDictionary(FreeSql.Internal.Model.TableInfo,System.Object)">
|
||||
<summary>
|
||||
根据实体对象,创建 table 对应的字典
|
||||
</summary>
|
||||
<param name="table"></param>
|
||||
<param name="instance"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSqlGlobalExpressionCallExtensions.Between(System.DateTime,System.DateTime,System.DateTime)">
|
||||
<summary>
|
||||
C#: that >= between && that <= and<para></para>
|
||||
|
@ -386,7 +386,7 @@ namespace FreeSql.Internal
|
||||
if (!string.IsNullOrEmpty(idxattr.Name) && !string.IsNullOrEmpty(idxattr.Fields))
|
||||
{
|
||||
if (ret.ContainsKey(idxattr.Name)) ret.Remove(idxattr.Name);
|
||||
ret.Add(idxattr.Name, new IndexAttribute(idxattr.Name, idxattr.Fields) { _IsUnique = idxattr._IsUnique });
|
||||
ret.Add(idxattr.Name, new IndexAttribute(idxattr.Name, idxattr.Fields) { _IsUnique = idxattr._IsUnique, IndexMethod = idxattr.IndexMethod });
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -397,7 +397,7 @@ namespace FreeSql.Internal
|
||||
if (!string.IsNullOrEmpty(idxattr.Name) && !string.IsNullOrEmpty(idxattr.Fields))
|
||||
{
|
||||
if (ret.ContainsKey(idxattr.Name)) ret.Remove(idxattr.Name);
|
||||
ret.Add(idxattr.Name, new IndexAttribute(idxattr.Name, idxattr.Fields) { _IsUnique = idxattr._IsUnique });
|
||||
ret.Add(idxattr.Name, new IndexAttribute(idxattr.Name, idxattr.Fields) { _IsUnique = idxattr._IsUnique, IndexMethod = idxattr.IndexMethod });
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -410,7 +410,7 @@ namespace FreeSql.Internal
|
||||
if (!string.IsNullOrEmpty(idxattr.Name) && !string.IsNullOrEmpty(idxattr.Fields))
|
||||
{
|
||||
if (ret.ContainsKey(idxattr.Name)) ret.Remove(idxattr.Name);
|
||||
ret.Add(idxattr.Name, new IndexAttribute(idxattr.Name, idxattr.Fields) { _IsUnique = idxattr._IsUnique });
|
||||
ret.Add(idxattr.Name, new IndexAttribute(idxattr.Name, idxattr.Fields) { _IsUnique = idxattr._IsUnique, IndexMethod = idxattr.IndexMethod });
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -11,6 +11,7 @@ namespace FreeSql.Internal.Model
|
||||
public string Name { get; set; }
|
||||
public IndexColumnInfo[] Columns { get; set; }
|
||||
public bool IsUnique { get; set; }
|
||||
public IndexMethod IndexMethod { get; set; }
|
||||
}
|
||||
|
||||
public class IndexColumnInfo
|
||||
|
@ -458,7 +458,8 @@ namespace FreeSql.Internal
|
||||
{
|
||||
Name = dbidx.Key,
|
||||
Columns = indexColumns.ToArray(),
|
||||
IsUnique = dbidx.Value.IsUnique
|
||||
IsUnique = dbidx.Value.IsUnique,
|
||||
IndexMethod = IndexMethod.B_Tree
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -493,7 +494,8 @@ namespace FreeSql.Internal
|
||||
{
|
||||
Name = indexName,
|
||||
Columns = indexColumns.ToArray(),
|
||||
IsUnique = index.IsUnique
|
||||
IsUnique = index.IsUnique,
|
||||
IndexMethod = index.IndexMethod
|
||||
});
|
||||
}
|
||||
trytb.Indexes = indexesDict.Values.ToArray();
|
||||
|
@ -1,4 +1,5 @@
|
||||
using FreeSql.Internal;
|
||||
using FreeSql.DataAnnotations;
|
||||
using FreeSql.Internal;
|
||||
using FreeSql.Internal.Model;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Npgsql.LegacyPostgis;
|
||||
@ -210,7 +211,9 @@ namespace FreeSql.PostgreSQL
|
||||
if (uk.IsUnique) sb.Append("UNIQUE ");
|
||||
sb.Append("INDEX ");
|
||||
if (isPg95) sb.Append("IF NOT EXISTS ");
|
||||
sb.Append(_commonUtils.QuoteSqlName(ReplaceIndexName(uk.Name, tbname[1]))).Append(" ON ").Append(createTableName).Append("(");
|
||||
sb.Append(_commonUtils.QuoteSqlName(ReplaceIndexName(uk.Name, tbname[1]))).Append(" ON ").Append(createTableName);
|
||||
if (uk.IndexMethod != IndexMethod.B_Tree) sb.Append(" USING ").Append(uk.IndexMethod.ToString().ToUpper().Replace("_", ""));
|
||||
sb.Append("(");
|
||||
foreach (var tbcol in uk.Columns)
|
||||
{
|
||||
sb.Append(_commonUtils.QuoteSqlName(tbcol.Column.Attribute.Name));
|
||||
@ -403,7 +406,9 @@ where ns.nspname in ({{0}}) and d.relname in ({{1}}) and a.indisprimary = 'f'",
|
||||
if (uk.IsUnique) sbalter.Append("UNIQUE ");
|
||||
sbalter.Append("INDEX ");
|
||||
if (isPg95) sbalter.Append("IF NOT EXISTS ");
|
||||
sbalter.Append(_commonUtils.QuoteSqlName(ukname)).Append(" ON ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append("(");
|
||||
sbalter.Append(_commonUtils.QuoteSqlName(ukname)).Append(" ON ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}"));
|
||||
if (uk.IndexMethod != IndexMethod.B_Tree) sbalter.Append(" USING ").Append(uk.IndexMethod.ToString().ToUpper().Replace("_", ""));
|
||||
sbalter.Append("(");
|
||||
foreach (var tbcol in uk.Columns)
|
||||
{
|
||||
sbalter.Append(_commonUtils.QuoteSqlName(tbcol.Column.Attribute.Name));
|
||||
@ -500,7 +505,9 @@ where pg_namespace.nspname={0} and pg_class.relname={1} and pg_constraint.contyp
|
||||
if (uk.IsUnique) sb.Append("UNIQUE ");
|
||||
sb.Append("INDEX ");
|
||||
if (isPg95) sb.Append("IF NOT EXISTS ");
|
||||
sb.Append(_commonUtils.QuoteSqlName(ReplaceIndexName(uk.Name, tbname[1]))).Append(" ON ").Append(tablename).Append("(");
|
||||
sb.Append(_commonUtils.QuoteSqlName(ReplaceIndexName(uk.Name, tbname[1]))).Append(" ON ").Append(tablename);
|
||||
if (uk.IndexMethod != IndexMethod.B_Tree) sb.Append(" USING ").Append(uk.IndexMethod.ToString().ToUpper().Replace("_", ""));
|
||||
sb.Append("(");
|
||||
foreach (var tbcol in uk.Columns)
|
||||
{
|
||||
sb.Append(_commonUtils.QuoteSqlName(tbcol.Column.Attribute.Name));
|
||||
|
Loading…
x
Reference in New Issue
Block a user