Skip to content

How DB Analyzer works?

Axe API is not just a passive framework that expects all the definitions from the developer. It is a very creative framework that helps developers to reduce mistakes in the development period. In this section, we are going to talk about the DB analyzer.

  • You will learn
  • What is DB Analyzer?
  • What DB Analyzer works?
  • What is the metadata?

Analyzing the schema

Axe API fetches the database schema structure in the initialization process, and keeps it in the memory to understand what kind of tables and data structures you have. It is named DB Analyzer.

It is designed to help developers to build the API with minimum errors.

knex-schema-inspector is used under the hood. Since knex supports almost every modern relational database, it works perfectly for all of them.

Errors

Since the database schema is kept in memory, DB Analyzer checks your model definitions while you are developing the API.

DB Analyzers throws an error if you define something in your model, which is not found on the database schema.

Let's assume that you have a model like this;

ts
import { Model } from "axe-api";

class User extends Model {
  fillable() {
    return ["name", "surnamex"]; 
  }
}

export default User;

You would get the following error in your terminal if the users table doesn't have a column like surnamex.

bash
[UNDEFINED_COLUMN]

User model doesn't have the following columns on the database; "users.surnamex"

DB Analyzer checks every table and column definition.

Also, in the HTTP request handling process, it checks the column names if they are actually defined. That way, you won't get an undefined column error from the database server.

Documentation

Thanks to DB Analyzer, Axe API provides the correct database schema structure to display auto-created documentation.

You can use the following endpoint to get all API metadata, including the database schema.

bash
GET /metadata

Also, you can use the following link to get metadata of the example Axe API project (Bookstore API):

bookstore.axe-api.com/metadata

Next step

In this section, we covered what is the DB Analyzer.

In the next chapter, we are going to talk about more advanced topics such as configuration, security, transactions, etc.

Released under the MIT License.