Can PowerShell play a NoSQL database? The answer is yes. As long as this database is compatible with. NET, it can be easily used by PowerShell.
The original intention: there is little talk about PowerShell calling NoSQL posts in the world, not to mention PowerShell calls Litedb. Only a handful of PowerShell calls Monodb code.
The first draft will be updated. There is a mistake to welcome correct, thank you.
Powershell,nosql,litedb,bson, database, PowerShell missionary
---"Storage format"---
Bson is a binary form of JSON-like storage format, referred to as binary JSON. Like JSON, it supports inline document objects and array objects, but Bson has some data types that JSON does not have, such as date and bindata types.
{"Hello": "World"} This is an example of a bson, where "Hello" is the key name, it is generally a string type, the following "World" is the key value, and its type is generally string,double,array,binarydata type.
The largest unit of Bson storage Records is document, which can be understood as a record.
According to the instructions in the Litedb manual, the limit is: Each database is less than 2GB, each document is less than 1MB;
Litedb---"Table---" bson_document---"bson_document---" key value pair
---"Application scenario, important! 】---
For personal finishing of the application, if there is a problem, please treatise.
1 single-machine, green, small and medium-size data. The total content of a single library is less than 1.8GB.
2 is similar to SQLite, but SQLite is a SQL database, this is NoSQL. A key-value pair, that is, there is only one column of data in each library. That is, NoSQL databases are not suitable for storing row and column data. But arrays, hash tables, and object conversions between objects are easier than SQL database. Querying data does not use SQL syntax with functions.
---"Cons"---
There are no tools for the graphical management database at the moment.
---"Download Install"---
1 Official website: http://www.litedb.org/
2 GitHub address is: https://github.com/mbdavid/LiteDB/
3 I compiled the binary package.
Http://files.cnblogs.com/files/piapia/powershell_litedb.zip
Contains litedb DLL files, litedb command line, and CHM version of the manual, PowerShell script example.
The CHM version of the Handbook is "dotnet Open source stronghold" http://home.cnblogs.com/u/asxinyu/do, thank him.
Litedb command-line manual. txt is the one I exported from the command line help.
---The Common objects list---
Litedb.litedatabase
Litedb.bsondocument
Litedb.bsonmapper Bson Key-value pairs <---> Object Translator class
Litedb.jsonserializer Bson Key-value pair <--->json key-value pair conversion class.
Litedb.bsonarray Bson Array
Litedb.bsonvalue Bson Value Boolean, date, Guid,object object, Bson value, byte array, int32,int64,double, String, list, dictionary, etc.
Litedb.litefilestorage Storing files
Litedb.query Query class
---the list of commonly used functions---
Excerpted from http://www.cnblogs.com/asxinyu/p/dotnet_Opensource_project_LiteDB.html
------Query-----Query.all Returns all data and can be sorted using the specified index field
QUERY.EQ Lookup returns data that is equal to the specified field value
Query.lt/lte finding data for a value < or <=
Query.gt/gte finding data for a value > or >=
Query.between finding data within a specified range
Query.in-Similar to SQL in, find data with equal values in the list
Query.not-In contrast to EQ, data that is not equal to a value
Query.startswith finding data that begins with a string
Query.contains finds data that includes a string that only scans the index
Query.and intersection of 2 queries
Query.or 2 Results of a query
------LINQ-----
FindAll: Find all results records in a table or collection
FindOne: Returns the first or default result
FindByID: Returns a single result by index
Find: Return results using a query expression or a LINQ expression query
Count (), Exists (), Min (), Max ()
---"example, important! 】---
In simple terms, we construct key-value pairs with strings, dates, and so on. Use n key values to make up bson_document, and then change the bson_document.
The following script win8.1 + PowerShell 4.0 + litedb 1.02 test passes.
#
#
# powershell_for_litedb v1.0.2 2015-08-30
$ script: script storage path = Split-Path -Parent $ myinvocation.mycommand.path
$ Env: Path + = "; $ script: Script storage path;"
$ script: database client directory = ‘a: \ pscode \ litedb \’
$ script: database client file name = `` LiteDB.dll ''
$ script: database client absolute file name = $ script: database client directory + $ script: database client file name
$ script: database file name = ‘test001.db’
$ script: database absolute file name = $ script: database client directory + $ script: database file name
if (test-path $ script: database client absolute file name)
{
[system.reflection.Assembly] :: LoadFrom ($ script: database client absolute file name) | Out-Null
write-host "--- LiteDB program loading is complete ---"
}
else
{
exit
}
# Open the database, if not, create a new database
$ Database001 = New-Object LiteDB.LiteDatabase ($ script: database absolute file name)
# $ Database001.GetDatabaseInfo ()
[string] $ Query table name = $ database001.GetCollectionNames ()
if ($ query table name -eq "")
{
write-host "empty database, no tables"
}
#Open the table, if not, create a new table
$ 表 001 = $ database001.GetCollection ("aaaa")
# $ Query result = $ 表 001.findall ()
# $ Query results
# --------------- Insert -----------------
$ String = ‘aa’
$ Number = 123
$ Date = get-date
$ Truefalse = $ true
$ Array = "a", "1", "kkk"
$ Hashtable 2 = @ {
name = $ string;
age = $ number;
bron = $ date;
sex = $ true or false;
array = $ array;
Hee hee = ‘haha’
}
$ json_hash table 2 = ConvertTo-Json -InputObject $ hash table 2
$ bson_hash table 2 = [LiteDB.JsonSerializer] :: Deserialize ($ json_hash table 2)
$ bson_hash table 2
# ‘--- bend ---’
# $ bson_hashtable.gettype ()
$ Table 001.Insert ($ bson_hash table 2)
# ------------- Insert key-value pairs -------------
[LiteDB.BsonValue] $ 值 2 = ‘powershell missionary original article 2015-08-30, reprint allowed, but the name and source must be retained, otherwise the legal missionary will be investigated. First draft, please correct me if there are errors, thank you. ‘
$ Key 2 = ‘statement’
$ bson_Document = New-Object LiteDB.BsonDocument
$ bson_Document.add ($ key2, $ value2)
# Eliminate the output with $ null = $ bson_Document.add ($ key2, $ value2)
$ 表 001.Insert ($ bson_Document)
#------------------Inquire--------------------
#Query must enter the key name, key value as a parameter.
#All returned are bson_Document, converted to json, and then converted to a hash table object. Then take the value.
$ Query result 1 = $ 表 001.find ([LiteDB.query] :: eq ("name", "aa"))
"---1---"
$ Query result 1
$ Query result 2 = $ 表 001.find ([LiteDB.query] :: gt ("age", "124"))
"---2---"
$ Query result 2
$ Query result 3 = $ 表 001.find ([LiteDB.query] :: StartsWith ("Hip hee", "Ha"))
"--- 3 ---"
$ Query result 3
PowerShell Play Litedb Database