Gz-Db

0.1.0


# Gz-Db Module

Database agnostic Powershell functions over ADO.NET.

The primary functions are Invoke-GzDbCommand, Read-GzDbData, and Write-GzDbData. If
a connection or connectionString is not provided to the functions, the functions
will attempt to use the default connection set by Set-GzDbConnectionString.

Any function that has a `-Do` parameter, can be

# Gz-Db Module

Database agnostic Powershell functions over ADO.NET.

The primary functions are Invoke-GzDbCommand, Read-GzDbData, and Write-GzDbData. If
a connection or connectionString is not provided to the functions, the functions
will attempt to use the default connection set by Set-GzDbConnectionString.

Any function that has a `-Do` parameter, can be passed a script block that will
have the `$_` context variable set with either the connection or command object.

Sqlite is bundled with module.  To switch the default provider use:

```powershell
Set-GzDbProviderFactoryDefault "Sqlite"
```

## Examples


- Set-GzDbConnectionString - sets the default or a named connection string.
- New-GzDbConnection - creates a new connection
- Write-GzDbData - inserts or updates data in the database.
- Read-GzDbData - reads data from the database.
- Invoke-GzDbCommand - executes a statement such as create database or grants.

```powershell
Set-GzDbConnectionString "Server=localhost;Database=test;Integrate Security=true" -Name "Default"

# uses the default connection string set above
$data = Read-GzDbData "SELECT name FROM [users]"
Write-Host $data  

# control the connection
$connection = New-GzDbConnection -ConnectionString $cs
$connection.Open()

$emails = $connection | Read-GzDbData "SELECT email FROM [users]"
$connection | Write-GzDbData "INSERT [name] INTO [user_roles] ([name], [role]) VALUES (@name, 1)" -Parameters @{name = "test"}

$connection.Dispose()

# opens and closes the connection
# autocreates a `$Connection` variable
# returns any output.
$data = New-GzDbConnection -Do {
  return  $Connection | Read-GzDbData "SELECT email FROM [users]"
}

```

## Gz Prefix

The Gz prefix exists to clobbering.

Add-GzDbAlias will set aliases that map to GzDb functions .e.g. Invoke-DbCommand
will be mapped to Invoke-GzDbCommand.  
Show more

Minimum PowerShell version

5.1

Installation Options

Copy and Paste the following command to install this package using PowerShellGet More Info

Install-Module -Name Gz-Db

Copy and Paste the following command to install this package using Microsoft.PowerShell.PSResourceGet More Info

Install-PSResource -Name Gz-Db

You can deploy this package directly to Azure Automation. Note that deploying packages with dependencies will deploy all the dependencies to Azure Automation. Learn More

Manually download the .nupkg file to your system's default download location. Note that the file won't be unpacked, and won't include any dependencies. Learn More

Owners

Copyright

(c) 2017-2019 Nerdy Mishka, Michael Herndon. All rights reserved.

Package Details

FileList

Version History

Version Downloads Last updated
0.1.0 (current version) 3,624 3/17/2019