Class XBRApiMetaDB
Provides an API for interacting with MetaDB, a database interaction layer that enables querying and managing tabular data using DuckDB syntax.
Namespace: Workspace.XBR.Xperiflow.SubApis
Assembly: Xperiflow.dll
public class XBRApiMetaDB
Examples
Creating a MetaDB connection:
using (var connection = XBRApi.MetaDB.CreateMetaDBConnection(si))
{
connection.Open();
Console.WriteLine("Connected to MetaDB successfully.");
}
Executing a query:
string query = "SELECT * FROM 'shared://myfolder/myfile.parquet' WHERE role = @role";
var param = new DbParameter("@role", "Admin");
DataTable result = XBRApi.MetaDB.ExecuteSql(si, query, param);
foreach (DataRow row in result.Rows)
`{
Console.WriteLine($"User: {row["name"]}`, Role: {row["role"]}");
}
Executing a non-query command:
string insertQuery = "INSERT INTO users (name, role) VALUES (@name, @role)";
var param1 = new DbParameter("@name", "John Doe");
var param2 = new DbParameter("@role", "Admin");
int rowsAffected = XBRApi.MetaDB.ExecuteNonQuery(si, insertQuery, param1, param2);
Console.WriteLine($"{rowsAffected} row(s) inserted successfully.");
Remarks
This class serves as an entry point for working with MetaDB, including establishing connections, executing queries, and performing database modifications. It wraps DuckDB with additional capabilities such as query parsing and connection handling to facilitate seamless integration with Xperiflow storage.
Methods
CreateMetaDBConnection(SessionInfo, string)
Creates a MetaDB connection using the provided connection string.
public DbConnection CreateMetaDBConnection(SessionInfo si, string connectionString = "DataSource=:memory:")
Returns
System.Data.Common.DbConnection
A Workspace.XBR.Xperiflow.MetaDB.MetaDBConnection representing the MetaDB connection.
Parameters
Type | Name | Description |
---|---|---|
OneStream.Shared.Common.SessionInfo | si | The session information. |
System.String | connectionString | The DuckDB connection string (e.g., an in-memory or file-based connection string). Defaults to an in-memory database. |
Exceptions
OneStream.Shared.Common.XFException
Thrown when an error occurs while creating the connection.
ExecuteSql(SessionInfo, string, params DbParameter[])
Executes a SQL query against MetaDB and returns the result as a System.Data.DataTable
.
public DataTable ExecuteSql(SessionInfo si, string sql, params DbParameter[] parameters)
Returns
System.Data.DataTable
A System.Data.DataTable
containing the query results.
Parameters
Type | Name | Description |
---|---|---|
OneStream.Shared.Common.SessionInfo | si | The session information. |
System.String | sql | The SQL query to execute. Uses DuckDB syntax. |
System.Data.Common.DbParameter[] | parameters | Optional parameters to include in the query. |
Exceptions
OneStream.Shared.Common.XFException
Thrown when an error occurs during query execution.
ExecuteNonQuery(SessionInfo, string, params DbParameter[])
Executes a non-query SQL command (e.g., INSERT, UPDATE, DELETE) against MetaDB and returns the number of rows affected.
public int ExecuteNonQuery(SessionInfo si, string sql, params DbParameter[] parameters)
Returns
System.Int32
The number of rows affected by the command.
Parameters
Type | Name | Description |
---|---|---|
OneStream.Shared.Common.SessionInfo | si | The session information. |
System.String | sql | The SQL command to execute. |
System.Data.Common.DbParameter[] | parameters | Optional parameters to include in the command. |
Exceptions
OneStream.Shared.Common.XFException
Thrown when an error occurs during command execution.
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object,System.Object)
System.Object.GetHashCode
System.Object.GetType
System.Object.MemberwiseClone
System.Object.ReferenceEquals(System.Object,System.Object)
System.Object.ToString