增加pgx驱动,完善前端的代码,暂定supabase后端数据库

This commit is contained in:
2025-05-21 08:50:34 +08:00
parent 9f2fb09157
commit 66980958f5
13 changed files with 126 additions and 85 deletions

26
database/pgsql.go Normal file
View File

@@ -0,0 +1,26 @@
package db
import (
"context"
"fmt"
"github.com/jackc/pgx/v5/pgxpool"
"os"
"zsxyww.com/scheduler/config"
)
// use pgx to connect
func PGSQL() {
pgx, err := pgxpool.New(context.Background(), config.Default.DB.Path)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to create connection pool: %v\n", err)
os.Exit(1)
}
version := ""
if err := pgx.QueryRow(context.Background(), "SELECT version()").Scan(&version); err != nil {
fmt.Printf("Query failed: %v\n", err)
os.Exit(1)
}
fmt.Println("Connected to:", version)
PGX = pgx
}