Skip to main content
ServiceQuery Logo

Get Started

Open Source


ServiceQuery is open source software and is free to use for commercial purposes. It is available under the MIT permissive license.

Example Applications

Explore all of our example applications. We have provided examples supporting the most popular database engines, such as SqlServer, MongoDB, Azure Data Tables, Cosmos, Sqlite, PostgreSQL, and more! View our GitHub repository to view them all.

View Examples Repository »

Query Your Database with Artificial Intelligence

We have released a companion package ServiceQuery.OpenAI that allows you to query your database using OpenAI GPT LLMs and simple human text input. Check out our repository for more information.

How to Use


Installing

ServiceQuery is available as a NuGet package. You can install it using the .NET CLI or Visual Studio Package Manager Console.

Install NuGet Package: ServiceQuery

Simple Database Access

Query your database in just a few lines of code:

using ServiceQuery;

// Get your Database Table/Collection as an IQueryable object
var queryable = databaseContext.ExampleTable.AsQueryable();

// Build a request using the ServiceQueryRequestBuilder object
var request = new ServiceQueryRequestBuilder().Build();

// Execute the request against the database and get the results
var response = request.Execute(queryable);

Use in a REST API

Query your database using a REST API in just a few lines of code:

using ServiceQuery;

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

Use in Javascript/JQuery

Query your database from a web page using javascript/jquery. Make sure to include the servicequery.js file in your project. It uses the exact same syntax as .NET code!

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

function GetAllRecords() {
var request = new ServiceQueryRequestBuilder().Build();
$.ajax({
url: '/api/Example/ServiceQuery',
data: JSON.stringify(request),
type: "POST",
dataType: 'json',
headers: { 'Content-Type': 'application/json' },
success: function (result) {
alert(result.list.length + ' records returned');
}
});
}
</script>

How to Build Queries


Default Properties

All queries are paged, with the default:

ServiceQueryRequestBuilder

Build complex queries using the ServiceQueryRequestBuilder object.

Make sure to include the servicequery.js file in your project if you are using javascript. It uses the exact same syntax as the .NET code below.

Example Operations


// Just the defaults
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("Price")
.Build();

Need More Help?

We are here to help! We have a dedicated team of developers ready to assist you with any questions you may have.