Table of Contents

Class Record

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

Represents a database record for INSERT and UPDATE operations. A Record contains field values that will be persisted to a specific table, with support for literal values, subqueries, and database functions.

public class Record : Datum
Inheritance
Record
Derived

Examples

Basic record creation and insertion:

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

    // Create a new 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);

    // Insert the record
    manager.AddRecord(record);
}

Using subqueries for field values:

// Create a query to get the max price from products
Query maxPriceQuery = new Query();
maxPriceQuery.AddFromItem(productsTable);
maxPriceQuery.AddSelectItem(new Function(FunctionType.Max, productsTable["price"]));

// Use the subquery result as a field value
Record record = new Record(settingsTable);
record.SetFieldString("setting_name", "max_price");
record.SetFieldAsQuery("setting_value", maxPriceQuery);

manager.AddRecord(record);
// SQL: INSERT INTO settings (setting_name, setting_value)
//      VALUES ('max_price', (SELECT MAX(price) FROM products))

Using database functions for field values:

Record record = new Record(usersTable);
record.SetFieldString("username", "john_doe");

// Use UPPER() function to convert text to uppercase
Function upperFunction = new Function(FunctionType.Upper, new Literal("john doe"));
record.SetFieldAsFunction("display_name", upperFunction);

// Use NOW() for timestamp
record.SetFieldAsFunction("created_at", new Function(FunctionType.Now));

manager.AddRecord(record);

Remarks

Records are created from a Table object and automatically inherit the table's column structure. You set field values using type-specific setter methods (SetFieldString, SetFieldInt, etc.) inherited from Datum.

Auto-generated columns (typically auto-incrementing primary keys) do not need values set and will be populated by the database during insertion.

Constructors

Record(Table)

Creates a new record for the specified table.

Fields

_fields
_functionFields
_queryFields
_table

Properties

FieldCount
Fields
Table

Gets the table that this record belongs to.

Methods

GetFieldAsFunction(string)

Gets the database function associated with a field.

GetFieldAsFunction(ISelectItem)

Gets the database function associated with a field.

GetFieldAsQuery(string)

Gets the subquery associated with a field.

GetFieldAsQuery(ISelectItem)

Gets the subquery associated with a field.

GetSelectItem(int)
GetSelectItem(string)
HasFieldAsFunction(ISelectItem)

Determines whether a field is set to a function value.

HasFieldAsQuery(ISelectItem)

Determines whether a field is set to a subquery value.

HasSelectItem(string)
SetFieldAsFunction(string, Function)

Sets a field value to be calculated using a database function.

SetFieldAsFunction(ISelectItem, Function)

Sets a field value to be calculated using a database function.

SetFieldAsQuery(string, Query)

Sets a field value to be populated from a subquery result.

SetFieldAsQuery(ISelectItem, Query)

Sets a field value to be populated from a subquery result.