Get a blog post (testing mysql connection)
This commit is contained in:
parent
19c3c49f4d
commit
5a0d0933ce
6 changed files with 20 additions and 7 deletions
|
@ -1,4 +1,6 @@
|
|||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using Dapper;
|
||||
using Website.Models;
|
||||
|
||||
namespace Website.Data
|
||||
|
@ -9,6 +11,13 @@ namespace Website.Data
|
|||
|
||||
public BlogRepository(DatabaseProvider dbProvider) => _dbProvider = dbProvider;
|
||||
|
||||
public Task<BlogPost> GetPost(int id) => Task.Run(() => new BlogPost{Id=id});
|
||||
public async Task<BlogPost> GetPostAsync(int id) {
|
||||
const string query = "SELECT * FROM blog_posts WHERE post_id=@id";
|
||||
using (var connection = _dbProvider.NewConnection()) {
|
||||
connection.Open();
|
||||
var result = await connection.QueryAsync<BlogPost>(query, new{id});
|
||||
return result.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue