Skip to content

Commit

Permalink
Read List and Enum with Dapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Giorgi committed Oct 4, 2023
1 parent a31dfbc commit 037e20b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DuckDB.NET.Test/DuckDBDataReaderEnumTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public override void Dispose()
base.Dispose();
}

enum Mood
internal enum Mood
{
Sad, Ok, Happy
}
Expand Down
19 changes: 19 additions & 0 deletions DuckDB.NET.Test/DuckDBDataReaderListTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Dapper;
using FluentAssertions;
using Xunit;

Expand Down Expand Up @@ -154,4 +155,22 @@ public void ReadListOfTimes()
var list = reader.GetFieldValue<List<TimeOnly>>(0);
list.Should().BeEquivalentTo(new List<TimeOnly> { new(12, 14, 16), new(18, 10, 12) });
}

[Fact]
public void ReadListWithDapper()
{
Command.CommandText = "CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');";
Command.ExecuteNonQuery();

var person = Connection.QueryFirst<Person>("SELECT [1, 2, 3] as Ids, 'happy' as Mood");

person.Ids.Should().BeEquivalentTo(new List<int> { 1, 2, 3 });
person.Mood.Should().Be(DuckDBDataReaderEnumTests.Mood.Happy);
}

class Person
{
public List<int> Ids { get; set; }
public DuckDBDataReaderEnumTests.Mood Mood { get; set; }
}
}

0 comments on commit 037e20b

Please sign in to comment.