Skip to Content
fusion-orm
Dialects

Feature flags

The feature.Feature bitset — every flag the library defines, grouped by category, and the exact sets SQLite and PostgreSQL declare.

Dialect capabilities are bit flags, not name strings. The feature package defines one bit per optional SQL capability; each dialect declares support by combining flags with bitwise OR, and query builders branch on capability:

// Package feature defines bit flags representing optional SQL dialect
// capabilities. Each dialect declares which features it supports by
// combining flags with the bitwise OR operator; query builders branch on
// capability instead of sniffing dialect names.

This is why "does this dialect support RETURNING?" is never an if d.Name() == "postgres" somewhere in the builders — it is a single Features().Has(feature.Returning) check, and a third-party dialect gets the same treatment as the in-tree ones.

Working with the bitset

// Has reports whether all bits of flag are present in f.
func (f Feature) Has(flag Feature) bool {
	return f&flag == flag
}

// Set returns f with flag added.
func (f Feature) Set(flag Feature) Feature {
	return f | flag
}

// Remove returns f with flag cleared.
func (f Feature) Remove(flag Feature) Feature {
	return f &^ flag
}

String() renders a set in declaration order — "CTE|Returning" — which makes capability sets readable in logs and String()-interpolated errors.

All flags, by category

Every flag defined in the package, with its one-line meaning:

