Connecting to the Database

To start working with my ORM system, you need to set up a database connection. Below is an example of connecting to a PostgreSQL database.

An example of connecting to PostgreSQL:

import {DatabaseManager, DatabasesTypes, DataSourceContext} from "@myroslavshymon/orm";

// Створення екземпляру DatabaseManager для PostgreSQL
export const databaseManager = new DatabaseManager<DatabasesTypes.POSTGRES>(
    {
        type: DatabasesTypes.POSTGRES,
        host: 'localhost',
        user: 'postgres',
        password: 'xxx',
        port: 5432,
        database: 'first',
        models: [
            Users,
        ],
    },
    new DataSourceContext()
);

// Створення ORM підключення
(async () => {
    await databaseManager.createOrmConnection()
})();

Configuration Parameters

  • type: The type of database (MySQL or PostgreSQL).

  • host: The address of the database server.

  • user: The username for connecting to the database.

  • password: The password for connecting to the database.

  • port: The port on which the database is running.

  • database: The name of the database.

  • models: An array of models that will be used in your ORM system.

Code Description

  1. Importing Required Modules: First, import the necessary modules from your ORM library.

  2. Creating an Instance of DatabaseManager: An instance of DatabaseManager is created, where the database connection parameters are specified.

  3. Creating ORM Connection: The createOrmConnection method is called to establish the connection to the database.

This code allows you to quickly set up a database connection and start working with my ORM system.

Last updated