docs.sheetjs.com/tests/data/knexjs.ps1

52 lines
1.7 KiB
PowerShell
Raw Normal View History

2026-01-29 04:58:19 +00:00
#!/usr/bin/env pwsh
# https://docs.sheetjs.com/docs/demos/data/knex
$oldDir = Get-Location
$tempDir = Join-Path -Path $env:TEMP -ChildPath "sheetjs-knexjs"
if (Test-Path -Path $tempDir) { Remove-Item -Path $tempDir -Recurse -Force }
New-Item -ItemType Directory -Path $tempDir | Out-Null
Set-Location -Path $tempDir
# Download sqlite CLI
Invoke-WebRequest -Uri "https://www.sqlite.org/2026/sqlite-tools-win-x64-3510200.zip" -OutFile "sqlite.zip"
Expand-Archive sqlite.zip
Move-Item */sqlite3.exe .
npm init -y
npm i --save https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz
Invoke-WebRequest -Uri "https://docs.sheetjs.com/knex/SheetJSKnexTest.js" -OutFile "SheetJSKnexTest.js"
Invoke-WebRequest -Uri "https://docs.sheetjs.com/pres.numbers" -OutFile "pres.numbers"
Copy-Item -Path "SheetJSKnexTest.js" -Destination "SheetJSKnexTestOrig.js"
# Workaround for KnexJS 0.21.20
Get-Content -Path "SheetJSKnexTestOrig.js" | ForEach-Object { $_ -replace 'better-sqlite3', 'sqlite' } | Out-File -FilePath "SheetJSKnexTest.js" -Encoding utf8
$oldVersions = @("0.21.20")
foreach ($n in $oldVersions) {
npm i --save knex@$n sqlite3
npm ls | Select-String "knex"
node SheetJSKnexTest.js
npx xlsx-cli SheetJSKnex.xlsx
.\sqlite3.exe SheetJSKnex.db 'select * from Test_Table'
}
# Newer KnexJS versions
Move-Item -Path "SheetJSKnexTestOrig.js" -Destination "SheetJSKnexTest.js" -Force
$newVersions = @("2.4", "2.5", "3.1")
foreach ($n in $newVersions) {
npm i --save knex@$n better-sqlite3
npm ls | Select-String "knex"
node SheetJSKnexTest.js
npx xlsx-cli SheetJSKnex.xlsx
.\sqlite3.exe SheetJSKnex.db 'select * from Test_Table'
}
Set-Location $oldDir
Remove-Item -Path $tempDir -Recurse -Force