Sreeni.OData.Transpiler.Core 1.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package Sreeni.OData.Transpiler.Core --version 1.0.4                
NuGet\Install-Package Sreeni.OData.Transpiler.Core -Version 1.0.4                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sreeni.OData.Transpiler.Core" Version="1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sreeni.OData.Transpiler.Core --version 1.0.4                
#r "nuget: Sreeni.OData.Transpiler.Core, 1.0.4"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Sreeni.OData.Transpiler.Core as a Cake Addin
#addin nuget:?package=Sreeni.OData.Transpiler.Core&version=1.0.4

// Install Sreeni.OData.Transpiler.Core as a Cake Tool
#tool nuget:?package=Sreeni.OData.Transpiler.Core&version=1.0.4                

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.

  1. Create a class that implements the IODataQueryTranslator interface.
  2. Implement the Translate method from IODataQueryTranslator interface.
  3. 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;
	   }
   }
  1. 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 option
  • FilterVisitor: Handles the $filter option
  • OrderByVisitor: Handles the $orderby option
  • TopVisitor: Handles the $top option
  • SkipVisitor: Handles the $skip option
  • ExpandVisitor: Handles the $expand option
  1. 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.
  2. Create a database specific client to execute the translated query.
    • Implement the IODataClient interface. It has GetItemByQueryAsync method to return single item, if you want to list of items then you need to implement IODataListClient 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
     		...
     	}
     }
    

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

To contribute(via Pull Request):

  1. Fork the repository.
  2. Create a new branch with a descriptive name.
  3. Make your changes and commit them with clear and concise messages.
  4. Push your changes to your forked repository.
  5. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
1.0.5 91 12/23/2024
1.0.4 81 12/16/2024
1.0.3 103 12/14/2024
1.0.2 80 12/14/2024
1.0.1 107 12/11/2024
1.0.0 89 12/11/2024