SqlBuilder Class OverviewThe 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.
Initializes the SqlBuilder with the provided arguments.
const sqlBuilder = new SqlBuilder({
name: 'mySqlInstance',
group: { resourceGroupName: 'myResourceGroup' },
// other necessary arguments
});
withVulnerabilityAssessmentIfConditionally sets the vulnerability assessment properties for the SQL instance.
sqlBuilder.withVulnerabilityAssessmentIf(true, {
// SqlBuilderVulnerabilityAssessmentType properties
});
withVulnerabilityAssessmentSets the vulnerability assessment properties for the SQL instance.
sqlBuilder.withVulnerabilityAssessment({
// SqlBuilderVulnerabilityAssessmentType properties
});
withElasticPoolSets the elastic pool properties for the SQL instance.
sqlBuilder.withElasticPool({
// SqlElasticPoolType properties
});
withTierSets the default SKU for the SQL databases.
sqlBuilder.withTier('S1');
withDatabasesSets the databases for the SQL instance.
sqlBuilder.withDatabases({
name: 'myDatabase',
// other FullSqlDbPropsType properties
});
copyDbCopies an existing database to a new database.
sqlBuilder.copyDb({
name: 'newDatabase',
fromDbId: 'existingDatabaseId',
// other SqlFromDbType properties
});
replicaDbCreates a replica of an existing database.
sqlBuilder.replicaDb({
name: 'replicaDatabase',
fromDbId: 'existingDatabaseId',
// other SqlFromDbType properties
});
withNetworkSets the network properties for the SQL instance.
sqlBuilder.withNetwork({
// SqlNetworkType properties
});
withAuthOptionsSets the authentication options for the SQL instance.
sqlBuilder.withAuthOptions({
// SqlBuilderAuthOptionsType properties
});
generateLoginEnables the generation of a random login for the SQL instance.
sqlBuilder.generateLogin();
withLoginInfoSets the login information for the SQL instance.
sqlBuilder.withLoginInfo({
adminLogin: 'adminUser',
password: 'securePassword',
});
ignoreChangesFromSpecifies properties to ignore changes for.
sqlBuilder.ignoreChangesFrom('property1', 'property2');
lockEnables or disables locking of the SQL instance.
sqlBuilder.lock(true);
buildLoginGenerates a random login if enabled.
This method is called internally by the build method and is not typically called directly.
buildSqlCreates the SQL instance with the specified configurations.
This method is called internally by the build method and is not typically called directly.
buildBuilds the SQL instance and returns the results.
const sqlResults = sqlBuilder.build();
console.log(sqlResults);
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);
This guideline should help developers understand and reuse the methods in the SqlBuilder class effectively.