Commit 01b4afb5 authored by 健杭 徐's avatar 健杭 徐
Browse files

main.go func createTable

parent ba358013
...@@ -143,3 +143,28 @@ func GetMessageList(c *gin.Context) { ...@@ -143,3 +143,28 @@ func GetMessageList(c *gin.Context) {
func RoomMessageUpdate(c *gin.Context) { func RoomMessageUpdate(c *gin.Context) {
// 处理更新房间消息的逻辑 // 处理更新房间消息的逻辑
} }
func createTable() {
query := `
CREATE TABLE IF NOT EXISTS messages (
message_id SERIAL PRIMARY KEY,
room_id INT NOT NULL,
profile_id INT NOT NULL,
sender VARCHAR(100) NOT NULL,
content TEXT NOT NULL,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS rooms (
room_id SERIAL PRIMARY KEY,
room_name VARCHAR(100) NOT NULL
LAST_MESSAGE TEXT,
LAST_MESSAGE_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
`
_, err := db.Exec(query)
if err != nil {
log.Fatal("Failed to create tables: ", err)
}
log.Println("Tables created successfully")
}
'use client'; 'use client';
import { METHODS } from "http";
import "./ChatRoom.css"; import "./ChatRoom.css";
import React, { useState } from "react"; import React, { useState } from "react";
...@@ -67,7 +66,7 @@ function RoomEntry () { ...@@ -67,7 +66,7 @@ function RoomEntry () {
<span className="chat-message">{room.lastContent}</span> <span className="chat-message">{room.lastContent}</span>
<span className="chat-time"></span> <span className="chat-time"></span>
</div> </div>
</div> </div>
))} ))}
</div> </div>
</div> </div>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment