Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #In this region, I'm getting my database stuff set up
- #Region DbSetup
- Push-Location -path "$env:Userprofile\Projects\Vrishni\Database\LiteDB"
- if (-not (test-path ".\mydb.db")){
- new-item -Path "." -Name "mydb.db"
- }
- $mydb = New-Object LiteDB.LiteDatabase(".\mydb.db")
- #endregion
- #In this region, adding litedb and creating a class
- #region Type Setup
- add-type -Path ".\Lib\LiteDB.dll"
- class Customer {
- [string]$_id
- [string]$name
- [int]$age
- [int]$weight
- }
- #endregion
- #Getting a list set up, and adding customers to it
- #region List Setup
- $customerList = [System.Collections.Generic.List[Customer]]::new()
- [Customer]$Customer1 = @{'_id' = [LiteDB.ObjectId]::NewObjectId(); 'Name' = 'Ronald'; 'age'= 19; 'weight' = 300 }
- [Customer]$Customer2 = @{'_id' = [LiteDB.ObjectId]::NewObjectId(); 'Name' = 'David'; 'age'= 25; 'weight' = 270 }
- $customerList.Add($Customer1)
- $customerList.Add($Customer2)
- #endregion
- #region Database stuff
- $mapper = [LiteDB.BsonMapper]::new()
- $customers = $mydb.GetCollection("customers")
- $customerList | ForEach-Object {
- $customers.Insert($mapper.ToDocument($_))
- }
- $mydb.GetCollection("customer").FindAll()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement