Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #In this region, I'm getting my database stuff set up
  2. #Region DbSetup
  3.  
  4. Push-Location -path "$env:Userprofile\Projects\Vrishni\Database\LiteDB"
  5.  
  6. if (-not (test-path ".\mydb.db")){
  7.     new-item -Path "." -Name "mydb.db"
  8. }
  9.  
  10. $mydb = New-Object LiteDB.LiteDatabase(".\mydb.db")
  11.  
  12. #endregion
  13.  
  14.  
  15. #In this region, adding litedb and creating a class
  16. #region Type Setup
  17.  
  18. add-type -Path ".\Lib\LiteDB.dll"
  19.  
  20. class Customer {
  21.     [string]$_id
  22.     [string]$name
  23.     [int]$age
  24.     [int]$weight
  25. }
  26.  
  27. #endregion
  28.  
  29.  
  30. #Getting a list set up, and adding customers to it
  31. #region List Setup
  32.  
  33. $customerList = [System.Collections.Generic.List[Customer]]::new()
  34.  
  35. [Customer]$Customer1 = @{'_id' = [LiteDB.ObjectId]::NewObjectId(); 'Name' = 'Ronald'; 'age'= 19; 'weight' = 300 }
  36. [Customer]$Customer2 = @{'_id' = [LiteDB.ObjectId]::NewObjectId(); 'Name' = 'David'; 'age'= 25; 'weight' = 270 }
  37.  
  38. $customerList.Add($Customer1)
  39. $customerList.Add($Customer2)
  40.  
  41. #endregion
  42.  
  43. #region Database stuff
  44.  
  45. $mapper = [LiteDB.BsonMapper]::new()
  46.  
  47. $customers = $mydb.GetCollection("customers")
  48.  
  49. $customerList | ForEach-Object {
  50.     $customers.Insert($mapper.ToDocument($_))
  51. }
  52.  
  53. $mydb.GetCollection("customer").FindAll()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement