Ultra-minimalist driver-agnostic SQL library for C#
- Only async functions
- Only postion data parameters
Library uses a global profile for easily settings change.
StGlobal.DefaultProfile = new StProfile { CreateConnection = () => ... }; // Set default profile
async Task Func() {
StGlobal.ChangeProfileAsyncLocal(new StProfile { ... });
// Now work with another settings in this async context
}All examples for PostgreSQL
Query for simple and static queries.
await foreach (var rd in Query.ReadAllRows("SELECT * FROM table WHERE id=$1", 123)){
var id = rd.Val<long>("id");
}QueryBuilder for any complex or dynamic queries
var deleted_cnt = await new QueryBuilder("DELETE from table")
.WhereAndEq("val1", 10)
.WhereAndEq("val2", 20)
.ExecuteGetRowsTouched(); // SQL: DELETE from table WHERE (val1=$1) AND (val2=$2)Inserter for basic insert queries
var inserted_id = await new Inserter("table")
.SkipOnConflict()
.Value("id", 123)
.ExecuteReturnField<long?>("id"); // SQL: INSERT into table(id) VALUES ($1) on conflict do nothing returning id
if (inserted_id != null) {
Console.WriteLine($"Was inserted: {inserted_id}");
}IStDataConverter used for custom data conversions
AutoTransaction used for easy transactions
{
using var transaction = new AutoTransaction();
// do as usual
await transaction.CommitAsync();
}