Instruction file imported from SynEdgy/PSUConfig (
.github/instructions/data-access.instructions.md). Copyright stays with the author.
Data Access Guidelines (synedgy.PSSqlite)
Use the synedgy.PSSqlite CRUD helpers; do not hand-write SQL or open Microsoft.Data.Sqlite.SqliteConnection directly except inside helpers that genuinely need raw access.
Cmdlet selection
- Read:
Get-PSSqliteRow. - Insert:
New-PSSqliteRow(returns the inserted row viaRETURNING *). - Update:
Set-PSSqliteRow. - Delete:
Remove-PSSqliteRow. - Raw SQL (only when CRUD is insufficient):
Invoke-PSSqliteQuery -SqliteConnection $conn -CommandText '...' -Parameters @{ ... }. Always parameterise; never interpolate user input intoCommandText.
Parameter conventions
- Pass the cached
[synedgy.PSSqlite.SqliteDBConfig]fromGet-PSUConfigDatabaseConfigurationto the-SqliteDBConfigparameter. Do not reload the YAML inside functions. - Pass
-TableNameas a literal string matchingschema.Tables.<Name>in the YAML. -RowDataand-ClauseDataaccept[System.Collections.IDictionary]. Keys must match column names declared in the schema; unknown keys emitWrite-Warningand are silently dropped.$nullvalues in-RowDataare dropped (useInvoke-PSSqliteQuerywithDBNULLif a NULL write is required).
ClauseData query semantics
- Exact match on column
Foo:@{ Foo = 'bar' }→Foo = @Foo. - Wildcard: any value containing
*is rewritten to SQLLIKEwith%(e.g.@{ Name = 'John*' }→Name LIKE 'John%'). - Range suffixes: keys ending in
Before/Aftermap to</>against the stripped column name. Example:@{ createdBefore = $cutoff }→created < @createdBefore. - Default collation is
COLLATE NOCASE. Pass-CaseSensitivewhen binary equality matters. - Index any column you query in
ClauseData(indexed: truein the schema YAML).
Connection lifetime
- Default: each CRUD call opens and closes its own connection (and clears the pool).
- For batches in the same function, create one connection with
New-PSSqliteConnection -ConnectionString $SqliteDBConfig.ConnectionString, pass it via-SqliteConnectionto every call with-KeepAlive, and close it withClose-PSSqliteConnectioninend { }. :memory:databases require-KeepAlivefor the entire lifetime of the data; closing drops the DB.
Output shape
Get-PSSqliteRowreturns[PSCustomObject]by default. Do not change the-Asparameter from public functions (it isDontShow); rely on the default.New-PSSqliteRowreturns the inserted row(s); capture it when the caller needs the generatedid.
Initialization
- Module-level DB init goes through
Initialize-PSUConfigDB(which wrapsInitialize-PSSqliteDatabase). Do not callInitialize-PSSqliteDatabasedirectly from public functions. MigrationModedefaults toINCREMENTAL. Pass-Forceonly from administrative entry points; it impliesOVERWRITEand drops all data.
