update,
This commit is contained in:
42
tsc1877/task1/_poc/sequelize/helloworld.js
Normal file
42
tsc1877/task1/_poc/sequelize/helloworld.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const { Sequelize } = require('sequelize')
|
||||
|
||||
const sequelize = new Sequelize('app_db', 'db_user', 'db_user_pass', {
|
||||
host: 'localhost',
|
||||
port: 6033,
|
||||
dialect: 'mysql'
|
||||
})
|
||||
|
||||
const User = sequelize.define(
|
||||
'User',
|
||||
{
|
||||
firstName: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
lastName: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false
|
||||
}
|
||||
},
|
||||
{ timestamps: false }
|
||||
)
|
||||
|
||||
;(async () => {
|
||||
try {
|
||||
await sequelize.authenticate()
|
||||
console.log('Connection has been established successfully.')
|
||||
|
||||
// create table
|
||||
await sequelize.sync()
|
||||
|
||||
const user = await User.create({ firstName: 'John', lastName: 'Doe' })
|
||||
console.log('Created user: ', user)
|
||||
|
||||
const users = await User.findAll()
|
||||
console.log('Found all users: ', users)
|
||||
|
||||
await sequelize.close()
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error)
|
||||
}
|
||||
})()
|
17
tsc1877/task1/_poc/sequelize/package.json
Normal file
17
tsc1877/task1/_poc/sequelize/package.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "sequelize",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "helloworld.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"mysql2": "^3.9.3",
|
||||
"sequelize": "^6.37.1",
|
||||
"sqlite3": "^5.1.7"
|
||||
}
|
||||
}
|
1043
tsc1877/task1/_poc/sequelize/yarn.lock
Normal file
1043
tsc1877/task1/_poc/sequelize/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user