Last active
April 12, 2018 08:25
-
-
Save uriee/39026305a0d6d9cd8425be79f81703bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var config = { | |
user: '', | |
password: '', | |
server: '', | |
database: '', | |
pool: { | |
max: 15, | |
min: 0, | |
idleTimeoutMillis: 30000 | |
} | |
} | |
const simpleQuery = async function(query,intval1 = 0 ,charval1 = '') { | |
const pool = new sql.ConnectionPool(config); | |
pool.on('error', err => { | |
console.log('sql errors', err); | |
}); | |
try { | |
await pool.connect(); | |
let result = await pool.request() | |
.input('intval1', sql.Int, intval1) | |
.input('charval1', sql.Char, charval1) | |
.query(query) | |
console.log(query,result.recordset ) | |
return result.recordset | |
} catch (err) { | |
return {err: err}; | |
} finally { | |
pool.close(); | |
} | |
}; | |
router.route('/inter/pl/:part') | |
.get(async function(req, res) { | |
const Q = `SELECT PLNAME,PRICE | |
FROM PRICELIST,PARTPRICE | |
WHERE PART = @intval1 | |
PRICELIST.PLIST = PARTPRICE.PLIST | |
AND PRICELISTDATE.PLIST = PRICELIST.PLIST | |
AND PARTPRICE.PLDATE = PRICELISTDATE.PLDATE` | |
return res.json(await simpleQuery(Q,req.params.part)) | |
}); | |
router.route('/inter/search/:desc') | |
.get(async function(req, res) { | |
const Q = `select PART.PARTNAME , PART.PARTDES | |
from PART | |
where PART.PARTDES like concat('%',@charval1,'%') | |
and PART.TYPE = 'P'` | |
return res.json(await simpleQuery(Q,0,req.params.desc)) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment