-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for sparsevec type to EF Core
- Loading branch information
Showing
5 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Microsoft.EntityFrameworkCore.Storage; | ||
using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; | ||
using NpgsqlTypes; | ||
|
||
namespace Pgvector.EntityFrameworkCore; | ||
|
||
public class SparsevecTypeMapping : RelationalTypeMapping | ||
{ | ||
public static SparsevecTypeMapping Default { get; } = new(); | ||
|
||
public SparsevecTypeMapping() : base("sparsevec", typeof(SparseVector)) { } | ||
|
||
public SparsevecTypeMapping(string storeType) : base(storeType, typeof(SparseVector)) { } | ||
|
||
protected SparsevecTypeMapping(RelationalTypeMappingParameters parameters) : base(parameters) { } | ||
|
||
protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) | ||
=> new SparsevecTypeMapping(parameters); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Pgvector.EntityFrameworkCore/SparsevecTypeMappingSourcePlugin.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Microsoft.EntityFrameworkCore.Storage; | ||
|
||
namespace Pgvector.EntityFrameworkCore; | ||
|
||
public class SparsevecTypeMappingSourcePlugin : IRelationalTypeMappingSourcePlugin | ||
{ | ||
public RelationalTypeMapping? FindMapping(in RelationalTypeMappingInfo mappingInfo) | ||
=> mappingInfo.ClrType == typeof(SparseVector) | ||
? new SparsevecTypeMapping(mappingInfo.StoreTypeName ?? "sparsevec") | ||
: null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters