mirror of
https://github.com/ZSCNetSupportDept/scheduler.git
synced 2025-10-29 13:04:15 +08:00
增加pgx驱动,完善前端的代码,暂定supabase后端数据库
This commit is contained in:
26
database/pgsql.go
Normal file
26
database/pgsql.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user