Fluent SQL builder for Dapper
library.
- Install latest nuget packet
Sqlify.Dapper
from nuget.org:Install-Package Sqlify.Dapper
- Create per database table:
public interface IUsersTable : ITable { Column<int> Id { get; } Column<string> Name { get; } Column<int> Age { get; } }
- Write a query!
public void InsertExample(IDbConnection connection)
{
var u = Sql.Table<IUsersTable>();
InsertQuery query = Sql
.Insert(u)
.Values(u.Id, 1)
.Values(u.Name, "Adam")
.Values(u.Age, 30);
// INSERT INTO Users (Id, Name, Age) VALUES (@p1, @p2, @p3)
var result = connection.Execute(query); // Dapper's Execute method
}
public void UpdateExample(IDbConnection connection)
{
var u = Sql.Table<IUsersTable>();
UpdateQuery query = Sql
.Update(u)
.Set(u.Age, u.Age + 1);
// UPDATE Users SET Age = Users.Age + @p1
var result = connection.Execute(query); // Dapper's Execute methods
}
public void SelectExample(IDbConnection connection)
{
var u = Sql.Table<IUsersTable>();
SelectQuery query = Sql
.Select()
.From(u)
.Where(u.Age > 30);
// SELECT * FROM Users WHERE Users.Age > @p1
var result = connection.Query(query); // Dapper's Query method
}
public void DeleteExample(IDbConnection connection)
{
var u = Sql.Table<IUsersTable>();
DeleteQuery query = Sql
.Delete(u)
.Where(u.Id == 1);
// DELETE FROM Users WHERE Users.Id = @p1
var result = connection.Execute(query); // Dapper's Execute method
}
# build
dotnet build ./src
# running tests
dotnet test ./src
# pack
dotnet pack ./src -c=release