Class Column
- Namespace
- YndigoBlue.Velocity.Model
- Assembly
- YndigoBlue.Velocity.dll
Represents a column in a database table.
public class Column : ISelectItem, IElement, ICheckItem, IGroupItem, IEquatable<Column>, IEquatable<string>, IComparable<Column>
- Inheritance
-
Column
- Implements
Remarks
Columns define the structure of data within a table, specifying the data type, size constraints, nullability, and whether values are auto-generated.
Columns are created using CreateColumn(string, DataType, bool, bool, int, byte, byte) and can be referenced in queries, constraints, and indexes. To add a column to an already-deployed table as a schema migration, use AddColumn(string, DataType, bool, bool, int, byte, byte) instead.
Examples
Defining columns on a new table:
Table usersTable = schema.CreateTable("users");
// Auto-incrementing primary key
usersTable.CreateColumn("user_id", DataType.Long, autoGenerate: true, notNull: true);
// Required text column with size limit
usersTable.CreateColumn("username", DataType.VarChar, size: 100, notNull: true);
// Optional text column
usersTable.CreateColumn("email", DataType.VarChar, size: 200);
// Numeric column with precision and scale
usersTable.CreateColumn("balance", DataType.Decimal, precision: 10, scale: 2);
// Integer column
usersTable.CreateColumn("age", DataType.Integer);
// Date/time columns
usersTable.CreateColumn("created_at", DataType.DateTime);
usersTable.CreateColumn("birth_date", DataType.Date);
// Boolean column
usersTable.CreateColumn("is_active", DataType.Boolean);
// Binary data column
usersTable.CreateColumn("profile_image", DataType.VarBinary, size: 1048576); // 1MB
Referencing columns in queries:
Table usersTable = schema["users"];
Column usernameColumn = usersTable["username"];
var query = new Query()
.Select([ usernameColumn, usersTable["email"] ])
.From(usersTable)
.Where(new Criterion<int>(usersTable["age"], ConditionalType.GreaterThan, 18))
.OrderBy(new OrderClause(usernameColumn, OrderClauseType.Ascending));
using (ResultSet results = manager.Retrieve(query))
{
// process results
}
Using columns in constraints:
// Primary key
usersTable.CreatePrimaryKey("pk_users", "user_id");
// Unique constraint
usersTable.CreateUniqueConstraint("uk_email", "email");
// Foreign key
ordersTable.CreateForeignKey(
"fk_orders_users",
"user_id",
usersTable.SchemaName, usersTable.Name, "user_id",
ForeignKeyRuleType.NoAction, ForeignKeyRuleType.NoAction
);
// Check constraint
usersTable.CreateCheckConstraint("ck_age",
[ usersTable["age"], new CheckOperator(CheckOperatorType.GreaterThanOrEquals), new Literal<int>(0) ]
);
Properties
- AutoGenerate
Gets whether the database automatically generates a value for this column (identity / sequence / auto-increment).
- CheckConstraintType
Gets the type of check constraint element.
- ColumnUpdate
Gets or sets whether this column's definition should be modified in the database during a schema migration.
- DataType
Gets the data type of this column.
- ExistingRowType
Gets or sets the type of default value to apply to existing rows when adding this column to a populated table.
- ExistingRowValue
Gets or sets the default value item to apply to existing rows when adding this column to a populated table.
- FromItem
Gets or sets the name of the table (or view) that this column belongs to.
- Name
Gets the name of this column.
- NotNull
Gets whether this column has a NOT NULL constraint.
- Precision
Gets the total number of significant digits for numeric columns (e.g.
Decimal).
- Scale
Gets the number of digits to the right of the decimal point for numeric columns.
- SchemaName
Gets the name of the schema that contains the table this column belongs to.
- SchemaUpdate
Gets or sets whether this column should be added to an existing table during a schema migration.
- Size
Gets the maximum length of this column for variable-length types such as
VarCharorChar.
Methods
- CompareTo(Column)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
- Equals(string)
Indicates whether the current object is equal to another object of the same type.
- Equals(Column)
Indicates whether the current object is equal to another object of the same type.
- IsEqual(ICheckItem)
Determines whether this check item is equal to another check item.
- ModifyDataType(DataType)
Changes the data type of this column and marks it for update via UpdateSchema(Schema, bool).
- ModifyNotNull(bool)
Changes the nullability of this column and marks it for update via UpdateSchema(Schema, bool).
- ModifyPrecisionScale(byte, byte)
Changes the precision and scale of this column and marks it for update via UpdateSchema(Schema, bool).
- ModifySize(int)
Changes the size of this column and marks it for update via UpdateSchema(Schema, bool).
- ReType(DataType, int)
Re-types this column to a compatible data type without marking it for a database schema update.
- ToString()
Returns a string that represents the current object.