Skip to content

View

File extension: *.view

Overview:

The *.view files in the codbex platform are used to define and manage database views. Views are virtual tables that represent the result of a stored query.

Here's an explanation of the example PERSONS_VIEW.view file and its properties:

{
    "name": "PERSONS_VIEW",
    "type": "VIEW",
    "query": "SELECT * FROM PERSONS",
    "dependencies": [
        "table:/my-project/tables/PERSONS.table:PERSONS"
    ]
}

Properties:

  • name (String): Specifies the name of the view. In this example, it is named PERSONS_VIEW.
  • type (String): Indicates the type of the artifact, and for views, it is set to VIEW.
  • query (String): Contains the SQL query that defines the view. In this example, it is SELECT * FROM PERSONS, which retrieves all columns from the PERSONS table.
  • dependencies (Array of Strings): Lists the dependencies of the view. Each dependency is specified in the format artifactType:artifactLocation:artifactName. In this example, the view depends on the "PERSONS" table.

Example Usage:

The example PERSONS_VIEW.view file defines a view named PERSONS_VIEW that represents the result of the SQL query SELECT * FROM PERSONS. It depends on the PERSONS table.

Getting Started:

Create a View File:

Create a new *.view file or modify an existing one based on your specific view requirements.

Define Query:

Specify the SQL query within the query property to define the content of the view.

Set Dependencies:

Specify any tables or artifacts on which the view depends within the dependencies array. This ensures that the necessary data is available for the view.

Use the View:

Once defined, the view can be used in queries and applications as if it were a table, providing a virtual representation of the underlying data.

Best Practices:

Clear Naming Conventions:

Follow clear and consistent naming conventions for views to ensure easy identification and reference.

Optimize Query:

Optimize the SQL query within the query property to retrieve only the necessary columns and rows for efficient performance.

Conclusion:

The *.view files in the platform provide a convenient way to define virtual tables based on SQL queries. Views can be used to simplify complex queries, encapsulate logic, and provide a structured way to access and present data.