-
Notifications
You must be signed in to change notification settings - Fork 0
API Overview
Marcus Ackre Medina edited this page Sep 13, 2026
·
1 revision
Namespace: MarcusMedina.Fluent.Data.Sql
The package exposes a single fluent builder class, Sql, plus two enums (DatabaseType, JoinType). There is no separate FluentSql entry point and no dedicated Insert/Update/Delete builders — Sql only builds SELECT statements.
| Member | Description |
|---|---|
new Sql(DatabaseType dbType) |
Creates a builder. dbType controls how table/column names are quoted ("name" for PostgreSQL/SQLite, `name` for MySQL, [name] for SQL Server). |
| Value | Quoting |
|---|---|
PostgreSQL |
"name" |
MySQL |
`name` |
SQLite |
"name" |
SqlServer |
[name] |
Inner, Left, Right, Full, Cross
| Method | Description |
|---|---|
.Table(name) |
Sets the FROM table. Required before .Build(). Throws ArgumentException if blank. |
.Select(params string[] columns) |
Sets the columns to select. Defaults to * if omitted or called with no arguments. |
Each condition method appends a clause and returns this for chaining. Conditions are combined with AND by default; call .Or() immediately before a condition to combine it with OR instead.
| Method | Generates |
|---|---|
.Is(field, value) |
field = value |
.IsNot(field, value) |
field <> value |
.Contains(field, value) |
field LIKE '%value%' |
.StartsWith(field, value) |
field LIKE 'value%' |
.EndsWith(field, value) |
field LIKE '%value' |
.In(field, params object[] values) |
field IN (...) |
.NotIn(field, params object[] values) |
field NOT IN (...) |
.Between(field, a, b) |
field BETWEEN a AND b |
.IsNull(field) |
field IS NULL |
.IsNotNull(field) |
field IS NOT NULL |
.When(rawCondition) |
Appends a raw, unescaped condition string, e.g. .When("age > 18")
|
.Or() |
Marks the next condition to be joined with OR instead of AND
|
| Method | Description |
|---|---|
.Join(table, on, type = JoinType.Inner) |
Adds a JOIN clause. Call after .Table(). |
.OrderBy(field, asc = true) |
Adds an ORDER BY field. Can be called multiple times. |
.Limit(count) |
Adds LIMIT (or FETCH NEXT on SQL Server). Throws if negative. |
.Offset(count) |
Adds OFFSET (or OFFSET ... ROWS on SQL Server). Throws if negative. |
| Method | Description |
|---|---|
.Build() |
Returns the final SQL string, terminated with ;. Throws InvalidOperationException if .Table() was never called. |
- Numeric and boolean values are inlined without quotes (
bool→1/0). - String values are single-quoted with
'and\escaped. -
nullbecomesNULL. - Table/column names are quoted per
DatabaseType; raw conditions passed to.When()are not escaped — the caller is responsible for their safety.
var sql = new Sql(DatabaseType.PostgreSQL)
.Table("users")
.Select("name", "age")
.Is("active", true)
.When("age > 18")
.OrderBy("name")
.Limit(10)
.Build();
// SELECT "name", "age" FROM "users" WHERE "active" = 1 AND age > 18 ORDER BY "name" ASC LIMIT 10;