drunk-pulumi-azure

SqlBuilder Class Overview

The SqlBuilder class is designed to build and configure an Azure SQL instance with specific configurations such as login, authentication options, network settings, elastic pool, databases, and vulnerability assessment.

Constructor

Purpose:

Initializes the SqlBuilder with the provided arguments.

Sample Usage:

const sqlBuilder = new SqlBuilder({
  name: 'mySqlInstance',
  group: { resourceGroupName: 'myResourceGroup' },
  // other necessary arguments
});

withVulnerabilityAssessmentIf

Purpose:

Conditionally sets the vulnerability assessment properties for the SQL instance.

Sample Usage:

sqlBuilder.withVulnerabilityAssessmentIf(true, {
  // SqlBuilderVulnerabilityAssessmentType properties
});

withVulnerabilityAssessment

Purpose:

Sets the vulnerability assessment properties for the SQL instance.

Sample Usage:

sqlBuilder.withVulnerabilityAssessment({
  // SqlBuilderVulnerabilityAssessmentType properties
});

withElasticPool

Purpose:

Sets the elastic pool properties for the SQL instance.

Sample Usage:

sqlBuilder.withElasticPool({
  // SqlElasticPoolType properties
});

withTier

Purpose:

Sets the default SKU for the SQL databases.

Sample Usage:

sqlBuilder.withTier('S1');

withDatabases

Purpose:

Sets the databases for the SQL instance.

Sample Usage:

sqlBuilder.withDatabases({
  name: 'myDatabase',
  // other FullSqlDbPropsType properties
});

copyDb

Purpose:

Copies an existing database to a new database.

Sample Usage:

sqlBuilder.copyDb({
  name: 'newDatabase',
  fromDbId: 'existingDatabaseId',
  // other SqlFromDbType properties
});

replicaDb

Purpose:

Creates a replica of an existing database.

Sample Usage:

sqlBuilder.replicaDb({
  name: 'replicaDatabase',
  fromDbId: 'existingDatabaseId',
  // other SqlFromDbType properties
});

withNetwork

Purpose:

Sets the network properties for the SQL instance.

Sample Usage:

sqlBuilder.withNetwork({
  // SqlNetworkType properties
});

withAuthOptions

Purpose:

Sets the authentication options for the SQL instance.

Sample Usage:

sqlBuilder.withAuthOptions({
  // SqlBuilderAuthOptionsType properties
});

generateLogin

Purpose:

Enables the generation of a random login for the SQL instance.

Sample Usage:

sqlBuilder.generateLogin();

withLoginInfo

Purpose:

Sets the login information for the SQL instance.

Sample Usage:

sqlBuilder.withLoginInfo({
  adminLogin: 'adminUser',
  password: 'securePassword',
});

ignoreChangesFrom

Purpose:

Specifies properties to ignore changes for.

Sample Usage:

sqlBuilder.ignoreChangesFrom('property1', 'property2');

lock

Purpose:

Enables or disables locking of the SQL instance.

Sample Usage:

sqlBuilder.lock(true);

buildLogin

Purpose:

Generates a random login if enabled.

Sample Usage:

This method is called internally by the build method and is not typically called directly.

buildSql

Purpose:

Creates the SQL instance with the specified configurations.

Sample Usage:

This method is called internally by the build method and is not typically called directly.

build

Purpose:

Builds the SQL instance and returns the results.

Sample Usage:

const sqlResults = sqlBuilder.build();
console.log(sqlResults);

Full Example

Here is a full example demonstrating how to use the SqlBuilder class:

import SqlBuilder from './Builder/SqlBuilder';
import { SqlBuilderArgs } from './types';

const args: SqlBuilderArgs = {
  name: 'mySqlInstance',
  group: { resourceGroupName: 'myResourceGroup' },
  // other necessary arguments
};

const sqlBuilder = new SqlBuilder(args);

sqlBuilder
  .withVulnerabilityAssessmentIf(true, {
    // SqlBuilderVulnerabilityAssessmentType properties
  })
  .withElasticPool({
    // SqlElasticPoolType properties
  })
  .withTier('S1')
  .withDatabases({
    name: 'myDatabase',
    // other FullSqlDbPropsType properties
  })
  .copyDb({
    name: 'newDatabase',
    fromDbId: 'existingDatabaseId',
    // other SqlFromDbType properties
  })
  .replicaDb({
    name: 'replicaDatabase',
    fromDbId: 'existingDatabaseId',
    // other SqlFromDbType properties
  })
  .withNetwork({
    // SqlNetworkType properties
  })
  .withAuthOptions({
    // SqlBuilderAuthOptionsType properties
  })
  .generateLogin()
  .withLoginInfo({
    adminLogin: 'adminUser',
    password: 'securePassword',
  })
  .ignoreChangesFrom('property1', 'property2')
  .lock(true);

const sqlResults = sqlBuilder.build();
console.log(sqlResults);

Summary

This guideline should help developers understand and reuse the methods in the SqlBuilder class effectively.