-
Notifications
You must be signed in to change notification settings - Fork 244
/
Copy pathDapperDb.cs
31 lines (24 loc) · 923 Bytes
/
DapperDb.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System.Collections.Generic;
using System.Threading.Tasks;
using Dapper;
using Npgsql;
namespace PlatformBenchmarks;
public sealed class DapperDb
{
private readonly string _connectionString;
public DapperDb(AppSettings appSettings)
=> _connectionString = appSettings.ConnectionString;
[DapperAot, CacheCommand, StrictTypes, QueryColumns("id", "message")]
public async Task<List<FortuneUtf16>> LoadFortunesRows()
{
List<FortuneUtf16> result;
using (var db = new NpgsqlConnection(_connectionString))
{
// Note: don't need to open connection if only doing one thing; let dapper do it
result = (await db.QueryAsync<FortuneUtf16>("SELECT id, message FROM fortune")).AsList();
}
result.Add(new FortuneUtf16(id: 0, message: "Additional fortune added at request time." ));
result.Sort();
return result;
}
}