Skip to content

Instantly share code, notes, and snippets.

@Cologler
Created July 4, 2022 17:18
Show Gist options
  • Save Cologler/1ece85b265951432484db48eac67b181 to your computer and use it in GitHub Desktop.
Save Cologler/1ece85b265951432484db48eac67b181 to your computer and use it in GitHub Desktop.
export database as json from deta.sh to stdout
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