Automate Couchbase Integration Tasks from PowerShell
The CData ADO.NET Provider for Couchbase is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Couchbase.
ADO.NET Provider
The ADO.NET Provider provides a SQL interface for Couchbase; this tutorial shows how to use the Provider to create, retrieve, update, and delete Couchbase data.
Once you have acquired the necessary connection properties, accessing Couchbase data in PowerShell can be enabled in three steps.
To connect using the Login method, set User, Password, and Server to the credentials for the account and the address of the server you want to connect to.
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Couchbase\lib\System.Data.CData.Couchbase.dll") -
Connect to Couchbase:
$conn= New-Object System.Data.CData.Couchbase.CouchbaseConnection("User=myuseraccount;Password=mypassword;Server=http://mycouchbaseserver;") $conn.Open() -
Instantiate the CouchbaseDataAdapter, execute an SQL query, and output the results:
$sql="SELECT FirstName, TotalDue from Customer" $da= New-Object System.Data.CData.Couchbase.CouchbaseDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.firstname $_.totaldue }
Update Couchbase Data
$cmd = New-Object System.Data.CData.Couchbase.CouchbaseCommand("UPDATE Customer SET FirstName='Bob' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Couchbase.CouchbaseParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Insert Couchbase Data
$cmd = New-Object System.Data.CData.Couchbase.CouchbaseCommand("INSERT INTO Customer (FirstName) VALUES (@myFirstName)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Couchbase.CouchbaseParameter("@myFirstName","Bob")))
$cmd.ExecuteNonQuery()
Delete Couchbase Data
$cmd = New-Object System.Data.CData.Couchbase.CouchbaseCommand("DELETE FROM Customer WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Couchbase.CouchbaseParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject