Database | Config & Commands

Adding Database Module

To integrate the Database module into your framework, follow these steps:

Configuration

  1. Open the app/Config.js file.

  2. Add the following lines to configure the Database module:

database: {
    module: require("etherial/components/database").Database,

    config: {
        server: process.env.DATABASE_SERVER,
        port: process.env.DATABASE_PORT,
        username: process.env.DATABASE_USERNAME,
        password: process.env.DATABASE_PASSWORD,
        name: process.env.DATABASE_NAME,
        secure: process.env.DATABASE_SECURE,
        dialect: process.env.DATABASE_DIALECT,
        models: [
            process_path("models"),
        ],
    },
},
  1. Customize the configuration parameters according to your specific setup. Here's a description of each parameter:

Database Configuration Parameters

  • server: The hostname or IP address of the database server (e.g., "localhost").

  • port: The port number for the database server (e.g., "3306").

  • username: The username used to authenticate with the database.

  • password: The password used to authenticate with the database.

  • name: The name of the database you want to connect to.

  • secure: A boolean indicating whether to use a secure connection (e.g., true or false).

  • dialect: The type of database dialect to use (e.g., "postgres" or "mysql").

  • models: An array of paths to the directory where your database models are located. You can customize this to fit your project structure.

  1. Save the app/Config.js file.

Database Configuration Type

To make it easier to work with the Database module, you can define a TypeScript interface or GraphQL type for the configuration. Here's an example TypeScript interface called DatabaseConfig:

You can use this DatabaseConfig type in your code to ensure that the configuration object adheres to the expected structure.

That's it! You have successfully added the Database module to Etherial and configured it for use. Make sure to customize the configuration parameters and paths to match your specific project requirements.

I see, you want separate documentation for each of the two commands: database:destroy and database:load:fixtures. Here are the individual documentation sections for each command:

Commands

Database Destroy Command

Command Name: database:destroy

This command is used to destroy the database in order to recreate it properly. It is invoked with the following command:

Description

This command will delete all data in the database and then recreate it from scratch. Use this command with caution as it will result in the loss of all data in the database.

Usage

Action

When executed, the command performs the following action:

  • It synchronizes the Sequelize models with the database and forces the synchronization, effectively dropping all existing tables and re-creating them.

  • If successful, it returns a success message. If an error occurs during the process, it returns an error message.

Database Load Fixtures Command

Command Name: database:load:fixtures

This command is used to load fixtures into the database. It also has an environment parameter to specify which fixtures file to load and will destroy the existing database before loading fixtures. It is invoked with the following command:

Description

This command loads fixtures into the database, overwriting existing data. It should be used when you want to populate the database with predefined data for a specific environment.

Usage

  • <env>: The environment for which you want to load fixtures (e.g., prod, dev, test).

Action

When executed, the command performs the following action:

  • It synchronizes the Sequelize models with the database and forces the synchronization, effectively dropping all existing tables and re-creating them.

  • It loads fixtures from a JSON file based on the specified environment (<env> parameter) using the sequelize-fixtures library.

  • If successful, it returns a success message. If an error occurs during the process, it returns an error message.

You can now use these individual documentation sections for the database:destroy and database:load:fixtures commands as reference documentation for your framework users.

Last updated

Was this helpful?