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

snowplow / sql-runner / 15063404311

16 May 2025 07:46AM UTC coverage: 27.73% (+1.0%) from 26.721%
15063404311

push

github

jbeemster
Prepared for release

353 of 1273 relevant lines covered (27.73%)

2.04 hits per line

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

0.0
/sql_runner/db.go
1
// Copyright (c) 2015-2025 Snowplow Analytics Ltd. All rights reserved.
2
//
3
// This program is licensed to you under the Apache License Version 2.0,
4
// and you may not use this file except in compliance with the Apache License Version 2.0.
5
// You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
6
//
7
// Unless required by applicable law or agreed to in writing,
8
// software distributed under the Apache License Version 2.0 is distributed on an
9
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
// See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
11
package main
12

13
import (
14
        "bytes"
15
        "text/template"
16
)
17

18
// Db is a generalized interface to a database client.
19
type Db interface {
20
        RunQuery(ReadyQuery, bool, bool) QueryStatus
21
        GetTarget() Target
22
        IsConnectable() bool
23
}
24

25
// Reads the script and fills in the template
26
func prepareQuery(queryPath string, sp SQLProvider, template bool, variables map[string]interface{}) (string, error) {
×
27

×
28
        var script string
×
29
        var err error
×
30

×
31
        script, err = sp.GetSQL(queryPath)
×
32

×
33
        if err != nil {
×
34
                return "", err
×
35
        }
×
36

37
        if template {
×
38
                script, err = fillTemplate(script, variables) // Yech, mutate
×
39
                if err != nil {
×
40
                        return "", err
×
41
                }
×
42
        }
43
        return script, nil
×
44
}
45

46
// Fills in a script which is a template
47
func fillTemplate(script string, variables map[string]interface{}) (string, error) {
×
48
        t, err := template.New("playbook").Funcs(TemplFuncs).Parse(script)
×
49
        if err != nil {
×
50
                return "", err
×
51
        }
×
52

53
        var filled bytes.Buffer
×
54
        if err := t.Execute(&filled, variables); err != nil {
×
55
                return "", err
×
56
        }
×
57
        return filled.String(), nil
×
58
}
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

© 2026 Coveralls, Inc