Functions/Columns/New-BigIntColumn.ps1
function New-BigIntColumn { <# .SYNOPSIS Creates a column object representing an BigInt datatype. .DESCRIPTION Use this function in the `Column` script block for `Add-Table`: Add-Table 'Migrations' { BigInt 'MigrationID' } ## ALIASES * BigInt .EXAMPLE Add-Table 'Migrations' { BigInt 'MigrationID' } Demonstrates how to create an optional `bigint` column called `MigrationID`. .EXAMPLE Add-Table 'Migrations' { BigInt 'ID' -Identity 1 1 } Demonstrates how to create a required `bigint` column called `ID`, which is used as the table's identity. The identity values will start at 1, and increment by 1. .EXAMPLE Add-Table 'Migrations' { BigInt 'MigrationID' -NotNull } Demonstrates how to create a required `bigint` column called `MigrationID`. .EXAMPLE Add-Table 'Migrations' { BigInt 'MigrationID' -Sparse } Demonstrates how to create a sparse, optional `bigint` column called `MigrationID`. .EXAMPLE Add-Table 'Migrations' { BigInt 'MigrationID' -NotNull -Default '0' } Demonstrates how to create a required `bigint` column called `MigrationID` with a default value of `0`. .EXAMPLE Add-Table 'Migrations' { BigInt 'MigrationID' -NotNull -Description 'The number of items currently on hand.' } Demonstrates how to create a required `bigint` column with a description. #> [CmdletBinding(DefaultParameterSetName='Nullable')] param( [Parameter(Mandatory=$true,Position=0)] [string] # The column's name. $Name, [Parameter(Mandatory=$true,ParameterSetName='Identity')] [Parameter(Mandatory=$true,ParameterSetName='IdentityWithSeed')] [Switch] # The column should be an identity. $Identity, [Parameter(Mandatory=$true,ParameterSetName='IdentityWithSeed',Position=1)] [int] # The starting value for the identity. $Seed, [Parameter(Mandatory=$true,ParameterSetName='IdentityWithSeed',Position=2)] [int] # The increment between auto-generated identity values. $Increment, [Parameter(ParameterSetName='Identity')] [Parameter(ParameterSetName='IdentityWithSeed')] [Switch] # Stops the identity from being replicated. $NotForReplication, [Parameter(Mandatory=$true,ParameterSetName='NotNull')] [Switch] # Don't allow `NULL` values in this column. $NotNull, [Parameter(ParameterSetName='Nullable')] [Switch] # Store nulls as Sparse. $Sparse, [Parameter()] [string] # A SQL Server expression for the column's default value $Default, [Parameter()] [string] # A description of the column. $Description ) switch ($PSCmdlet.ParameterSetName) { 'Nullable' { $nullable = 'Null' if( $Sparse ) { $nullable = 'Sparse' } [Rivet.Column]::BigInt($Name, $nullable, $Default, $Description) } 'NotNull' { [Rivet.Column]::BigInt($Name,'NotNull', $Default, $Description) } 'Identity' { $i = New-Object 'Rivet.Identity' $NotForReplication [Rivet.Column]::BigInt( $Name, $i, $Description ) } 'IdentityWithSeed' { $i = New-Object 'Rivet.Identity' $Seed, $Increment, $NotForReplication [Rivet.Column]::BigInt( $Name, $i, $Description ) } } } Set-Alias -Name 'BigInt' -Value 'New-BigIntColumn' |