Method ExportData
- Namespace
- YndigoBlue.Velocity.Engine
- Assembly
- YndigoBlue.Velocity.dll
ExportData(Query, string, ExportConfig)
Exports query results to a CSV file.
public void ExportData(Query query, string dataFilePath, ExportConfig exportConfig = null)
Parameters
queryQueryA Query that defines the data to export.
dataFilePathstringThe path where the CSV file will be created.
exportConfigExportConfigOptional ExportConfig specifying delimiters, headers, and format settings. Uses defaults if null.
Examples
using (var m = new Manager(conn))
{
var schema = m.LoadSchema("app");
var usersTable = schema["users"];
var ordersTable = schema["orders"];
// Create a query with a join
var query = new Query()
.Select([
usersTable["name"],
usersTable["email"],
new Aggregate("total_spent", ordersTable["total"], AggregateType.Sum)
])
.From(usersTable)
.Join(JoinType.Inner, ordersTable, usersTable["id"], JoinOperatorType.Equals, ordersTable["user_id"])
.GroupBy([usersTable["id"]]);
// Export to CSV
var config = new ExportConfig { IncludeHeaders = true, Delimiter = ',' };
m.ExportData(query, "user_spending.csv", config);
}
Exceptions
- DbException
Thrown when a database error occurs.
ExportData(Table, string, ExportConfig)
Exports all data from a table to a CSV file.
public void ExportData(Table table, string dataFilePath, ExportConfig exportConfig = null)
Parameters
tableTableThe Table to export data from.
dataFilePathstringThe path where the CSV file will be created.
exportConfigExportConfigOptional ExportConfig specifying delimiters, headers, and format settings. Uses defaults if null.
Examples
using (var m = new Manager(conn))
{
var schema = m.LoadSchema("app");
var usersTable = schema["users"];
// Export entire table
m.ExportData(usersTable, "users_backup.csv");
// Export with custom delimiter
var config = new ExportConfig { Delimiter = '|', IncludeHeaders = true };
m.ExportData(usersTable, "users_pipe.csv", config);
}
Exceptions
- DbException
Thrown when a database error occurs.
ExportData(View, string, ExportConfig)
Exports all data from a view to a CSV file.
public void ExportData(View view, string dataFilePath, ExportConfig exportConfig = null)
Parameters
viewViewThe View to export data from.
dataFilePathstringThe path where the CSV file will be created.
exportConfigExportConfigOptional ExportConfig specifying delimiters, headers, and format settings. Uses defaults if null.
Examples
using (var m = new Manager(conn))
{
var schema = m.LoadSchema("app");
var activeUsersView = schema.Views["active_users"];
// Export view data
m.ExportData(activeUsersView, "active_users.csv");
}
Exceptions
- DbException
Thrown when a database error occurs.