NAME
SQL::QueryBuilder::WebApi::Role - a Moose role 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/.
A note on Moose
This role is the only component of the library that uses Moose. See
SQL::QueryBuilder::WebApi::ApiFactory for non-Moosey usage.
Structure of the library
The library consists of a set of API classes, one for each endpoint. These APIs
implement the method calls available on each endpoint.
Additionally, there is a set of "object" classes, which represent the objects
returned by and sent to the methods on the endpoints.
An API factory class is provided, which builds instances of each endpoint API.
This Moose role flattens all the methods from the endpoint APIs onto the consuming
class. It also provides methods to retrieve the endpoint API objects, and the API
factory object, should you need it.
For documentation of all these methods, see AUTOMATIC DOCUMENTATION below.
METHODS
base_url
The generated code has the base_url
already set as a default value. This method
returns (and optionally sets, but only if the API client has not been
created yet) the current value of base_url
.
api_factory
Returns an API factory object. You probably won't need to call this directly.
$self->api_factory('Pet'); # returns a SQL::QueryBuilder::WebApi::PetApi instance
$self->pet_api; # the same
AUTOMATIC DOCUMENTATION
You can print out a summary of the generated API by running the included
autodoc
script in the bin
directory of your generated library. A few
output formats are supported:
Usage: autodoc [OPTION]
-w wide format (default)
-n narrow format
-p POD format
-H HTML format
-m Markdown format
-h print this help message
-c your application class
The -c
option allows you to load and inspect your own application. A dummy
namespace is used if you don't supply your own class.
LOAD THE MODULES
To load the API packages:
use SQL::QueryBuilder::WebApi::ActiveQueryBuilderApi;
To load the models:
use SQL::QueryBuilder::WebApi::Object::Condition;
use SQL::QueryBuilder::WebApi::Object::ConditionGroup;
use SQL::QueryBuilder::WebApi::Object::HiddenColumn;
use SQL::QueryBuilder::WebApi::Object::Pagination;
use SQL::QueryBuilder::WebApi::Object::QueryColumn;
use SQL::QueryBuilder::WebApi::Object::Sorting;
use SQL::QueryBuilder::WebApi::Object::SqlQuery;
use SQL::QueryBuilder::WebApi::Object::Totals;
use SQL::QueryBuilder::WebApi::Object::Transform;
use SQL::QueryBuilder::WebApi::Object::TransformResult;
GETTING STARTED
Put the Perl SDK under the 'lib' folder in your project directory, then run the following
use lib 'lib';
use strict;
use warnings;
use SQL::QueryBuilder::WebApi::ActiveQueryBuilderApi;
use SQL::QueryBuilder::WebApi::Object::Condition;
use SQL::QueryBuilder::WebApi::Object::ConditionGroup;
use SQL::QueryBuilder::WebApi::Object::HiddenColumn;
use SQL::QueryBuilder::WebApi::Object::Pagination;
use SQL::QueryBuilder::WebApi::Object::QueryColumn;
use SQL::QueryBuilder::WebApi::Object::Sorting;
use SQL::QueryBuilder::WebApi::Object::SqlQuery;
use SQL::QueryBuilder::WebApi::Object::Totals;
use SQL::QueryBuilder::WebApi::Object::Transform;
use SQL::QueryBuilder::WebApi::Object::TransformResult;
use Data::Dumper;
my $api = SQL::QueryBuilder::WebApi::ActiveQueryBuilderApi->new();
my $metadataGuid = 'b3207f4f-b1f4-4dc2-979b-7724ed2d0221';
my $sql = 'Select customer_id, first_name From customer';
my $query = SQL::QueryBuilder::WebApi::Object::SqlQuery->new();
$query->guid( $metadataGuid );
$query->text( $sql );
my $columns = $api->get_query_columns_post(query => $query);
print Dumper($columns);
my $transform = SQL::QueryBuilder::WebApi::Object::Transform->new();
$transform->guid( $metadataGuid );
$transform->sql( $sql );
my $filter = SQL::QueryBuilder::WebApi::Object::ConditionGroup->new();
my $condition = SQL::QueryBuilder::WebApi::Object::Condition->new();
$condition->field('customer_id');
$condition->condition_operator('Greater');
$condition->values( [ '10' ] );
$filter->conditions( [ $condition ] );
my $page = SQL::QueryBuilder::WebApi::Object::Pagination->new();
$page->skip(2);
$page->take(3);
my $order = SQL::QueryBuilder::WebApi::Object::Sorting->new();
$order->field('customer_id');
$order->order('desc');
$transform->filter($filter);
$transform->pagination($page);
$transform->sortings( [ $order ] );
my $result = $api->transform_sql_post(transform => $transform);
print Dumper($result);
DOCUMENTATION FOR API ENDPOINTS
All URIs are relative to https://webapi.activequerybuilder.com
DOCUMENTATION FOR MODELS
DOCUMENTATION FOR AUTHORIATION
All endpoints do not require authorization.
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-perl