generated from lucien/api-template
Created two API endpoints.
This commit is contained in:
parent
00e78c2dff
commit
8a61aaa68f
8 changed files with 854 additions and 203 deletions
47
libs/mysql.js
Normal file
47
libs/mysql.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
const mysql = require("mysql");
|
||||
|
||||
function getConnection() {
|
||||
return mysql.createConnection({
|
||||
host: process.env.MYSQL_HOST,
|
||||
user: process.env.MYSQL_USER,
|
||||
password: process.env.MYSQL_PASSWORD,
|
||||
database: process.env.MYSQL_DB,
|
||||
});
|
||||
}
|
||||
|
||||
function getShares(connection) {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query(
|
||||
`SELECT * FROM Share`,
|
||||
(error, result) => {
|
||||
if (error) {
|
||||
throw(new Error(error));
|
||||
}
|
||||
resolve(result);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function getShareholders(connection) {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query(
|
||||
`SELECT * FROM Shareholder`,
|
||||
(error, result) => {
|
||||
if (error) {
|
||||
throw(new Error(error));
|
||||
}
|
||||
resolve(result);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getConnection,
|
||||
|
||||
getShares,
|
||||
|
||||
getShareholders,
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue