Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
58 lines (53 sloc) 1.32 KB
//
// Promise-mysql:
// https://github.com/CodeFoodPixels/node-promise-mysql
//
import * as mysql from 'promise-mysql';
/********************************
*
*********************************/
function get_table(): void{
let connection :mysql.Connection;
mysql.createConnection({
host: "localhost",
user: "db_user",
password: "password",
database: "vue1"
})
.then((conn) => {
connection = conn;
return connection.query('SELECT * FROM books');
}).then((results: any[]) => {
// console.log(results );
results.forEach(result => {
console.log(result);
});
connection.end();
});
}
/********************************
*
*********************************/
function add_table(title: string): void{
let sql = `
INSERT INTO books (title ,createdAt ) VALUES
('${ title }', now() )
`;
let connection :mysql.Connection;
mysql.createConnection({
host: "localhost",
user: "db_user",
password: "password",
database: "vue1"
})
.then((conn) => {
connection = conn;
connection.query( sql )
connection.end();
});
}
/********************************
* main
*********************************/
let items = get_table();
//let items = add_table("t16");
You can’t perform that action at this time.