Table of Contents

Class Literal<T>

Namespace
YndigoBlue.Velocity.Model
Assembly
YndigoBlue.Velocity.dll

Represents a literal constant value used in queries, expressions, and constraints.

public class Literal<T> : ILiteral, IElement, ICheckItem, IDefaultItem

Type Parameters

T

The C# type of the literal value. Common types include: string, int, long, decimal, DateTime, bool, byte[], and others.

Inheritance
Literal<T>
Implements

Examples

Using literals in expressions:

// Calculate: price * 1.1 (add 10% markup)
Expression markupExpression = new Expression("markup_price");
markupExpression.Add(productsTable["price"]);
markupExpression.Add(new ArithmeticOperator(ArithmeticType.Multiply));
markupExpression.Add(new Literal<decimal>(1.1m));

query.AddSelectItem(markupExpression);
// SQL: SELECT price * 1.1 AS markup_price

Using literals with functions:

// ROUND(price * 1.1, 2)
Function roundFunction = new Function(FunctionType.Round);
roundFunction.Add(productsTable["price"]);
roundFunction.Add(new ArithmeticOperator(ArithmeticType.Multiply));
roundFunction.Add(new Literal<decimal>(1.1m));
roundFunction.Add(new Literal<int>(2)); // decimal places

query.AddSelectItem(roundFunction);

Using literals in CHECK constraints:

// Ensure age is between 18 and 120
Table usersTable = schema.CreateTable("users");
Column ageColumn = usersTable.AddColumn("age", DataType.Integer);

CheckConstraint ageCheck = new CheckConstraint("age_check");
ageCheck.Add(ageColumn);
ageCheck.Add(new CheckOperator(CheckOperatorType.GreaterThanOrEquals));
ageCheck.Add(new Literal<int>(18));
ageCheck.Add(new BooleanItem(BooleanType.And));
ageCheck.Add(ageColumn);
ageCheck.Add(new CheckOperator(CheckOperatorType.LessThanOrEquals));
ageCheck.Add(new Literal<int>(120));

usersTable.AddCheckConstraint(ageCheck);

Using literals in DEFAULT constraints:

// Default status to 'pending'
Column statusColumn = usersTable.AddColumn("status", DataType.VarChar, size: 50);
DefaultConstraint defaultStatus = new DefaultConstraint(
    "default_status",
    new Literal<string>("pending")
);
statusColumn.SetDefaultConstraint(defaultStatus);

Remarks

Literal values are type-safe wrappers around constant values that can be used in:

  • Expression - For arithmetic calculations
  • Function - As arguments to database functions
  • CHECK constraints - For validation rules
  • DEFAULT constraints - For default column values

Each literal automatically generates a unique parameter name for safe SQL generation and tracks metadata like length (for strings) and precision/scale (for decimals).

Constructors

Literal(T)

Creates a new literal value.

Properties

CheckConstraintType

Gets the type of check constraint element.

DataType

Gets the database data type of this literal.

DefaultConstraintType

Gets the type of default constraint element.

Length

Gets the length of the literal value (for string types).

ParameterName

Gets the unique parameter name used for this literal in SQL generation.

Precision

Gets the precision of the literal value (for decimal types).

Scale

Gets the scale of the literal value (for decimal types).

Value

Gets the literal's constant value.

Methods

IsEqual(ICheckItem)

Determines whether this check item is equal to another check item.

IsEqual(IDefaultItem)

Determines whether this default item is equal to another default item.

ToString()

Returns a string that represents the current object.