This class is responsible for generating database level objects like views, stored procedures, permissions, etc. You can sub-class this class to create your own SQL generation logic or implement support for other databases. The base class implements support for SQL Server. In future versions of MJ, we will break out an abstract base class that has the skeleton of the logic and then the SQL Server version will be a sub-class of that abstract base class and other databases will be sub-classes of the abstract base class as well.

Constructors

Properties

Accessors

Methods

Constructors

Properties

_sqlUtilityObject: SQLUtilityBase = ...
cascadeDeleteDependencies: Map<string, Set<string>> = ...

Tracks cascade delete dependencies between entities. Key: Entity ID whose update/delete SP is called by other entities' delete SPs Value: Set of Entity IDs that have CascadeDeletes=true and call this entity's update/delete SP

entitiesNeedingDeleteSPRegeneration: Set<string> = ...

Tracks entities that need their delete stored procedures regenerated due to cascade dependencies

entitiesQualifiedForForcedRegeneration: string[] = []

Array of entity names that qualify for forced regeneration based on the whereClause filter

filterEntitiesQualifiedForRegeneration: boolean = false

Flag indicating whether to filter entities for forced regeneration based on entityWhereClause

orderedEntitiesForDeleteSPRegeneration: string[] = []

Ordered list of entity IDs for delete SP regeneration (dependency order)

Accessors

Methods

  • Builds a complete map of cascade delete dependencies by analyzing all entities. This method populates the cascadeDeleteDependencies map without generating SQL.

    Parameters

    Returns Promise<void>

  • Parameters

    Returns {
        fetchInto: string;
        selectFields: string;
        spParams: string;
        varDeclarations: string;
    }

    • fetchInto: string
    • selectFields: string
    • spParams: string
    • varDeclarations: string
  • Parameters

    Returns {
        allParams: string;
        declarations: string;
        fetchInto: string;
        selectFields: string;
    }

    • allParams: string
    • declarations: string
    • fetchInto: string
    • selectFields: string
  • Formats a default value for use in SQL, handling special cases like SQL functions

    Parameters

    • defaultValue: string

      The default value from the database metadata

    • needsQuotes: boolean

      Whether the field type typically needs quotes

    Returns string

    Properly formatted default value for SQL

  • This function will handle the process of creating all of the generated objects like base view, stored procedures, etc. for all entities in the entities array. It will generate the SQL for each entity and then execute it.

    Parameters

    • options: {
          batchSize?: number;
          directory: string;
          enableSQLLoggingForNewOrModifiedEntities?: boolean;
          entities: EntityInfo[];
          onlyPermissions: boolean;
          pool: ConnectionPool;
          skipExecution: boolean;
          writeFiles: boolean;
      }
      • Optional batchSize?: number
      • directory: string
      • Optional enableSQLLoggingForNewOrModifiedEntities?: boolean
      • entities: EntityInfo[]
      • onlyPermissions: boolean
      • pool: ConnectionPool
      • skipExecution: boolean
      • writeFiles: boolean

    Returns Promise<{
        Files: string[];
        Success: boolean;
    }>

  • Parameters

    • options: {
          directory: string;
          enableSQLLoggingForNewOrModifiedEntities?: boolean;
          entity: EntityInfo;
          onlyPermissions: boolean;
          pool: ConnectionPool;
          skipExecution: boolean;
          writeFiles: boolean;
      }
      • directory: string
      • Optional enableSQLLoggingForNewOrModifiedEntities?: boolean
      • entity: EntityInfo
      • onlyPermissions: boolean
      • pool: ConnectionPool
      • skipExecution: boolean
      • writeFiles: boolean

    Returns Promise<{
        Files: string[];
        Success: boolean;
    }>

  • Generates an inline Table Value Function for calculating root ID for a recursive FK field The function takes both the record ID and parent ID for optimization Returns SQL to create the function including DROP IF EXISTS

    Parameters

    Returns string

  • Generates OUTER APPLY joins to inline Table Value Functions for root ID calculation Each recursive FK gets an OUTER APPLY that calls its corresponding function

    Parameters

    Returns string

  • Parameters

    • options: {
          directory: string;
          enableSQLLoggingForNewOrModifiedEntities?: boolean;
          entity: EntityInfo;
          onlyPermissions: boolean;
          pool: ConnectionPool;
          skipExecution: boolean;
          writeFiles: boolean;
      }
      • directory: string
      • Optional enableSQLLoggingForNewOrModifiedEntities?: boolean
      • entity: EntityInfo
      • onlyPermissions: boolean
      • pool: ConnectionPool
      • skipExecution: boolean
      • writeFiles: boolean

    Returns Promise<{
        files: string[];
        permissionsSQL: string;
        sql: string;
    }>

  • Identifies entities that need their delete stored procedures regenerated due to cascade dependencies on entities that had schema changes.

    Parameters

    • pool: ConnectionPool
    • changedEntityIds: Set<string>

    Returns Promise<Set<string>>

  • Parameters

    • entityName: string

    Returns {
        nameField: string;
        nameFieldIsVirtual: boolean;
    }

    • nameField: string
    • nameFieldIsVirtual: boolean
  • Gets entities that had schema changes from the ManageMetadataBase tracking. Returns a map of entity names to their IDs for entities that had update-affecting changes.

    Parameters

    Returns Promise<Map<string, string>>

  • Marks entities for delete stored procedure regeneration based on cascade dependencies. This should be called after metadata management and before SQL generation.

    Parameters

    Returns Promise<void>

  • Orders entities by their cascade delete dependencies using topological sort. Ensures that if Entity A's delete SP calls Entity B's update/delete SP, then Entity B is regenerated before Entity A.

    Parameters

    • entities: EntityInfo[]

      All entities for name lookup

    • entityIdsToOrder: Set<string>

      Set of entity IDs that need ordering

    Returns string[]

    Array of entity IDs in dependency order