64 lines
2.1 KiB
Go
64 lines
2.1 KiB
Go
//go:build ignore
|
|
|
|
package main
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"log"
|
|
|
|
_ "github.com/jackc/pgx/v5/stdlib"
|
|
)
|
|
|
|
func main() {
|
|
dsn := "host=66.116.207.225 port=5433 user=admin password=Package@123# dbname=nearledb sslmode=disable"
|
|
db, err := sql.Open("pgx", dsn)
|
|
if err != nil {
|
|
log.Fatalf("Error opening db connection: %v", err)
|
|
}
|
|
defer db.Close()
|
|
|
|
err = db.Ping()
|
|
if err != nil {
|
|
log.Fatalf("Error pinging db: %v", err)
|
|
}
|
|
fmt.Println("Connected successfully to PostgreSQL!")
|
|
|
|
// 1. Query locations
|
|
fmt.Println("\n--- SURIYA STORE LOCATIONS (tenantid = 1135) ---")
|
|
rows, err := db.Query(`SELECT locationid, tenantid, locationname, email, contactno, status FROM tenantlocations WHERE tenantid = 1135`)
|
|
if err != nil {
|
|
log.Fatalf("Error querying locations: %v", err)
|
|
}
|
|
defer rows.Close()
|
|
|
|
for rows.Next() {
|
|
var locationid, tenantid int
|
|
var locationname, email, contactno, status sql.NullString
|
|
if err := rows.Scan(&locationid, &tenantid, &locationname, &email, &contactno, &status); err != nil {
|
|
log.Fatalf("Scan error: %v", err)
|
|
}
|
|
fmt.Printf("Loc ID: %d | Tenant ID: %d | Name: %s | Email: %s | Contact: %s | Status: %s\n",
|
|
locationid, tenantid, locationname.String, email.String, contactno.String, status.String)
|
|
}
|
|
|
|
// 2. Query users
|
|
fmt.Println("\n--- USERS ASSOCIATED WITH tenantid = 1135 ---")
|
|
rows2, err := db.Query(`SELECT userid, authname, firstname, email, contactno, roleid, locationid, status FROM app_users WHERE tenantid = 1135`)
|
|
if err != nil {
|
|
log.Fatalf("Error querying users: %v", err)
|
|
}
|
|
defer rows2.Close()
|
|
|
|
for rows2.Next() {
|
|
var userid int
|
|
var roleid, locationid sql.NullInt64
|
|
var authname, firstname, email, contactno, status sql.NullString
|
|
if err := rows2.Scan(&userid, &authname, &firstname, &email, &contactno, &roleid, &locationid, &status); err != nil {
|
|
log.Fatalf("Scan error: %v", err)
|
|
}
|
|
fmt.Printf("User ID: %d | Auth: %s | Name: %s | Email: %s | Contact: %s | Role: %d | Loc: %d | Status: %s\n",
|
|
userid, authname.String, firstname.String, email.String, contactno.String, roleid.Int64, locationid.Int64, status.String)
|
|
}
|
|
}
|