|
| 1 | +#!/usr/bin/env pwsh |
| 2 | +# Interactive DB-query demo: type a query, press Run, scroll the results. Full-screen Terminal.Gui, |
| 3 | +# authored in PowerShell on the reactive store. |
| 4 | +# |
| 5 | +# dotnet build src/Strata.Dsl.TerminalGui/Strata.Dsl.TerminalGui.csproj |
| 6 | +# pwsh -File samples/Strata.Demo.PowerShell/db-query.ps1 |
| 7 | +# |
| 8 | +# Tab/arrows move focus, Enter activates the focused control, Esc quits. |
| 9 | + |
| 10 | +$binDir = Resolve-Path "$PSScriptRoot/../../src/Strata.Dsl.TerminalGui/bin/Debug/net10.0" |
| 11 | +[System.Runtime.Loader.AssemblyLoadContext]::Default.add_Resolving({ |
| 12 | + param($context, $assemblyName) |
| 13 | + $candidate = Join-Path $binDir "$($assemblyName.Name).dll" |
| 14 | + if (Test-Path $candidate) { return $context.LoadFromAssemblyPath($candidate) } |
| 15 | + return $null |
| 16 | +}) |
| 17 | +Add-Type -Path (Join-Path $binDir 'Strata.Dsl.TerminalGui.dll') |
| 18 | +Import-Module "$PSScriptRoot/../../src/Strata.PowerShell/Strata.PowerShell.psd1" -Force |
| 19 | + |
| 20 | +# Stand-in data source so the demo runs with no database. |
| 21 | +function Invoke-DemoQuery([string]$q) { |
| 22 | + 1..8 | ForEach-Object { "row $_ :: $q" } |
| 23 | +} |
| 24 | + |
| 25 | +$store = New-StrataStore @{ query = 'SELECT * FROM users'; rows = @() } |
| 26 | + |
| 27 | +$layout = Stack -Class 'app' { |
| 28 | + Text 'DB Query' -Class 'h1' |
| 29 | + TextField -Bind '$.query' |
| 30 | + Button 'Run' -OnSelect { |
| 31 | + param($ctx) |
| 32 | + $q = $ctx.Store.State['query'].ToString() |
| 33 | + Update-StrataStore $ctx.Store -Set '$.rows' -Value (Invoke-DemoQuery $q) |
| 34 | + } |
| 35 | + List -Bind '$.rows' |
| 36 | +} |
| 37 | + |
| 38 | +Show-StrataApp -Layout $layout -Store $store -Stylesheet "$PSScriptRoot/query.css" |
0 commit comments