Created
July 4, 2022 17:18
-
-
Save Cologler/1ece85b265951432484db48eac67b181 to your computer and use it in GitHub Desktop.
export database as json from deta.sh to stdout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[Parameter(Mandatory = $true)] | |
[string] $ProjectKey, | |
[Parameter(Mandatory = $true)] | |
[string] $BaseName | |
) | |
$BaseUrl = "https://database.deta.sh/v1" | |
$ProjectId = $ProjectKey.Substring(0, $ProjectKey.IndexOf('_')) | |
$RootUrl = "$BaseUrl/$ProjectId/$BaseName" | |
$Items = @{ } | |
while ($true) { | |
$Payload = @{ } | |
if ($Last) { | |
$Payload.Add("last", $Last) | |
} | |
$Response = Invoke-RestMethod ` | |
-Method POST ` | |
-Uri "$RootUrl/query" ` | |
-Headers @{ | |
"X-API-Key" = $ProjectKey | |
"Content-Type" = "application/json" | |
} ` | |
-Body $($Payload | ConvertTo-Json) | |
foreach ($Item in $Response.Items) | |
{ | |
$Items.Add($Item.Key, $Item) | |
} | |
if (!$Response.paging.last) { | |
break | |
} | |
else { | |
$Last = $Response.paging.last | |
} | |
} | |
Write-Output $(ConvertTo-Json $Items) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment