Scripts/Open-LitePanel.ps1

<#
.Synopsis
    Shows LiteDB collections and documents.
 
.Description
    This command opens a panel with LiteDB database collections or documents.
    Root documents may be viewed and edited as JSON if they have the _id key.
    Nested documents are not edited directly.
 
    Paging. Large collections is not a problem. Documents are shown 1000/page.
    Press [PgDn]/[PgUp] at last/first panel items to show next/previous pages.
    Paging is not used with queries, they may use LIMIT and OFFSET themselves.
 
    KEYS AND ACTIONS
 
    [Del]
        Deletes selected documents and empty collections.
        For deleting not empty collections use [ShiftDel].
 
    [ShiftDel]
        Deletes selected collections and documents.
 
    [ShiftF6]
        Prompts for a new name and renames the current collection.
 
    [F4]
        Edits the current document JSON and updates the document.
 
    [F7]
        Opens the editor for the new document JSON.
 
.Parameter ConnectionString
        Specifies the LiteDB connection string. If Query is omitted then the
        panel shows database collections. Use System in order to include the
        system collections.
 
.Parameter Query
        Specifies either the collection name or SQL SELECT command and tells to
        show collection or queried documents. Note that SELECT should use _id
        or $ in order to modify or delete result documents in the panel.
 
.Parameter System
        Tells to include and show system collections.
 
.Example
    ># Browse collections
    Open-LitePanel Test.LiteDB -System
 
.Example
    ># Browse Log documents
    Open-LitePanel Test.LiteDB Log
 
.Example
    ># Browse some documents from Log
    Open-LitePanel Test.LiteDB 'SELECT $ FROM Log WHERE ...'
 
.Link
    https://www.litedb.org/api/query/
#>


function Open-LitePanel {
    [CmdletBinding(DefaultParameterSetName='Database')]
    param(
        [Parameter(Position=0, Mandatory=1)]
        [string]$ConnectionString
        ,
        [Parameter(ParameterSetName='Query', Position=1, Mandatory=1)]
        [string]$Query
        ,
        [Parameter(ParameterSetName='Database')]
        [switch]$System
    )

    trap {Write-Error -ErrorRecord $_}

    if ($Query) {
        (New-FLDocumentsExplorer $ConnectionString $Query).OpenPanel()
    }
    else {
        (New-FLCollectionsExplorer $ConnectionString -System:$System).OpenPanel()
    }
}