Simplifies SQL database querying a bit
SqlClient creation:
var sqlClient = new SqlClient(regularConnectionString);
ExecuteNonQueryAsync:
var rowsAffected = await sqlClient.ExecuteNonQueryAsync(
"INSERT INTO dbo.Users (Username) VALUES (@username)",
new Dictionary<string, object>
{
{ "@username", "Vasile Pupkeanu" }
});
ExecuteReaderAsync:
var userList = await sql.ExecuteReaderAsync(
"SELECT Id, Username FROM dbo.Task WHERE Id = @id",
new Dictionary<string, object>
{
{ "@id", userId },
},
reader =>
{
var result = new List<User>();
while (reader.Read())
{
result.Add(new User
{
Id = reader.GetString(0),
Username = reader.GetString(1)
});
}
return result;
});
ExecuteScalarAsync:
var userName = await sql.ExecuteScalarAsync(
"SELECT Name FROM dbo.Task WHERE Id = @id",
new Dictionary<string, object>
{
{ "@id", userId },
});
ExecuteXmlReaderAsync:
var userList = await sql.ExecuteXmlReaderAsync(
"SELECT Id, Username FROM dbo.Task WHERE Id = @id",
new Dictionary<string, object>
{
{ "@id", userId },
},
xmlReader =>
{
var result = new List<User>();
// populate result object from the xmlReader
return result;
});
Syntax sugar is syntax sugar: it's not a necessary thing per se but it can improve code quality.
Prosecco is a available in a form of a NuGet package. Follow regular installation process to bring it to your project. https://www.nuget.org/packages/Prosecco/
Unit tests are available in Prosecco.Tests project.
The code is distributed under the MIT license.
Reporting an issue, proposing a feature, or asking a question are all great ways to improve software quality.
Here are a few important things that package contributors will expect to see in a new born GitHub issue:
- the relevant version of the package;
- the steps to reproduce;
- the expected result;
- the observed result;
- some code samples illustrating current inconveniences and/or proposed improvements.
Contribution is the best way to improve any project!
- Fork it!
- Create your feature branch (
git checkout -b my-new-feature
). - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
...or follow steps described in a nice fork guide by Karl Broman