๐ InsertBuilder Developer Guide¶
Safe and validated INSERT builder with dialect injection and RETURNING support.
This document describes the behavior, constraints, and dialect integration strategy for Entiqon's InsertBuilder. It ensures insert operations are consistent, secure, and aligned with SQL engine-specific capabilities.
โ Overview¶
InsertBuilder constructs safe, parameterized SQL INSERT statements. It supports:
- Fluent configuration of table, columns, and values
- Multiple row insertion
- Dialect-specific identifier quoting
- Optional
RETURNINGclause (PostgreSQL, etc.)
๐งฑ Method Summary¶
| Method | Description |
|---|---|
NewInsert() |
Creates a new insert builder |
Into() |
Sets the table name |
Columns() |
Defines the column names (must match values) |
Values() |
Adds a row of values |
Returning() |
Sets fields for RETURNING clause (if supported) |
UseDialect() |
Injects a dialect by name (e.g., "postgres") |
Build() |
Renders full query + args |
BuildInsertOnly() |
Renders INSERT statement only (no RETURNING) |
๐ Column Aliases Are Not Allowed¶
Column aliasing (e.g., email AS contact) is rejected in InsertBuilder. If a column contains an alias, Build() returns an error:
Columns("email AS contact") // โ invalid
Aliases are meant for SELECT clauses and are not valid in INSERT column lists.
๐งฉ Dialect Integration¶
Use UseDialect("postgres") to apply dialect behavior:
- Quotes table and column names (e.g.,
"users","email") - Enables support for dialect-specific features like
RETURNING - Disallows
RETURNINGunless the dialect supports it
Example:
Insert().
Into("users").
Columns("email", "role").
Values("admin@example.com", "admin").
Returning("id").
UseDialect("postgres").
Build()
Yields:
INSERT INTO "users" ("email", "role") VALUES (?, ?) RETURNING "id"
๐งช Test Coverage¶
Every path in InsertBuilder is covered:
| Function | Coverage | Status |
|---|---|---|
| Public API methods | 100% | โ |
| Internal builders | 100% | โ |
| Dialect integration | Verified | โ |
| RETURNING enforcement | Covered | โ |
| Alias rejection | Validated | โ |
- Full support for multiple
Values(...)rows - Guardrails for mismatched row/column counts
- Safe error when using
RETURNINGwithout a supported dialect - Rejection of column aliases
BuildInsertOnly()logic also dialect-aware
โ RETURNING Clause Behavior¶
- Only allowed when
SupportsReturning()returnstrue - Currently supported by
PostgresDialect - Builder fails gracefully with an error for unsupported dialects
๐ Summary¶
InsertBuilderis dialect-aware, secure, and strictly validated- Compatible with PostgreSQL and fallback-safe with generic dialects
- Covers
Build()andBuildInsertOnly()paths fully - All behaviors tested to 100% coverage