Skip to content

EnsureData

Inserts or updates a row in the table based on the specified column and value as a single criterion. Only the included columns get updated. The column/value pair selects existing rows; it is not automatically copied into a new row. Include the source primary key explicitly in input or initInput to preserve it on insert. This method saves immediately. For a batch, update a DataTable in memory and call DataTable.Save once after the loop.

1
$Database.EnsureData(schema: string, table: string, column: string, value: any, input: object, initInput?: object):DataRow

Parameters

string schema
    The name of the target schema.

string table
    The name of the target table.

string column
    The name of the column to use as criteria.

any value
    The value of the column to use as criteria.

object input
    A JavaScript object or function for the column values to update.

object initInput optional
    A JavaScript object or function for initializing values for new rows. Optional.

Returns

A DataRow object representing the inserted or updated row.

Remarks

Example

1
2
3
4
5
6
$Database.EnsureData("MySchema", "MyTable", "Id", id, {
    Id : id,
    Name : $Xml.Evaluate('Name')
}, {
    CreateDate : DateTimeOffset.now
});

See Also