Enexure.Sql.Dynamic
Dynamic Sql Generation
Install / Use
/learn @enexure/Enexure.Sql.DynamicREADME
Enexure.Sql.Dynamic
Dynamic Sql Generation Library
##How to use
All queryies start by creating a Query from a TabularDataSource this could be a table to a derived table (subquery).
var tableA = new Table("TableA").As("a");
var tableB = new Table("TableB").As("b");
var query = Query
.From(tableA)
.Join(tableB, Expression.Eq(tableA.Field("Id"), tableB.Field("Fk")))
.Where(Expression.Eq(tableA.Field("Id"), Expression.Const(1)))
.Select(tableA.Field("Id"), tableB.All());
The entire query api is immutable, which means copying and reusing parts of any query is easy.
var people = new Table("People").As("p");
var queryBase = Query.From(people);
var countQuery = queryBase.Select(Field.All.Count())
var resultsQuery = queryBase.Select(people.All());
Providers
Once you've constructed your query you need to use a provider to generate the DbCommand and SQL.
// Get the DbCommand
var command = TSqlProvider.GetCommand(query)
// Get the just SQL, great for debugging
var sql = TSqlProvider.GetSqlString(query);
The resulting SQL for the query above looks like the following.
select [a].[Id], [b].*
from [TableA] [a]
join [TableB] [b] on [a].[Id] = [b].[Fk]
where [a].[Id] = @p0
Related Skills
feishu-drive
339.1k|
things-mac
339.1kManage Things 3 via the `things` CLI on macOS (add/update projects+todos via URL scheme; read/search/list from the local Things database)
clawhub
339.1kUse the ClawHub CLI to search, install, update, and publish agent skills from clawhub.com
task-list
Platform to build admin panels, internal tools, and dashboards. Integrates with 25+ databases and any API.
