Created
June 13, 2016 14:35
-
-
Save tanner0101/20468c7fedd0d81687844b88edc1b1d2 to your computer and use it in GitHub Desktop.
Nancy Benchmark
This file contains hidden or 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
using System; | |
using System.IO; | |
using System.Linq; | |
using System.Reflection; | |
using Dapper; | |
using Microsoft.Data.Sqlite; | |
using Nancy; | |
namespace NancyVsVapor | |
{ | |
public class HomeModule : NancyModule | |
{ | |
private static string connstring = string.Concat("Data Source=", Path.Combine( | |
Path.GetDirectoryName(typeof(HomeModule).GetTypeInfo().Assembly.Location), | |
"test.sqlite")); | |
private static Random random = new Random(); | |
public HomeModule() | |
{ | |
Get("/plaintext", _ => "Hello, World!"); | |
Get("/json", _ => | |
{ | |
return Response.AsJson(new JsonModel()); | |
}); | |
Get("sqlite-fetch", async (_, __) => | |
{ | |
using (var conn = new SqliteConnection(connstring)) | |
{ | |
var users = await conn.QueryAsync<User>("select * from users where id = @id", new { id = random.Next(1, 3) }); | |
return Response.AsJson(users.FirstOrDefault()); | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment