Tuesday, November 17, 2015

Underscore.js : JavaScript Library

Underscore.js


Introduction

Underscore is a JavaScript library which provides a whole useful library of helper functions without requiring extension of any built-in objects. Underscore provides well over 100 functions that support the common needs of a programmer in his/her daily programming life. This is a must have for all the web programmers who deal with JavaScript. 

Key helper functions

  • Collections (Helper functions for lists/collection objects)
    • each
    • map
    • reduce
    • reduceRight
    • find
    • filter
    • where
    • findWhere
    • reject
    • every
    • some
    • contains
    • invoke
    • pluck
    • max
    • min
    • sortBy
    • groupBy
    • indexBy
    • countBy
    • shuffle
    • sample
    • toArray
    • size
    • partition
  • Arrays (Helper functions for arrays)
    • first
    • initial
    • last
    • rest
    • compact
    • flatten
    • without
    • union
    • intersection
    • difference
    • uniq
    • zip
    • unzip
    • object
    • indexOf
    • lastIndexOf
    • sortedIndex
    • findIndex
    • findLastIndex
    • range
  • Functions (General helper functions)
    • bind
    • bindAll
    • partial
    • memoize
    • delay
    • defer
    • throttle
    • debounce
    • once
    • after
    • before
    • wrap
    • negate
    • compose
  • Objects (Helper functions that can be applied to objects)
    • keys
    • allKeys
    • values
    • mapObject
    • pairs
    • invert
    • create
    • functions
    • findKey
    • extend
    • extendOwn
    • pick
    • omit
    • defaults
    • clone
    • tap
    • has
    • matcher
    • property
    • propertyOf
    • isEqual
    • isMatch
    • isEmpty
    • isElement
    • isArray
    • isObject
    • isArguments
    • isFunction
    • isString
    • isNumber
    • isFinite
    • isBoolean
    • isDate
    • isRegExp
    • isNaN
    • isNull
    • isUndefined
  • Utility
    • noConflict
    • identity
    • constant
    • noop
    • times
    • random
    • mixin
    • iteratee
    • uniqueId
    • escape
    • unescape
    • result
    • now
    • template
  • Chaining
    • chain
    • value

Conclusion


By using Underscore.js, a web developer could save a lot of time. Using these helper functions in the team or in the company enhances code re-usability and code readability. To get to know more about each helper functions in detail, go to http://underscorejs.org/ 





Wednesday, November 4, 2015

Should I use user schema seperation in SQL Server

User Schema

Introduction

Prior to SQL Server 2005, a database object  is owned by a user. That user could be DBO or any valid user account. That table is now directly linked to that user– the user cannot be deleted without removing the table or changing the owner of the table. The table can only ever be owned by one user. User-schema separation, introduced in SQL Server 2005, means that the table is no longer owned by any user; it belongs to a schema. In turn, the schema is owned by a user.

A schema is separate entity within the database. It is created by using the CREATE SCHEMA statement. A schema can be owned by a user, a role, or a group. A user executing CREATE SCHEMA can be the owner of the schema or it can allocate another user as the schema owner with appropriate IMPERSONATE permissions. A schema only has one owner, but a user can own many schema. Schema ownership is transferable.

Pros

  1. Schema allows much more control of access, and levels of access for the administrator
  2. Ownership of schema and the database objects within them is transferable
  3. Objects can be moved between schema
  4. Multiple database users can share a single schema
  5. A database user can be dropped without dropping objects in a corresponding schema
  6. Schema logically separates objects in a database. 
Cons
  1. If not used wisely, (considering dependencies and commonality of objects), user schema can be quiet confusing.
  2. Schema organization must be considered during the design phase to avoid problems with the code. Changing schema design late in the fame could cause many changes in the code.
  3. For Programmers who use C# code, although, in most of the cases, user schema works like Namespaces in C#, note that the notations like HR.People schema will be converted to HR_People class in C#.


Thursday, January 1, 2015

Dapper and Passing Table Value Parameter(TVP)

Dapper and TVP (Table Value Parameter)


  • Introduction
In one sentence, dapper is a Micro ORM. I find it very helpful if my application uses stored procedures  to connect to the database and do various operations than  using Entity Framework for the database operations. The beauty is, they could coexist in the same application and Dapper can facilitate database operations for stored procedures and raw SQL while Entity Framework can do database operations through POCO or Models. So they together satisfy all your needs in terms of database operations from your applications. Dapper has a bunch of extension classes which extends the .NET database facilitation classes.

Dapper is very simple and in fact, it has only two methods related to database activity. Execute and Query. As the name says, do execute when you need to do some modifications in the database and do the Query when you want to fetch some records from the database. When you fetch using the Query method, you could specify which type of object you are expecting by adding the type in the Generic <T> place holder. 

  • TVP (Table Value Parameter)
We might need to pass a table value parameter in some cases to the stored procedure using dapper. One of the typical situation is when you want to have a list of objects persisted in database through stored procedure. To pass the TVP through dapper to a stored procedure, you need to install an extension for dapper which is called Dapper.TVP. You could easily download and install that using your Nuget package manager. Once you install it, implement the code like the sample code I have given below.

using Dapper;
using Dapper.tvp;

conn.Execute("<Procedure Name>", new {TVP = datatable.AsTableValuedParameter("<SQL Type>")}, commandType: CommandType.StoredProcedure);