ServiceQuery 2.1.1

dotnet add package ServiceQuery --version 2.1.1                
NuGet\Install-Package ServiceQuery -Version 2.1.1                
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="ServiceQuery" Version="2.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ServiceQuery --version 2.1.1                
#r "nuget: ServiceQuery, 2.1.1"                
#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 ServiceQuery as a Cake Addin
#addin nuget:?package=ServiceQuery&version=2.1.1

// Install ServiceQuery as a Cake Tool
#tool nuget:?package=ServiceQuery&version=2.1.1                

<img src="https://github.com/holomodular/ServiceQuery/blob/main/Logo.png" title="ServiceQuery Logo" width="250"/>

ServiceQuery Allows Querying Data Over REST APIs

ServiceQuery, https://ServiceQuery.com, is an open-source library that allows dynamically querying database information over REST APIs. Similar to how OData and GraphQL work, it leverages the power of an expressions builder and a simple model that is capable of serializing query instructions over service boundaries. It supports numerous popular relational (SQL) and document (NoSQL) database engines that expose an IQueryable interface. ServiceQuery builds LINQ expressions using individually mapped functions and parsed data that eliminates injection attacks, so querying your data is safe and secure. This library provides clients and front end applications unprecedented queryability using a standardized endpoint supporting polyglot data access.

Installation Instructions

Install the NuGet Package <b>ServiceQuery</b>

Examples

We have numerous examples built using the most popular database storage providers, such as Azure Data Tables, Cosmos DB, MongoDB, MySQL, SQLite, SQL Server, PostgreSQL, Oracle and more! View all our examples in the examples folder in this project.

Feedback

We want to hear from our users. Please feel free to post any issues or questions on our discussion board. You can star our repository or you can also reach us at: Support@HoloModular.com

Simple Example - Dynamic Querying Using Javascript

Modeled based on LINQ, you create a simple request object that is sent over a REST API endpoint to your web server. Make sure to include the following ServiceQuery.js javascript file to quickly build request queries in javascript.

<script src="/js/servicequery.js"></script>
<script type="text/javascript">

  function GetById() {

    // Build the request
    var request = new ServiceQueryRequestBuilder().IsEqual("Id","123").Build();

    // Send request to REST API
    $.ajax({
        url: '/api/MyAPI/ExampleServiceQuery',
        data: JSON.stringify(request),
        type: "POST",
        dataType: 'json',
        headers: { 'Content-Type': 'application/json' },
        success: function (result) {

          // Output the response
          alert(result.list.length + ' records returned');
        }
    });
  }
</script>

On the web server, the request is safely converted into IQueryable expressions that can be executed against several different database engines. The following exposes a REST API POST method that the client will call.

using ServiceQuery;

[HttpPost]
[Route("ExampleServiceQuery")]
public ServiceQueryResponse<ExampleTable> ExampleServiceQuery(ServiceQueryRequest request)
{
  var queryable = databaseContext.ExampleTable.AsQueryable();
  return request.Execute(queryable);
}

Documentation

Documentation is located on our website at http://ServiceQuery.com as well as a simplified version below. The website also contains tables for supported data types and operations by .NET Framework version and database engine.

ServiceQuery.AzureDataTables

AzureDataTables does not support several things out of the box, such as aggregates, string comparisons and ordering (solved by downloading all records). We have built a companion NuGet package <b>ServiceQuery.AzureDataTables</b> that provides workarounds to these limitations so you can use all standard operations and execute the request in one line of code. See our example projects for more information.

Building and Executing a Query

Building a query is accomplished using the ServiceQueryRequestBuilder object to create the request.

using ServiceQuery;

public void Example()
{
  var request = new ServiceQueryRequestBuilder().Build();
  var queryable = databaseContext.ExampleTable.AsQueryable();
  var response = request.Execute(queryable);

  List<ExampleTable> list = response.List; // contains the list of objects returned from the query
  int? count = response.Count; // returns the count of the query (if requested)
  double? aggregate = response.Aggregate; // returns the aggregate (if requested)
}

Supported Operations

Aggregate Functions

  • Average
  • Count
  • Maximum
  • Minimum
  • Sum

Comparison Functions

  • Between
  • Equal
  • Not Equal
  • Less Than
  • Less Than or Equal
  • Greater Than
  • Greater Than or Equal
  • In Set
  • Not In Set

Comparison Functions (string)

  • Contains
  • StartsWith
  • EndsWith

Grouping Functions

  • And
  • Or
  • Begin
  • End

Nullability Functions

  • Null
  • Not Null

Paging Functions

  • Page Number
  • Page Size
  • Include Count

Selecting Functions

  • Distinct
  • Select

Sorting Functions

  • Sort Ascending
  • Sort Descending

Using Query Operations

If you are using javascript, make sure to download the ServiceQuery.js javascript file. This allows you to use the same syntax as the .NET code below!

  using ServiceQuery;

  var request = new ServiceQueryRequestBuilder().Build();

  // This is the same as just a new object
  request = new ServiceQueryRequestBuilder()
    .Paging(1, 1000, false)
    .Build();

  // Include the count of records with the response
  request = new ServiceQueryRequestBuilder()
    .IsGreaterThan("id","10")
    .IncludeCount()
    .Build();

  // Select only the properties you want
  request = new ServiceQueryRequestBuilder()
    .Select("Id","FirstName","LastName")
    .Build();
  
  // Build AND expressions 
  request = new ServiceQueryRequestBuilder()
    .IsEqual("Id","1")
    .And()
    .StartsWith("FirstName", "John")    
    .Build();

  // Build OR expressions
  request = new ServiceQueryRequestBuilder()
    .Between("Id","1", "5")
    .Or()
    .Contains("LastName", "Smith")    
    .Build();

  // Group expressions with BEGIN, END, AND and OR. Nest as deeply as needed.
  request = new ServiceQueryRequestBuilder()
    .Begin()
      .IsEqual("Id","1")
      .And()
      .IsInSet("Status", "Created", "Open", "InProcess")
    .End()
    .Or()
    .Begin()
      .IsLessThanOrEqual("BirthDate","1/1/2000")
      .And()
      .IsNull("CloseDate")
    .End()
    .Build();

  // Sorting
  request = new ServiceQueryRequestBuilder()
    .IsEqual("Age", "21")
    .SortAsc("FirstName")
    .Build();

  // Aggregate functions
  request = new ServiceQueryRequestBuilder()
    .IsLessThan("Id", "200")
    .Sum("Age")
    .Build();

ServiceQuery Options

We currently provide the following server-side options when processing queries.

    public class ServiceQueryOptions
    {
        /// <summary>
        /// Dictionary list of property name mappings.
        /// Exposed Class -> Internal Class
        /// Default will use all queryable class property names
        /// </summary>
        public Dictionary<string, string> PropertyNameMappings { get; set; }

        /// <summary>
        /// Determine whether property names must be case sensitive or throw an exception.
        /// Default is false.
        /// </summary>
        public bool PropertyNameCaseSensitive { get; set; }
        
	/// <summary>
	/// Determine if missing BEGIN/END/AND/OR expressions throw an exception
	/// or try to add them missing ones automatiically.
	/// </summary>
        public bool AllowMissingExpressions { get; set; }
    }

Roadmap

There are several new features planned and currently in development. Visit the Issues page at the top to view the current list. Let us know if you have any requests.

About

I am a business executive and software architect with over 26 years professional experience. You can reach me via www.linkedin.com/in/danlogsdon or https://HoloModular.com

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net40 is compatible.  net403 was computed.  net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.0

    • No dependencies.
  • .NETFramework 4.5

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on ServiceQuery:

Package Downloads
ServiceBricks

The open source microservices platform. Visit https://ServiceBricks.com to learn more.

ServiceQuery.AzureDataTables

ServiceQuery allows dynamic querying of data over service boundaries. Visit http://ServiceQuery.com to learn more.

ServiceQuery.OpenAI

ServiceQuery.OpenAI allows dynamic querying of data over service boundaries using artificial intelligence. Visit https://ServiceQuery.com to learn more.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.1 9,594 4/21/2024
2.1.0 173 4/14/2024
2.0.1 192 2/20/2024
2.0.0 197 2/13/2024
1.0.8 210 2/8/2024
1.0.7 110 2/3/2024
1.0.6 341 7/7/2023
1.0.5 873 7/1/2023
1.0.4 215 6/30/2023
1.0.3 163 6/27/2023
1.0.2 155 6/26/2023
1.0.1 37,506 9/14/2022