Table of Contents

Class Table

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

Represents a database table with columns, constraints, and indexes.

public class Table : IFromItem, IEquatable<Table>, IComparable<Table>
Inheritance
Table
Implements
Derived

Examples

Creating a table programmatically:

Schema schema = Schema.NewSchema("my_application");

// Create a users table
Table usersTable = schema.CreateTable("users");

// Add columns
usersTable.AddColumn("user_id", DataType.Long, autoGenerate: true, notNull: true);
usersTable.AddColumn("username", DataType.VarChar, size: 100, notNull: true);
usersTable.AddColumn("email", DataType.VarChar, size: 200, notNull: true);
usersTable.AddColumn("age", DataType.Integer);
usersTable.AddColumn("created_at", DataType.DateTime);

// Add primary key constraint
usersTable.AddPrimaryKey("pk_users", usersTable["user_id"]);

// Add unique constraint
usersTable.AddUnique("uk_username", usersTable["username"]);

// Add index for performance
Index ageIndex = usersTable.AddIndex("idx_age");
ageIndex.AddIndexItem(usersTable["age"]);

// Add check constraint
usersTable.AddCheck("ck_age", usersTable["age"], CheckOperator.GreaterThanOrEquals, 18);

Adding a foreign key relationship:

Table ordersTable = schema.CreateTable("orders");
ordersTable.AddColumn("order_id", DataType.Long, autoGenerate: true, notNull: true);
ordersTable.AddColumn("user_id", DataType.Long, notNull: true);
ordersTable.AddColumn("total", DataType.Decimal, precision: 10, scale: 2);

// Add foreign key to users table
ordersTable.AddForeignKey(
    "fk_orders_users",
    ordersTable["user_id"],
    usersTable["user_id"]
);

Working with table data:

using (Manager manager = new Manager(connection))
{
    manager.LoadSchema("my_application");
    Schema schema = manager.GetSchema("my_application");
    Table usersTable = schema["users"];

    // Insert a record
    Record record = new Record(usersTable);
    record.SetFieldString("username", "john_doe");
    record.SetFieldString("email", "john@example.com");
    record.SetFieldInt("age", 30);
    record.SetFieldDateTime("created_at", DateTime.UtcNow);
    manager.AddRecord(record);

    // Query the table
    Query query = new Query();
    query.AddFromItem(usersTable);
    query.AddSelectItem(usersTable["username"]);
    query.AddSelectItem(usersTable["email"]);
    query.AddFilter(usersTable["age"], ConditionalType.GreaterThan, 25);

    using (ResultSet results = manager.Retrieve(query))
    {
        foreach (Result row in results)
        {
            Console.WriteLine($"{row.GetFieldString("username")}: {row.GetFieldString("email")}");
        }
    }
}

Remarks

Table is the primary container for structured data in a database schema. Tables contain columns that define the data structure, constraints that enforce data integrity rules, and indexes that optimize query performance.

Tables are created within a Schema using CreateTable(string) or loaded from an existing database or schema file.

Fields

_columns

Properties

Columns
Constraints
FullTextIndex

Gets the full-text index for this table, if one has been defined.

Indexes
this[int]
this[string]
Name

Gets the name of the table.

NotNullColumns
SchemaName

Gets or sets the name of the schema that contains this table.

SchemaUpdate

Gets or sets a value indicating whether this table is part of a schema update operation.

SelectItems

Gets the collection of select items (columns or expressions) available from this FROM item.

SpatialIndex

Gets the spatial index for this table, if one has been defined.

Methods

AddColumn(string, DataType, bool, bool, int, byte, byte)
AddColumn(string, DataType, DefaultConstraintType, IDefaultItem, bool, bool, int, byte, byte)
Clone(string)
CloneForStaging(string, bool)
CompareTo(Table)

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.

CreateCheckConstraint(string, IEnumerable<ICheckItem>)
CreateCheckConstraint(string, ICheckItem)
CreateCheckConstraint(string, ICheckItem[])
CreateColumn(string, DataType, bool, bool, int, byte, byte)
CreateDefaultConstraint(string, IDefaultItem, DefaultConstraintType, DataType)
CreateForeignKey(string, IEnumerable<string>, string, string, IEnumerable<string>, ForeignKeyRuleType, ForeignKeyRuleType)
CreateForeignKey(string, string, string, string, string, ForeignKeyRuleType, ForeignKeyRuleType)
CreateForeignKey(string, string[], string, string, string[], ForeignKeyRuleType, ForeignKeyRuleType)
CreateFullTextIndex(string, IEnumerable<string>)
CreateFullTextIndex(string, string, IEnumerable<string>)
CreateIndex(string)
CreateIndex(string, string, IndexOrderType)
CreatePrimaryKey(string, IEnumerable<string>)
CreatePrimaryKey(string, string)
CreatePrimaryKey(string, string[])
CreateSpatialIndex(string, string)
CreateSpatialIndex(string, string, double, double, double, double, double, double, double)
CreateSpatialIndexLatLong(string, string, double, double, double, double, double, double, double)
CreateUniqueConstraint(string, IEnumerable<string>)
CreateUniqueConstraint(string, string)
CreateUniqueConstraint(string, string[])
Equals(Table)

Indicates whether the current object is equal to another object of the same type.

GetAutoIncrementColumn()
GetConstraint(string)
GetIndex(string)
GetSelectItem(string)

Retrieves the select item with the specified name.

GetTypeMap()
HasAutoIncrementColumn()
HasColumn(string)
HasIndex(string)
HasSelectItem(string)

Determines whether this FROM item contains a select item with the specified name.

HasSelectItem(ISelectItem)

Determines whether this FROM item contains the specified select item.

ToString()

Returns a string that represents the current object.

ValidateColumnDataType(string, DataType)