promise learn

This commit is contained in:
2021-01-13 12:07:33 +01:00
parent c6e338502e
commit 13c72409c5
6 changed files with 282 additions and 0 deletions

View File

@ -0,0 +1,31 @@
const mariadb = require('mariadb')
let conn : mariadb.Connection
mariadb.createConnection({
host: 'database',
user: 'heroes',
password: 'test123',
database: 'heroes'
})
.then(conn => {
conn.query("SELECT * FROM hero")
.then((rows) => {
console.log(rows)
return rows
})
.then((res) => {
console.log(res)
conn.end()
})
.catch(err => {
console.log(err)
conn.end()
})
})
.catch(err => {
console.log('not connected')
})