File tree 8 files changed +88
-3
lines changed
src/Pgvector.EntityFrameworkCore
8 files changed +88
-3
lines changed Original file line number Diff line number Diff line change
1
+ ## 0.2.2 (unreleased)
2
+
3
+ - Added support for scaffolding
4
+
1
5
## 0.2.1 (2024-06-25)
2
6
3
7
- Added support for ` halfvec ` and ` sparsevec ` types
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ namespace Pgvector.EntityFrameworkCore;
5
5
public class HalfvecTypeMappingSourcePlugin : IRelationalTypeMappingSourcePlugin
6
6
{
7
7
public RelationalTypeMapping ? FindMapping ( in RelationalTypeMappingInfo mappingInfo )
8
- => mappingInfo . ClrType == typeof ( HalfVector )
8
+ => mappingInfo . ClrType == typeof ( HalfVector ) || ( mappingInfo . ClrType == null && ( mappingInfo . StoreTypeNameBase ?? mappingInfo . StoreTypeName ) == "halfvec" )
9
9
? new HalfvecTypeMapping ( mappingInfo . StoreTypeName ?? "halfvec" )
10
10
: null ;
11
11
}
Original file line number Diff line number Diff line change 20
20
<None Include =" ..\..\LICENSE.txt" Pack =" true" PackagePath =" \" />
21
21
<None Include =" ..\..\README.md" Pack =" true" PackagePath =" \" />
22
22
<None Include =" ..\..\icon.png" Pack =" true" PackagePath =" \" />
23
+ <None Include =" build\**\*" Pack =" true" PackagePath =" build" />
23
24
<ProjectReference Include =" ..\Pgvector\Pgvector.csproj" />
24
25
<PackageReference Include =" Npgsql.EntityFrameworkCore.PostgreSQL" Version =" 8.0.0" />
25
26
</ItemGroup >
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ namespace Pgvector.EntityFrameworkCore;
5
5
public class SparsevecTypeMappingSourcePlugin : IRelationalTypeMappingSourcePlugin
6
6
{
7
7
public RelationalTypeMapping ? FindMapping ( in RelationalTypeMappingInfo mappingInfo )
8
- => mappingInfo . ClrType == typeof ( SparseVector )
8
+ => mappingInfo . ClrType == typeof ( SparseVector ) || ( mappingInfo . ClrType == null && ( mappingInfo . StoreTypeNameBase ?? mappingInfo . StoreTypeName ) == "sparsevec" )
9
9
? new SparsevecTypeMapping ( mappingInfo . StoreTypeName ?? "sparsevec" )
10
10
: null ;
11
11
}
Original file line number Diff line number Diff line change
1
+ using Microsoft . EntityFrameworkCore ;
2
+ using Microsoft . EntityFrameworkCore . Design ;
3
+ using Microsoft . EntityFrameworkCore . Scaffolding ;
4
+ using Npgsql . EntityFrameworkCore . PostgreSQL . Infrastructure ;
5
+ using System . Reflection ;
6
+
7
+ namespace Pgvector . EntityFrameworkCore ;
8
+
9
+ public class VectorCodeGeneratorPlugin : ProviderCodeGeneratorPlugin
10
+ {
11
+ private static readonly MethodInfo _useVectorMethodInfo
12
+ = typeof ( VectorDbContextOptionsBuilderExtensions ) . GetMethod (
13
+ nameof ( VectorDbContextOptionsBuilderExtensions . UseVector ) ,
14
+ [ typeof ( NpgsqlDbContextOptionsBuilder ) ] ) ! ;
15
+
16
+ public override MethodCallCodeFragment GenerateProviderOptions ( )
17
+ => new ( _useVectorMethodInfo ) ;
18
+ }
Original file line number Diff line number Diff line change
1
+ using Microsoft . EntityFrameworkCore . Design ;
2
+ using Microsoft . EntityFrameworkCore . Scaffolding ;
3
+ using Microsoft . EntityFrameworkCore . Storage ;
4
+ using Microsoft . Extensions . DependencyInjection ;
5
+
6
+ namespace Pgvector . EntityFrameworkCore ;
7
+
8
+ public class VectorDesignTimeServices : IDesignTimeServices
9
+ {
10
+ public virtual void ConfigureDesignTimeServices ( IServiceCollection serviceCollection )
11
+ => serviceCollection
12
+ . AddSingleton < IRelationalTypeMappingSourcePlugin , VectorTypeMappingSourcePlugin > ( )
13
+ . AddSingleton < IRelationalTypeMappingSourcePlugin , HalfvecTypeMappingSourcePlugin > ( )
14
+ . AddSingleton < IRelationalTypeMappingSourcePlugin , SparsevecTypeMappingSourcePlugin > ( )
15
+ . AddSingleton < IProviderCodeGeneratorPlugin , VectorCodeGeneratorPlugin > ( ) ;
16
+ }
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ namespace Pgvector.EntityFrameworkCore;
5
5
public class VectorTypeMappingSourcePlugin : IRelationalTypeMappingSourcePlugin
6
6
{
7
7
public RelationalTypeMapping ? FindMapping ( in RelationalTypeMappingInfo mappingInfo )
8
- => mappingInfo . ClrType == typeof ( Vector )
8
+ => mappingInfo . ClrType == typeof ( Vector ) || ( mappingInfo . ClrType == null && ( mappingInfo . StoreTypeNameBase ?? mappingInfo . StoreTypeName ) == "vector" )
9
9
? new VectorTypeMapping ( mappingInfo . StoreTypeName ?? "vector" )
10
10
: null ;
11
11
}
Original file line number Diff line number Diff line change
1
+ <Project >
2
+ <PropertyGroup >
3
+ <MSBuildAllProjects >$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects >
4
+ <EFCoreNpgsqlPgvectorFile >$(IntermediateOutputPath)EFCoreNpgsqlPgvector$(DefaultLanguageSourceExtension)</EFCoreNpgsqlPgvectorFile >
5
+ </PropertyGroup >
6
+ <Choose >
7
+ <When Condition =" '$(Language)' == 'F#'" >
8
+ <Choose >
9
+ <When Condition =" '$(OutputType)' == 'Exe' OR '$(OutputType)' == 'WinExe'" >
10
+ <PropertyGroup >
11
+ <CodeFragmentItemGroup >CompileBefore</CodeFragmentItemGroup >
12
+ </PropertyGroup >
13
+ </When >
14
+ <Otherwise >
15
+ <PropertyGroup >
16
+ <CodeFragmentItemGroup >CompileAfter</CodeFragmentItemGroup >
17
+ </PropertyGroup >
18
+ </Otherwise >
19
+ </Choose >
20
+ </When >
21
+ <Otherwise >
22
+ <PropertyGroup >
23
+ <CodeFragmentItemGroup >Compile</CodeFragmentItemGroup >
24
+ </PropertyGroup >
25
+ </Otherwise >
26
+ </Choose >
27
+ <Target Name =" AddEFCoreNpgsqlPgvector"
28
+ BeforeTargets =" CoreCompile"
29
+ DependsOnTargets =" PrepareForBuild"
30
+ Condition =" '$(DesignTimeBuild)' != 'True'"
31
+ Inputs =" $(MSBuildAllProjects)"
32
+ Outputs =" $(EFCoreNpgsqlPgvectorFile)" >
33
+ <ItemGroup >
34
+ <EFCoreNpgsqlPgvectorServices Include =" Microsoft.EntityFrameworkCore.Design.DesignTimeServicesReferenceAttribute" >
35
+ <_Parameter1 >Pgvector.EntityFrameworkCore.VectorDesignTimeServices, Pgvector.EntityFrameworkCore</_Parameter1 >
36
+ <_Parameter2 >Npgsql.EntityFrameworkCore.PostgreSQL</_Parameter2 >
37
+ </EFCoreNpgsqlPgvectorServices >
38
+ </ItemGroup >
39
+ <WriteCodeFragment AssemblyAttributes =" @(EFCoreNpgsqlPgvectorServices)"
40
+ Language =" $(Language)"
41
+ OutputFile =" $(EFCoreNpgsqlPgvectorFile)" >
42
+ <Output TaskParameter =" OutputFile" ItemName =" $(CodeFragmentItemGroup)" />
43
+ <Output TaskParameter =" OutputFile" ItemName =" FileWrites" />
44
+ </WriteCodeFragment >
45
+ </Target >
46
+ </Project >
You can’t perform that action at this time.
0 commit comments