Initial commit including .env
This commit is contained in:
43
scratch/list_tables.go
Normal file
43
scratch/list_tables.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// DSN matches the one in connect.go and .env
|
||||
dsn := "host=31.97.228.132 user=admin password=Package@321# dbname=logistics port=5433 sslmode=disable"
|
||||
db, err := sql.Open("postgres", dsn)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to open DB: %v", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
if err := db.Ping(); err != nil {
|
||||
log.Fatalf("Failed to ping DB: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println("--- Listing Tables in logistics Database ---")
|
||||
rows, err := db.Query(`
|
||||
SELECT table_name
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = 'public'
|
||||
ORDER BY table_name;
|
||||
`)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to query tables: %v", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var name string
|
||||
if err := rows.Scan(&name); err != nil {
|
||||
log.Fatalf("Scan failed: %v", err)
|
||||
}
|
||||
fmt.Printf("Table: %s\n", name)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user