Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nightroman/ldbc
LiteDB Cmdlets, the document store in PowerShell
https://github.com/nightroman/ldbc
litedb powershell
Last synced: 7 days ago
JSON representation
LiteDB Cmdlets, the document store in PowerShell
- Host: GitHub
- URL: https://github.com/nightroman/ldbc
- Owner: nightroman
- License: apache-2.0
- Created: 2020-02-05T20:23:53.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-07-06T03:53:19.000Z (4 months ago)
- Last Synced: 2024-07-06T05:20:46.526Z (4 months ago)
- Topics: litedb, powershell
- Language: PowerShell
- Homepage:
- Size: 233 KB
- Stars: 39
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Ldbc
LiteDB Cmdlets, the document store in PowerShell
***
Ldbc is the PowerShell module with [LiteDB](https://www.litedb.org),
a small, fast, zero configuration NoSQL embedded database.- Ldbc works with Windows PowerShell and PowerShell Core.
- LiteDB is included and ready to use without installing anything.Some LiteDB features:
- Single datafile
- ACID transactions
- Store files and stream data
- Cross collections references
- Recovery after writing failures
- Mapping classes to documentsLdbc makes LiteDB operations and data PowerShell friendly. You can store and
retrieve hashtables and dictionaries, PowerShell classes and custom objects,
.NET complex types. Operate on data using specialized cmdlets or LiteDB SQL.## Quick start
**Step 1:** Get and install
Ldbc is published as the [PSGallery module](https://www.powershellgallery.com/packages/Ldbc).
You can install the module by this command:
```powershell
Install-Module Ldbc
```**Step 2:** In a PowerShell command prompt import the module:
```powershell
Import-Module Ldbc
```**Step 3:** Take a look at help and available commands:
```powershell
help about_Ldbc
Get-Command -Module Ldbc
help Use-LiteDatabase -Full
```**Step 4:** Try add, get, remove operations with a memory database
(a) using `Add-LiteData`, `Get-LiteData`, `Remove-LiteData`:
```powershell
Use-LiteDatabase :memory: {
# get the collection, specify auto id
$test = Get-LiteCollection Test Int32# add two documents
@{Name = 'John'}, @{Name = 'Mary'} | Add-LiteData $test# find using filter with an argument
$r = Get-LiteData $test -Where 'Name = @0', John
"$r" # {"_id":1,"Name":"John"}# remove one by _id
Remove-LiteData $test -ById 1# get all documents
$r = Get-LiteData $test
"$r" # {"_id":2,"Name":"Mary"}
}
```(b) ditto using just `Invoke-LiteCommand` and LiteDB SQL:
```powershell
Use-LiteDatabase :memory: {
# add two documents
Invoke-LiteCommand 'INSERT INTO Test : INT VALUES {Name: "John"}, {Name: "Mary"}' -Quiet# find using WHERE with parameters
$r = Invoke-LiteCommand 'SELECT $ FROM Test WHERE Name = @param1' @{param1 = 'John'}
"$r" # {"_id":1,"Name":"John"}# remove using WHERE with parameters
Invoke-LiteCommand 'DELETE Test WHERE _id = @_id' @{_id = 1} -Quiet# get all documents
$r = Invoke-LiteCommand 'SELECT $ FROM Test'
"$r" # {"_id":2,"Name":"Mary"}
}
```(c) store and retrieve PowerShell custom objects
```powershell
Use-LiteDatabase :memory: {
# get the collection
$test = Get-LiteCollection Test# get PS objects, select some properties, insert
Get-ChildItem | Select-Object Name, Mode, Length | Add-LiteData $test# get back PS custom objects
Get-LiteData $test -As PS
}
```**Next steps**
Read cmdlets help with basic examples. Take a look at tests in the repository
for more technical examples.Read LiteDB [docs](https://www.litedb.org/docs/).
Some API may be needed and used directly in addition to provided by the module.## LiteDB methods and module commands
| LiteDB | Module | Output
| :----- | :----- | :-----
| **Database** | |
| LiteDatabase | New-LiteDatabase | database (needs Dispose)
| LiteDatabase | Use-LiteDatabase {..} | $Database (auto Dispose)
| GetCollection | Get-LiteCollection | collection instance
| Execute | Invoke-LiteCommand | values, documents
| BeginTrans | Use-LiteTransaction {..} | ..
| + Commit | (success) |
| + Rollback | (failure) |
| **Collection** | |
| Count | Get-LiteData -Count | count
| Exists | Test-LiteData | true or false
| Find* | Get-LiteData | documents
| Insert | Add-LiteData | none, ids
| Update | Set-LiteData | none, count
| Upsert | Set-LiteData -Add | none, count
| UpdateMany | Update-LiteData | none, count
| DeleteMany | Remove-LiteData | none, count
| **Misc** | |
| RegisterType | Register-LiteType | none## Work in progress
Work on module commands and features is in progress, they may change before v1.0.0
## See also
- [Ldbc Release Notes](https://github.com/nightroman/Ldbc/blob/main/Release-Notes.md)
- [about_Ldbc.help.txt](https://github.com/nightroman/Ldbc/blob/main/Module/en-US/about_Ldbc.help.txt)
- [Mdbc, similar project for MongoDB](https://github.com/nightroman/Mdbc)