Sreeni.OData.Transpiler.Core
1.0.5
dotnet add package Sreeni.OData.Transpiler.Core --version 1.0.5
NuGet\Install-Package Sreeni.OData.Transpiler.Core -Version 1.0.5
<PackageReference Include="Sreeni.OData.Transpiler.Core" Version="1.0.5" />
paket add Sreeni.OData.Transpiler.Core --version 1.0.5
#r "nuget: Sreeni.OData.Transpiler.Core, 1.0.5"
// Install Sreeni.OData.Transpiler.Core as a Cake Addin #addin nuget:?package=Sreeni.OData.Transpiler.Core&version=1.0.5 // Install Sreeni.OData.Transpiler.Core as a Cake Tool #tool nuget:?package=Sreeni.OData.Transpiler.Core&version=1.0.5
Sreeni.OData.Transpiler.Core
Sreeni.OData.Transpiler.Core is a .Net based OData transpiler that translates OData queries to downstream data source queries like MySQL, Postgres, MS SQL, Azure Cosmos, etc.
The objective is to enable seamless integration and query translation across different database platforms.
This package has core contracts and infrastructure designed to translate OData queries into database-specific queries for multiple database systems.
Features
- Parse OData queries
- Convert OData queries to SQL-like queries
- Supports multiple database systems:
- Azure Cosmos DB - Completed
- MS SQL(Open)
- MySQL(Open)
- PostgreSQL(Open)
- MongoDB(Open)
- And more
- Support for common OData query options:
$select
,$filter
,$orderby
,$top
,$skip
, and$expand
- Nested fields in the select clause, filter expressions, and orderby expressions
Getting Started
Installation
To install the package, add the following dependency to your project:
dotnet add package Sreeni.OData.Transpiler.Core
Usage
This package primarily required to build your own OData transpiler for a specific database system. The following steps are required to build a transpiler for a specific database system.
- Create a class that implements the
IODataQueryTranslator
interface. - Implement the
Translate
method fromIODataQueryTranslator
interface. - Use
ODataQueryParser
to parse the given OData query.
public class AzureCosmosODataQueryTranslator : IODataQueryTranslator
{
public QueryResult Translate(string odataQuery)
{
// Validate the query
...
var parser = new ODataQueryParser();
ODataQuery query = parser.Parse(odataQuery);
// Translate OData query to Cosmos SQL query
...
Create visitor for each OData query option like $select, $filter, $orderby, $top, $skip, and $expand and use them here
...
// Return the translated query
return queryResult;
}
}
- The library uses the visitor pattern to handle different parts of the OData query. The following visitors are required for each database query translator:
SelectVisitor
: Handles the$select
optionFilterVisitor
: Handles the$filter
optionOrderByVisitor
: Handles the$orderby
optionTopVisitor
: Handles the$top
optionSkipVisitor
: Handles the$skip
optionExpandVisitor
: Handles the$expand
option
- Implement the visitor classes for each OData query option like
$select
,$filter
,$orderby
,$top
,$skip
, and$expand
.- Use the visitor classes to translate the OData query to the database-specific query.
- Create a database specific client to execute the translated query.
- Implement the
IODataClient
interface. It hasGetItemByQueryAsync
method to return single item, if you want to list of items then you need to implementIODataListClient
interface.
public class AzureCosmosODataClient : IODataClient { public async Task<T> GetItemByQueryAsync<T>(string query) { // Execute the query and return the result ... } } //To get list of items public class AzureCosmosODataClient : IODataListClient { public async Task<T> GetItemByQueryAsync<T>(string query) { // Execute the query and return the result ... } public async Task<IEnumerable<T>> GetListByQueryAsync<T>(string query) { // Execute the query and return the result ... } }
- Implement the
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
To contribute(via Pull Request):
- Fork the repository.
- Create a new branch with a descriptive name.
- Make your changes and commit them with clear and concise messages.
- Push your changes to your forked repository.
- Submit a pull request.
Please ensure your code follows the project's coding standards and passes all tests.
License
This project is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- Newtonsoft.Json (>= 13.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Sreeni.OData.Transpiler.Core:
Package | Downloads |
---|---|
Sreeni.OData.Transpiler.Azure.Cosmos
Sreeni.OData.Transpiler.Azure.Cosmos is a .NET-based OData query translator specifically designed for Azure Cosmos DB. It translates OData queries into Cosmos DB SQL queries, enabling seamless integration and query translation for Azure Cosmos DB. |
GitHub repositories
This package is not used by any popular GitHub repositories.