promise learn
This commit is contained in:
31
tools/app/promise-learn/src/index.ts
Normal file
31
tools/app/promise-learn/src/index.ts
Normal 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')
|
||||
})
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user