Skip to content

Commit

Permalink
Merge pull request #156 from rossipedia/default-isolation-level
Browse files Browse the repository at this point in the history
Add option to set the default isolation level for the connection
  • Loading branch information
patriksimek committed Jun 24, 2014
2 parents a7794da + 02efee4 commit 48237e5
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/connection.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class Connection extends EventEmitter
@config.options.cryptoCredentialsDetails ||= {}
@config.options.useUTC ?= true
@config.options.useColumnNames ?= false
@config.options.connectionIsolationLevel ||= ISOLATION_LEVEL.READ_COMMITTED

if !@config.options.port && !@config.options.instanceName
@config.options.port = DEFAULT_PORT
Expand Down Expand Up @@ -526,7 +527,7 @@ class Connection extends EventEmitter
@messageIo.sendMessage(TYPE.SQL_BATCH, payload.data)

getInitialSql: ->
'set textsize ' + @config.options.textsize + '''
"""set textsize #{@config.options.textsize}
set quoted_identifier on
set arithabort off
set numeric_roundabort off
Expand All @@ -539,7 +540,7 @@ set implicit_transactions off
set language us_english
set dateformat mdy
set datefirst 7
set transaction isolation level read committed'''
set transaction isolation level #{@getIsolationLevelText @config.options.connectionIsolationLevel}"""

processedInitialSql: ->
@clearConnectTimer()
Expand Down Expand Up @@ -656,4 +657,13 @@ set transaction isolation level read committed'''
currentTransactionDescriptor: ->
@transactionDescriptors[@transactionDescriptors.length - 1]

getIsolationLevelText: (isolationLevel) ->
switch isolationLevel
when ISOLATION_LEVEL.READ_UNCOMMITTED then 'read uncommitted'
when ISOLATION_LEVEL.REPEATABLE_READ then 'repeatable read'
when ISOLATION_LEVEL.SERIALIZABLE then 'serializable'
when ISOLATION_LEVEL.SNAPSHOT then 'snapshot'
else 'read committed'


module.exports = Connection

0 comments on commit 48237e5

Please sign in to comment.