$Database¶
$Database allows you to perform relational database operations.
You can use the $Database.Get method to query existing records, make changes on the returned DataTable instance, and persist all changes with the DataTable.Save method.
If you need to just insert new values, you can use the $Database.Empty method to create an empty to add new rows and save the table.
This class also provides the $Database.ImportFromXml and $Database.ExportToXml methods to map the database to a Data Model (XML) to allow users to make interactive changes.
To update or insert a single row, you can use the $Database.EnsureData method to perform single-row updates with less code.
1 | |
Capabilities¶
Data Modification¶
- Database.AddData: Appends a new row to the specified target table and returns the inserted row as a DataRow object.
- Database.DeleteData: Removes all rows from the specified table by using a column and value as a single criterion, and returns the number of rows deleted.
- Database.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.
- Database.EnsureStoreData: Inserts or updates a row in the table based on the specified column and value as a single criterion. Only the included columns are updated. The criterion is not automatically assigned on insert. Include the source key in input or initInput. Like EnsureData, this method saves immediately; use DataTable.Save for in-memory batch changes.
- Database.ExecuteNonQuery: Creates a connection to the relevant system with the information defined on the domain and runs the query. Returns the number of affected rows.
Import and Export¶
- Database.Empty: Returns an empty DataTable for importing data into a target table.
- Database.ExportToXml: Exports the data table content to XML data. For each row in the data table, a new XML child element is created at the specified XPath location.
- Database.ImportFromXml: Imports XML data into a specified table. For more details, see DataTable.ImportFromXml.
Queries and Retrieval¶
- Database.ExecuteQuery: Creates a connection to the relevant system using the information defined on the domain and runs the query.
- Database.Get: Executes the specified query and returns the results as a DataTable instance.
- Database.GetData: Executes a query using the specified column and value as a single criterion, and returns the resulting DataTable instance.