Introduction

GoooQo

GoooQo is a CRUD framework in Golang based on the OQM technique.

The OQM (Object-Query Mapping) technique is a database access technique that constructs database query statements through objects.

OQM proposes a new method to solve the problem of the dynamic combination of n query conditions by mapping 2^n assignment combinations of an object instance with n fields to 2^n combinations of n query conditions. Or simply, one field to one condition, one assigned field to one combined condition.

This approach enables developers to define and construct objects only to build dynamic query statements, setting OQM apart from ORM.

Such objects are called query objects, which is the Qo in GoooQo.

The first three Os in the name GoooQo stands for the three major object concepts in OQM:

  • Entity Object is used to map the static part in the SQL statements, such as the table name and column names;

  • Query Object is used to map the dynamic part of the SQL statements, such as filter conditions, pagination, and sorting;

  • View Object is used to map the static part in complex query statements, such as table names, column names, nested views, and the GROUP BY clause.

The Dynamic Combination of Query Conditions ​

A query interface with n query conditions can generate 2^n unique query requests by combining different parameter values to construct corresponding query statements.

Similarly, an object with n fields has 2^n different assignment combinations.

The 2^n assignment combinations of object instances are mapped exactly to 2^n combinations of query conditions.

OQM technology leverages this relationship and introduces the query object mapping method, where each field of the query object corresponds to a query condition, and query clauses are constructed based on field assignments.

In this way, the logic of building query clauses can be separated from the logic of constructing query parameters and encapsulated as common functions in a framework, allowing developers to focus solely on the definition and assignment of query objects.

The Definition of the Query​ Object

A basic query condition consists of a column name, a comparison operator, and a value. The fields in the entity correspond to the column names. When we use aliases to represent comparison operators and combine them with the fields in an entity object as suffixes, we get the fields of the query object. Therefore, we have the following formula:

Here is an example:

Community

Gitter: https://gitter.im/doytowin/goooqo

Discussion: https://github.com/doytowin/goooqo/discussions

Last updated