Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Fs from 'fs'
- import Path from 'path'
- import Mime from 'mime'
- import { Connection } from 'tedious'
- import { Request } from 'tedious'
- const TYPES = require('tedious').TYPES
- module.exports = async (ctx, next) => {
- var config = {
- userName: process.env.DB_USER,
- password: process.env.DB_PASS,
- server: process.env.DB_HOST,
- options: {
- database: process.env.DB_BASE ,
- rowCollectionOnRequestCompletion: true
- }
- }
- const connection = new Connection(config)
- let rowdata = {}
- let rowarray = []
- connection.on('connect', (err) => {
- if (err) {
- console.log(`error : ${err}`)
- } else {
- let sql = `select a.nome as name, CONVERT(varchar(7),r.date, 126) as date
- from blah a left join blah r
- on a.blah = r.blah
- where a.blah = @blah `
- let request = new Request(sql, function(err, rowCount) {
- if (err) {
- console.log(err);
- } else {
- ctx.statusCode = 200
- ctx.body = JSON.stringify(rowdata)
- console.log(rowdata.name)
- }
- })
- request.addParameter('blah ', TYPES.Int, ctx.params.id)
- request.on('row', function(columns) {
- columns.forEach(function(column) {
- rowdata[column.metadata.colName] = column.value
- console.log(column.value)
- console.log(column.metadata.colName)
- })
- rowarray.push(rowdata)
- })
- connection.execSql(request);
- }
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement