• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cybertec-postgresql / pg_timetable / 18127629475

30 Sep 2025 10:59AM UTC coverage: 84.299% (-1.9%) from 86.155%
18127629475

Pull #720

github

web-flow
Merge f545f91b2 into 61518f6b4
Pull Request #720: [!] add YAML-based chain definitions

196 of 204 new or added lines in 7 files covered. (96.08%)

62 existing lines in 4 files now uncovered.

1659 of 1968 relevant lines covered (84.3%)

0.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

42.62
/internal/pgengine/copy.go
1
package pgengine
2

3
import (
4
        "context"
5
        "errors"
6
        "os"
7
        "os/exec"
8
)
9

10
// CopyToFile copies data from database into local file using COPY format specified by sql
11
func (pge *PgEngine) CopyToFile(ctx context.Context, filename string, sql string) (int64, error) {
1✔
12
        dbconn, err := pge.ConfigDb.Acquire(ctx)
1✔
13
        if err != nil {
2✔
14
                return -1, err
1✔
15
        }
1✔
16
        defer dbconn.Release()
1✔
17
        f, err := os.Create(filename)
1✔
18
        defer func() { _ = f.Close() }()
2✔
19
        if err != nil {
2✔
20
                return -1, err
1✔
21
        }
1✔
22
        res, err := dbconn.Conn().PgConn().CopyTo(ctx, f, sql)
1✔
23
        return res.RowsAffected(), err
1✔
24
}
25

26
// CopyFromFile copies data from local file into database using COPY format specified by sql
27
func (pge *PgEngine) CopyFromFile(ctx context.Context, filename string, sql string) (int64, error) {
1✔
28
        dbconn, err := pge.ConfigDb.Acquire(ctx)
1✔
29
        if err != nil {
2✔
30
                return -1, err
1✔
31
        }
1✔
32
        defer dbconn.Release()
1✔
33
        f, err := os.Open(filename)
1✔
34
        defer func() { _ = f.Close() }()
2✔
35
        if err != nil {
2✔
36
                return -1, err
1✔
37
        }
1✔
38
        res, err := dbconn.Conn().PgConn().CopyFrom(ctx, f, sql)
1✔
39
        return res.RowsAffected(), err
1✔
40
}
41

42
// CopyToProgram copies data from database to the standard input of the command using COPY format specified by sql
UNCOV
43
func (pge *PgEngine) CopyToProgram(ctx context.Context, sql string, cmd string, args ...string) (int64, error) {
×
UNCOV
44
        dbconn, err := pge.ConfigDb.Acquire(ctx)
×
UNCOV
45
        if err != nil {
×
46
                return -1, err
×
47
        }
×
UNCOV
48
        defer dbconn.Release()
×
UNCOV
49
        c := exec.CommandContext(ctx, cmd, args...)
×
UNCOV
50
        inPipe, err := c.StdinPipe()
×
UNCOV
51
        if err != nil {
×
52
                return -1, err
×
53
        }
×
UNCOV
54
        if err := c.Start(); err != nil {
×
55
                return -1, err
×
56
        }
×
UNCOV
57
        res, sqlErr := dbconn.Conn().PgConn().CopyTo(ctx, inPipe, sql)
×
UNCOV
58
        _ = inPipe.Close()
×
UNCOV
59
        cmdError := c.Wait()
×
UNCOV
60
        return res.RowsAffected(), errors.Join(sqlErr, cmdError)
×
61
}
62

63
// CopyFromProgram copies data from the standard output of the command into database using COPY format specified by sql
64
func (pge *PgEngine) CopyFromProgram(ctx context.Context, sql string, cmd string, args ...string) (int64, error) {
×
65
        dbconn, err := pge.ConfigDb.Acquire(ctx)
×
66
        if err != nil {
×
67
                return -1, err
×
68
        }
×
69
        defer dbconn.Release()
×
70
        c := exec.CommandContext(ctx, cmd, args...)
×
71
        outPipe, err := c.StdoutPipe()
×
72
        if err != nil {
×
73
                return -1, err
×
74
        }
×
75
        if err := c.Start(); err != nil {
×
76
                return -1, err
×
77
        }
×
78
        res, err := dbconn.Conn().PgConn().CopyFrom(ctx, outPipe, sql)
×
79
        waitErr := c.Wait()
×
80
        return res.RowsAffected(), errors.Join(waitErr, err)
×
81
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc