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
});
withVulnerabilityAssessmentIf
Conditionally sets the vulnerability assessment properties for the SQL instance.
sqlBuilder.withVulnerabilityAssessmentIf(true, {
// SqlBuilderVulnerabilityAssessmentType properties
});
withVulnerabilityAssessment
Sets the vulnerability assessment properties for the SQL instance.
sqlBuilder.withVulnerabilityAssessment({
// SqlBuilderVulnerabilityAssessmentType properties
});
withElasticPool
Sets the elastic pool properties for the SQL instance.
sqlBuilder.withElasticPool({
// SqlElasticPoolType properties
});
withTier
Sets the default SKU for the SQL databases.
sqlBuilder.withTier('S1');
withDatabases
Sets the databases for the SQL instance.
sqlBuilder.withDatabases({
name: 'myDatabase',
// other FullSqlDbPropsType properties
});
copyDb
Copies an existing database to a new database.
sqlBuilder.copyDb({
name: 'newDatabase',
fromDbId: 'existingDatabaseId',
// other SqlFromDbType properties
});
replicaDb
Creates a replica of an existing database.
sqlBuilder.replicaDb({
name: 'replicaDatabase',
fromDbId: 'existingDatabaseId',
// other SqlFromDbType properties
});
withNetwork
Sets the network properties for the SQL instance.
sqlBuilder.withNetwork({
// SqlNetworkType properties
});
withAuthOptions
Sets the authentication options for the SQL instance.
sqlBuilder.withAuthOptions({
// SqlBuilderAuthOptionsType properties
});
generateLogin
Enables the generation of a random login for the SQL instance.
sqlBuilder.generateLogin();
withLoginInfo
Sets the login information for the SQL instance.
sqlBuilder.withLoginInfo({
adminLogin: 'adminUser',
password: 'securePassword',
});
ignoreChangesFrom
Specifies properties to ignore changes for.
sqlBuilder.ignoreChangesFrom('property1', 'property2');
lock
Enables or disables locking of the SQL instance.
sqlBuilder.lock(true);
buildLogin
Generates a random login if enabled.
This method is called internally by the build
method and is not typically called directly.
buildSql
Creates the SQL instance with the specified configurations.
This method is called internally by the build
method and is not typically called directly.
build
Builds 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.