4. Advanced Options
Overview
The datasets in the Chainbase Network is like base metals, and the alchemists (developers) can use Manuscripts to process this data, extracting greater value from the existing data.
Protocol
Chainbase Network is committed to making data (on-chain & off-chain) more accessible, so Manuscripts allow users and developers to query and process data using SQL.
Manuscripts mainly consist of two parts.
- Schema: The definition of dataset.
- Operators: The extract, transform, and load methods which being used to extract greater value from the existing data.
Schema
Schema can be defined like this.
Developers need to define the schema of the result table, including field names, field types, and field descriptions.
Data Types
Data Type | Remarks for Data Type |
---|---|
CHAR | |
VARCHAR | |
STRING | |
BOOLEAN | |
BINARY | |
VARBINARY | |
BYTES | |
DECIMAL | Supports fixed precision and scale. |
TINYINT | |
SMALLINT | |
INTEGER | |
BIGINT | |
FLOAT | |
DOUBLE | |
DATE | |
TIMESTAMP | |
TIMESTAMP_LTZ |
Operators
SELECT & WHERE clause
The general syntax of the SELECT
statement is:
The table_expression
refers to any data set in Chainbase Network. It could be an existing table, or VALUES clause, the joined results of multiple existing tables, or a subquery. The following would read all rows from blocks
.
The select_list
specification *
means the query will resolve all columns.
Instead, a select_list
can specify a subset of available columns or make calculations using said columns. For example, if token_transfers
has columns name token_id
, token_value
and token_decimal
you could write the following query:
Rows can be filtered based on a WHERE
clause:
ORDER BY clause
The ORDER BY
clause causes the result rows to be sorted according to the specified expression(s). If two rows are equal according to the leftmost expression, they are compared according to the next expression and so on. If they are equal according to all specified expressions, they are returned in an implementation-dependent order.
LIMIT clause
LIMIT
clause constrains the number of rows returned by the SELECT
statement. In general, this clause is used in conjunction with ORDER BY
to ensure that the results are deterministic.
The following example selects the latest 10 blocks on blocks table.
SELECT DISTINCT
If SELECT DISTINCT
is specified, all duplicate rows are removed from the result set (one row is kept from each group of duplicates).
Group Aggregation
An aggregate function computes a single result from multiple input rows. For example, there are aggregates to compute the COUNT
, SUM
, AVG(average)
, MAX(maximum)
and MIN(minimum)
over a set of rows.
The standard GROUP BY
clause is also supported for aggregating data.
Joins
INNER Equi-JOIN:
OUTER Equi-JOIN:
INSERT Statement
INSERT
statements are used to add rows to a dataset.
Syntax:
Examples:
GPL
For experienced alchemists, a General-perpose Programming Language (GPL), such as Python or JavaScript, can be used to extract and process data. GPL will provides the most flexible and powerful data extraction capabilities
Coming Soon…