Sunday, June 21, 2015

Ruby script to use Azure Blob Storage

Azure Blob storage is a service for storing large amounts of unstructured data, such as text or binary data, that can be accessed from anywhere in the world via HTTP or HTTPS. You can use Blob storage to expose data publicly to the world, or to store application data privately.

This post will show you how to perform common scenarios using the Azure Blob service. The samples are written using the Ruby API. The scenarios covered include uploading, listing, downloading, and deleting blobs.

You can download final ruby script from here.

This post assumes you have already created a storage account and a container.

  • Type "gem install azure" in the command window to install the gem and dependencies.
  • Import installed package in to the script file.
  • Setup global parameters.
  • Uploading a Blob into a Container
  • List the Blobs in a Container
  • Download Blobs
  • Delete a Blob

Writing Dynamic SQL in MyBatis

This post will take you through a several examples of creating a dynamic sql queries which you will come up in a day to day development using mybatis.
  • Use of if statement
We can use the if statement where we need to conditionally include parts of a where clause.
eg: Search Employee. Employee name and role can be added as filter fields.
  • Use of choose, when, otherwise
What about switch statement in query where we need to choose only one case among many options.
  • Use of where
When you have a query with multiple optional where clauses you may find a difficulty to build the query with correct prefix. MyBatis has a simple solution for this. It is where element. The where element knows to only insert "WHERE" if there is any content returned by the containing tags. Furthermore, if that content begins with "AND" or "OR", it knows to strip it off.
  • Use of set
The set element can be used to dynamically include columns to update, and leave out others.
  • Use of foreach
Another common necessity for dynamic SQL is the need to iterate over a collection, often to build an IN condition.