Skip to content

API Overview

Marcus Ackre Medina edited this page Sep 13, 2026 · 1 revision

API Reference

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.

Constructing a builder

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).

DatabaseType enum

Value Quoting
PostgreSQL "name"
MySQL `name`
SQLite "name"
SqlServer [name]

JoinType enum

Inner, Left, Right, Full, Cross

Sql — table and columns

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.

Sql — WHERE conditions

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

Sql — joins, ordering, paging

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.

Sql — building

Method Description
.Build() Returns the final SQL string, terminated with ;. Throws InvalidOperationException if .Table() was never called.

Values and escaping

  • Numeric and boolean values are inlined without quotes (bool1/0).
  • String values are single-quoted with ' and \ escaped.
  • null becomes NULL.
  • Table/column names are quoted per DatabaseType; raw conditions passed to .When() are not escaped — the caller is responsible for their safety.

Example

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;

Clone this wiki locally