https://github.com/potatoqualitee/PSPostgres
PowerShell binary module for Postgres
https://github.com/potatoqualitee/PSPostgres
Last synced: 5 months ago
JSON representation
PowerShell binary module for Postgres
- Host: GitHub
- URL: https://github.com/potatoqualitee/PSPostgres
- Owner: potatoqualitee
- License: mit
- Created: 2023-02-02T21:10:38.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-02T21:10:41.000Z (about 2 years ago)
- Last Synced: 2024-11-13T06:50:43.103Z (5 months ago)
- Language: C#
- Size: 6.84 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - potatoqualitee/PSPostgres - PowerShell binary module for Postgres (C# #)
README
# PSPostgres
Simple PowerShell binary wrapper for Npgsql, somewhat based on [cbsch-pgsql](https://github.com/cbsch/cbsch-pgsql).For more advanced functionality, check out [dbops](https://github.com/dataplat/dbops).
# Examples
```powershell
# Connect to a Postgres database and execute a statement that creates a table.$conn = Connect-Postgres -ConnectionString $env:PGSQLConn
Invoke-PostgresQuery -Connection $conn -Query @"
CREATE TABLE test(
id int,
guid uuid,
date timestamp with time zone,
smallint integer,
bigint bigint,
double double precision
)
"@# Connect to a Postgres database and execute a statement that safely inserts a row using a parameterized query.
$conn = Connect-Postgres -ConnectionString $env:PGSQLConn
Invoke-PostgresQuery -Connection $conn -Query @"
INSERT INTO test(id, guid, date, smallint, bigint, double)
VALUES(@id, @guid, @date, @smallint, @bigint, @double)
"@ -Parameters @{
"@id" = 1
"@guid" = [Guid]::NewGuid()
"@date" = [DateTime]::Now
"@smallint" = 42
"@bigint" = [Int64]::MaxValue
"@double" = 0.23
}# Connects to a Postgres database and executes a simple query.
$conn = Connect-Postgres -ConnectionString $env:PGSQLConn
Invoke-PostgresQuery -Connection $conn -Query "SELECT * FROM test"
```