-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added built-in support for the `ag_catalog.agtype` PostgreSQL type to Npgsql using a custom converter. This fixes #3 .
- Loading branch information
Showing
31 changed files
with
1,184 additions
and
616 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
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
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,42 @@ | ||
using System.Buffers; | ||
using System.Text; | ||
using ApacheAGE.Types; | ||
using Npgsql.Internal; | ||
|
||
namespace ApacheAGE.Converters | ||
{ | ||
#pragma warning disable NPG9001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. | ||
internal class AgtypeConverter: PgBufferedConverter<Agtype> | ||
{ | ||
public override bool CanConvert(DataFormat format, out BufferRequirements bufferRequirements) | ||
{ | ||
bufferRequirements = BufferRequirements.None; | ||
return format is DataFormat.Text; | ||
} | ||
|
||
/// <summary> | ||
/// Read agtype from its binary representation. | ||
/// </summary> | ||
/// <param name="reader"></param> | ||
/// <returns></returns> | ||
protected override Agtype ReadCore(PgReader reader) | ||
{ | ||
ReadOnlySequence<byte> textBytes = reader.ReadBytes(reader.CurrentRemaining); | ||
string text = Encoding.UTF8.GetString(textBytes); | ||
|
||
return new(text); | ||
} | ||
|
||
/// <summary> | ||
/// Write agtype to its binary representation. | ||
/// </summary> | ||
/// <param name="writer"></param> | ||
/// <param name="value"></param> | ||
protected override void WriteCore(PgWriter writer, Agtype value) | ||
{ | ||
byte[] bytes = Encoding.UTF8.GetBytes(value.GetString()); | ||
writer.WriteBytes(bytes); | ||
} | ||
} | ||
#pragma warning restore NPG9001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. | ||
} |
Oops, something went wrong.