ActiveDbSoft / webapi-active-query-builder-csharp

Active Query Builder WebAPI client for .NET

Home Page:https://webapi.activequerybuilder.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WebApi.ActiveQueryBuilder - the C# library for the QueryBuilderApi

Active Query Builder Web API lets create, analyze and modify SQL queries for different database servers using RESTful HTTP requests to a cloud-based service. It requires SQL execution context (information about database schema and used database server) to be stored under the registered account at https://webapi.activequerybuilder.com/.

Frameworks supported

  • .NET 4.0 or later
  • Windows Phone 7.1 (Mango)

Dependencies

The DLLs included in the package may not be the latest version. We recommned using [NuGet] (https://docs.nuget.org/consume/installing-nuget) to obtain the latest version of the packages:

Install-Package RestSharp
Install-Package Newtonsoft.Json

NOTE: RestSharp versions greater than 105.1.0 have a bug which causes file uploads to fail. See RestSharp#742

Installation

Include the DLL in the C# project, and use the namespaces:

using WebApi.ActiveQueryBuilder.Api;
using WebApi.ActiveQueryBuilder.Client;
using WebApi.ActiveQueryBuilder.Model;

Getting Started

using System;
using System.Collections.Generic;
using System.Diagnostics;
using WebApi.ActiveQueryBuilder.Api;
using WebApi.ActiveQueryBuilder.Client;
using WebApi.ActiveQueryBuilder.Model;

namespace Example
{
    public class Example
    {
        public void main()
        {
            string sql = "Select customer_id, first_name From customer";
            string metadataGuid = "b3207f4f-b1f4-4dc2-979b-7724ed2d0221";

            var apiInstance = new ActiveQueryBuilderApi();
            
            var query = new SqlQuery() // SqlQuery | Information about SQL query and it's context.
            {
              Guid = metadataGuid,
              Text = sql
            };
            
            List<QueryColumn> columns = apiInstance.GetQueryColumnsPost(query);
            Debug.WriteLine("API called successfully. Returned columns: " + columns.Count);
            
            var transform = new Transform
            {
                Guid = metadataGuid,
                Sql = sql
            };

            var filter = new ConditionGroup();

            var conditionGroup = new ConditionGroup();

            var condition = new Condition
            {
                Field = "customer_id",
                ConditionOperator = Condition.ConditionOperatorEnum.Greater,
                Values = new List<string> { "10" }
            };
            
            conditionGroup.Conditions = new List<Condition> { condition };

            filter.ConditionGroups = new List<ConditionGroup> { conditionGroup };

            var page = new Pagination { Skip = 2, Take = 3 };
            var order = new Sorting { Field = "customer_id", Order = Sorting.OrderEnum.Desc };            

            transform.Filter = filter;
            transform.Pagination = page;
            transform.Sortings = new List<Sorting> { order };

            TransformResult result = apiInstance.TransformSQLPost(transform);
            Debug.WriteLine("API called successfully. Returned result: " + result.Sql);
        }
    }
}

Documentation for API Endpoints

All URIs are relative to https://webapi.activequerybuilder.com

Class Method HTTP request Description
ActiveQueryBuilderApi GetQueryColumnsPost POST /getQueryColumns
ActiveQueryBuilderApi TransformSQLPost POST /transformSQL

Documentation for Models

Source code

Full source code of all clients for Active Query Builder Web API is available on GitHub. Get the source code of javascript here: https://github.com/ActiveDbSoft/webapi-active-query-builder-csharp

About

Active Query Builder WebAPI client for .NET

https://webapi.activequerybuilder.com/

License:Apache License 2.0


Languages

Language:C# 95.9%Language:Shell 2.9%Language:Batchfile 1.2%