Skip to content

examples-mysql

git: https://github.com/WuChenDi/Front-End/tree/master/07-nodejs/examples-mysql

ts
import { Hono } from 'hono'
import mysql from 'mysql2/promise'

const app = new Hono()

app.get('/', (c) => {
  return c.text('Hello Hono!')
})

// Create the connection to database
const connection = await mysql.createConnection({
  host: 'localhost',
  user: 'root',
  password: '123456',
  database: 'dd',
})

// Execute sql statement
const sql = 'SELECT * FROM `tasks`'
// const sql = 'SELECT id, title, description FROM `tasks`'
// const sql = `SELECT * FROM tasks WHERE id='1'`
// const sql = `UPDATE tasks SET description='sql description' WHERE id=1`
// const sql = `UPDATE tasks SET title='test title' where title='title 12332111111'`
// const sql = `INSERT INTO tasks (title, description, createdAt, updatedAt) values ('test title', 'test description', '${new Date().toISOString().slice(0, 19).replace('T', ' ')}', '${new Date().toISOString().slice(0, 19).replace('T', ' ')}')`

try {
  const [results, fields] = await connection.query(sql)
  // results contains rows returned by server
  console.log(results)
  // fields contains extra meta data about results, if available
  console.log(fields)
} catch (err) {
  console.log(err)
}

export default app
json
{
  "name": "examples-mysql",
  "version": "1.0.0",
  "author": "wudi",
  "license": "MIT",
  "scripts": {
    "dev": "bun run --hot src/index.ts"
  },
  "dependencies": {
    "hono": "^4.2.6",
    "mysql2": "^3.9.7"
  },
  "devDependencies": {
    "@types/bun": "latest",
    "@types/node": "^20.12.7"
  }
}

Layout Switch

Adjust the layout style of VitePress to adapt to different reading needs and screens.

Expand all
The sidebar and content area occupy the entire width of the screen.
Expand sidebar with adjustable values
Expand sidebar width and add a new slider for user to choose and customize their desired width of the maximum width of sidebar can go, but the content area width will remain the same.
Expand all with adjustable values
Expand sidebar width and add a new slider for user to choose and customize their desired width of the maximum width of sidebar can go, but the content area width will remain the same.
Original width
The original layout width of VitePress

Page Layout Max Width

Adjust the exact value of the page width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the page layout
A ranged slider for user to choose and customize their desired width of the maximum width of the page layout can go.

Content Layout Max Width

Adjust the exact value of the document content width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the content layout
A ranged slider for user to choose and customize their desired width of the maximum width of the content layout can go.

Spotlight

Highlight the line where the mouse is currently hovering in the content to optimize for users who may have reading and focusing difficulties.

ONOn
Turn on Spotlight.
OFFOff
Turn off Spotlight.