-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpg_client.go
More file actions
42 lines (37 loc) · 977 Bytes
/
Copy pathpg_client.go
File metadata and controls
42 lines (37 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package gotweet
import (
"context"
"fmt"
"os"
"github.com/jackc/pgx/v4"
)
func pgExec(connstring, q string) error {
conn, err := pgx.Connect(context.Background(), connstring)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err)
os.Exit(1)
}
defer conn.Close(context.Background())
// var args []interface{}
tag, err := conn.Query(context.Background(), q)
if err != nil {
fmt.Println(err)
return err
}
fmt.Println("tags in tags out // : ", tag)
return error(nil)
}
func pgQueryOne(connstring, q string, args []interface{}) (pgx.Rows, error) {
conn, err := pgx.Connect(context.Background(), connstring)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err)
os.Exit(1)
}
defer conn.Close(context.Background())
// var res pgx.Rows
rows, err := conn.Query(context.Background(), q, args...)
if err != nil {
fmt.Fprintf(os.Stderr, "Bad request error: %v\n", err)
}
return rows, err
}