0.1.0 • Published 3 years ago

vv-mssql v0.1.0

Weekly downloads
35
License
MIT
Repository
github
Last release
3 years ago

for Node: exec query on Microsoft SQL Server; based on http://tediousjs.github.io/tedious/

Install

npm i vv-mssql

Use

let connection = require('vv-mssql').create({
    instance: 'myserver\\myinstance',
    login: 'sa',
    password: 'my very protected password',
    additional: {
        app_name: 'my best app',
        database: 'tempdb',
        use_utc: true,
        //connection_timeout: 0
        //and timeout, encrypt
    }
})

connection.ping(error => {
    if (error) {
        console.error(error)
        return
    }
    console.log('Server info', connection.server_info())

    //example 1 - simple 1 query
    connection.exec("select top 10 * from sys.objects", undefined, callback_exec => {
        if (callback_exec.type !== 'end') return

        console.log('script', callback_exec.end.get_beauty_query('actual'))

        if (callback_exec.end.error) {
            console.error(callback_exec.end.error_type, callback_exec.end.error)
            return
        }
        console.log('result', callback_exec.end.table_list)
    })

    //example 2 - 2 queries in one connect
    connection.exec(["select top 5 * from sys.objects", "select top 5 * from sys.columns"], undefined, callback_exec => {
        if (callback_exec.type !== 'end') return

        console.log('script', callback_exec.end.get_beauty_query('actual'))

        if (callback_exec.end.error) {
            console.error(callback_exec.end.error_type, callback_exec.end.error)
            return
        }

        console.log('total duration (script time + all handlers time)', callback_exec.end.duration)
        console.log('current database at the time the script was running (if use in script instrunction "use database")', callback_exec.end.database)
        callback_exec.end.table_list.forEach(table => {
            console.log('==============TABLE #'.concat(table.table_index.toString(), ', QUERY #', table.query_index.toString()))
            console.log('SCHEMA:')
            table.column_list.forEach(column => {
                console.log('    '.concat(column.name, ' ', column.declararion))
            })
            console.log('rows', table.row_list)
        })
    })

    //example 3 - a) get spid, b) exec script in other database
    connection.exec("select * from sys.objects", {get_spid: true, database: 'master'}, callback_exec => {
        if (callback_exec.type === 'spid') {
            console.log('spid', callback_exec.spid)
        }
        if (callback_exec.type === 'end') {
            if (callback_exec.end.error) {
                console.error(callback_exec.end.error_type, callback_exec.end.error)
            }
            console.log('script database', callback_exec.end.database)
        }
    })

    //example 4 - chunked result
    connection.exec("select * from sys.objects", {chunk: {type: 'row', chunk: 50 }}, callback_exec => {
        if (callback_exec.type === 'chunk') {
            // see callback_exec.chunk
        }
        if (callback_exec.type === 'end') {
            if (callback_exec.end.error) {
                console.error(callback_exec.end.error_type, callback_exec.end.error)
            }
        }
    })

    //example 5 - columns buetify - two column without name and two column with same name
    connection.exec("select 'aaa', 'bbb', 'ccc' as f1, 'ddd' as f1, * from sys.objects", undefined, callback_exec => {
        if (callback_exec.type === 'end') {
            // see callback_exec.end for more info
            if (callback_exec.end.error) {
                console.error(callback_exec.end.error_type, callback_exec.end.error)
            }
        }
    })
})

Classes

Typedefs

App

Kind: global class

new App(options)

ParamType
optionstype.constructor_options

app.ping(callback)

check connect to MS SQL, load MS SQL server info

Kind: instance method of App

ParamType
callbackcallback_ping

app.server_info() ⇒ type.connection_server_info

return MS SQL info (non empty after exec ping())

Kind: instance method of App

app.exec(query, options, callback)

exec one query or many queries in one batch

Kind: instance method of App

ParamType
querystring | Array.<string>
optionstype.exec_option
callbackcallback_exec

app.newid(count, callback)

get ms sql generated guid's

Kind: instance method of App

ParamTypeDescription
countnumbercount guid
callbackcallback_newid

callback_ping : function

Kind: global typedef

ParamType
errorError

callback_exec : function

Kind: global typedef

ParamType
callbacktype.exec_result

callback_newid : function

Kind: global typedef

ParamType
errorError
guid_listArray.<string>
0.1.0

3 years ago

0.0.44

3 years ago

0.0.41

3 years ago

0.0.42

3 years ago

0.0.39

3 years ago

0.0.37

3 years ago

0.0.36

3 years ago

0.0.35

3 years ago

0.0.33

3 years ago

0.0.34

3 years ago

0.0.31

3 years ago

0.0.30

3 years ago

0.0.29

3 years ago

0.0.28

4 years ago

0.0.27

4 years ago

0.0.26

4 years ago

0.0.25

4 years ago

0.0.24

4 years ago

0.0.23

4 years ago

0.0.20

4 years ago

0.0.21

4 years ago

0.0.22

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.17

4 years ago

0.0.16

4 years ago

0.0.14

4 years ago

0.0.15

4 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago