This commit is contained in:
louiscklaw
2025-01-31 20:14:02 +08:00
parent 49e275d85d
commit 5c584709c4
706 changed files with 40207 additions and 0 deletions

View 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)
}
})()

View 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"
}
}

File diff suppressed because it is too large Load Diff