CategoryFlagMeaning
CommonCTECommon Table Expressions (WITH ... AS ...)
CommonWithValuesWITH ... (VALUES ...) inline value lists
CommonReturningRETURNING clause on DML
CommonOutputOUTPUT clause (MSSQL's RETURNING equivalent)
CommonDefaultPlaceholderDEFAULT keyword in INSERT value lists
CommonDoubleColonCastPostgreSQL-style :: type cast syntax
CommonValuesRowVALUES ROW(...) syntax
CommonCompositeInWHERE (A, B) IN ((N, NN), ...) comparison
CommonRowValuesRow-value comparison, e.g. (A, B) > (N, NN) — composite-key keyset pagination
SELECTOffsetFetchOFFSET ... FETCH NEXT syntax
SELECTSelectExistsEXISTS subquery expressions
INSERTInsertReturningINSERT ... RETURNING
INSERTInsertTableAliasTable alias in INSERT statements
INSERTInsertOnConflictINSERT ... ON CONFLICT
INSERTInsertOnDuplicateKeyINSERT ... ON DUPLICATE KEY
INSERTInsertIgnoreINSERT IGNORE
UPDATEUpdateFromTableUPDATE ... FROM ...
UPDATEUpdateMultiTableMulti-table UPDATE syntax
UPDATEUpdateTableAliasTable alias in UPDATE statements
UPDATEUpdateOrderLimitUPDATE ... ORDER BY ... LIMIT
DELETEDeleteReturningDELETE ... RETURNING
DELETEDeleteTableAliasTable alias in DELETE statements
DELETEDeleteOrderLimitDELETE ... ORDER BY ... LIMIT
MERGEMergeMERGE ... USING ... ON ... WHEN
MERGEMergeReturningMERGE ... RETURNING
DDLTableCascadeCASCADE for DROP TABLE and related operations
DDLTableIdentityTable-level IDENTITY property
DDLTableTruncateTRUNCATE TABLE support
DDLTableNotExistsIF NOT EXISTS / IF EXISTS DDL syntax
DDLAlterColumnExistsADD/DROP COLUMN IF [NOT] EXISTS syntax
DDLCreateIndexIfNotExistsCREATE INDEX IF NOT EXISTS
ColumnAutoIncrementAUTO_INCREMENT column syntax
ColumnIdentityIDENTITY column syntax
ColumnGeneratedIdentityGENERATED ALWAYS AS IDENTITY
Dialect-specificFKDefaultOnActionFK ON UPDATE/ON DELETE defaults to NO ACTION
Dialect-specificSavepointSAVEPOINT / ROLLBACK TO / RELEASE (nested transactions)
Migrator/catalogPostgreSQLTypesPostgreSQL-native type names: BOOLEAN, BIGINT, DOUBLE PRECISION, BYTEA, JSONB
Migrator/catalogInformationSchemaSQL-standard information_schema catalog introspection
Migrator/catalogPragmaTableInfoSQLite's PRAGMA table_info introspection
Migrator/catalogDollarPlaceholder$1, $2, ... bind placeholders instead of ?
Migrator/catalogSerialColumnSERIAL/BIGSERIAL pseudo-types for auto-increment
Migrator/catalogAutoIncrementClauseRequires the AUTOINCREMENT keyword after PRIMARY KEY
Migrator/catalogAlterColumnTypeALTER COLUMN ... TYPE statements
Migrator/catalogAddColumnNonConstantDefaultALTER TABLE ADD COLUMN with non-constant defaults (CURRENT_TIMESTAMP, function calls)

The last group's flags exist because migrators introspect the catalog differently per engine and some DDL loopholes are engine-specific — SQLite rejects non-constant column defaults outside CREATE TABLE, PostgreSQL does not.

What each built-in dialect declares

SQLite

// Features declares SQLite's capabilities.
func (d *Dialector) Features() feature.Feature {
	return feature.CTE |
		feature.WithValues |
		feature.Returning |
		feature.InsertReturning |
		feature.InsertTableAlias |
		feature.UpdateTableAlias |
		feature.DeleteTableAlias |
		feature.InsertOnConflict |
		feature.TableNotExists |
		feature.SelectExists |
		feature.AutoIncrement |
		feature.CompositeIn |
		feature.RowValues |
		feature.FKDefaultOnAction |
		feature.DeleteReturning |
		feature.CreateIndexIfNotExists |
		feature.Savepoint |
		feature.PragmaTableInfo |
		feature.AutoIncrementClause
}

19 flags. Notably absent: DollarPlaceholder (SQLite uses ?), InformationSchema (introspection goes through PRAGMA table_info instead), Merge, GeneratedIdentity, and every ...OrderLimit / multi-table flag.

PostgreSQL

// Features declares PostgreSQL's capabilities.
func (d *Dialector) Features() feature.Feature {
	return feature.CTE |
		feature.WithValues |
		feature.Returning |
		feature.InsertReturning |
		feature.DefaultPlaceholder |
		feature.DoubleColonCast |
		feature.InsertTableAlias |
		feature.UpdateTableAlias |
		feature.DeleteTableAlias |
		feature.TableCascade |
		feature.TableIdentity |
		feature.TableTruncate |
		feature.TableNotExists |
		feature.InsertOnConflict |
		feature.SelectExists |
		feature.GeneratedIdentity |
		feature.CompositeIn |
		feature.RowValues |
		feature.FKDefaultOnAction |
		feature.DeleteReturning |
		feature.Merge |
		feature.MergeReturning |
		feature.AlterColumnExists |
		feature.CreateIndexIfNotExists |
		feature.Savepoint |
		feature.PostgreSQLTypes |
		feature.InformationSchema |
		feature.DollarPlaceholder |
		feature.SerialColumn |
		feature.AlterColumnType |
		feature.AddColumnNonConstantDefault
}

31 flags. Notably absent: InsertIgnore and InsertOnDuplicateKey (PostgreSQL upserts via INSERT ... ON CONFLICT), Output, OffsetFetch, ValuesRow, and the MySQL-style UPDATE ... ORDER BY ... LIMIT family.

Shared core, divergent edges

Both dialects share 16 flags — CTEs, RETURNING, ON CONFLICT, alias support, exists, composite predicates, savepoints. When a capability differs (upsert syntax, placeholder style, introspection), the flag set is what tells the builders — check the tables above before reaching for a feature in raw Clauses work.

When a flag is missing

Builders that hit an unsupported capability do not guess or degrade silently. They record a *fusion.UnsupportedFeatureError, which wraps fusion.ErrUnsupportedFeature and names the missing flag:

// UnsupportedFeatureError names the specific feature flag that a dialect
// lacks, so callers can branch on ErrUnsupportedFeature while still seeing
// which feature was required.
type UnsupportedFeatureError struct {
	Feature string
}

func (e *UnsupportedFeatureError) Error() string {
	return fmt.Sprintf("unsupported feature: %s", e.Feature)
}

For example, starting a nested transaction against a dialect without Savepoint, or using row-value pagination without RowValues, produces an error whose Feature field is "Savepoint" / "RowValues" respectively:

tx.AddError(NewUnsupportedFeatureError(feature.Savepoint.Name()))

Branch with errors.Is(err, fusion.ErrUnsupportedFeature) and, if needed, errors.As to read the flag name.

Next

On this page